journal.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428
  1. /*
  2. * linux/fs/jbd2/journal.c
  3. *
  4. * Written by Stephen C. Tweedie <sct@redhat.com>, 1998
  5. *
  6. * Copyright 1998 Red Hat corp --- All Rights Reserved
  7. *
  8. * This file is part of the Linux kernel and is made available under
  9. * the terms of the GNU General Public License, version 2, or at your
  10. * option, any later version, incorporated herein by reference.
  11. *
  12. * Generic filesystem journal-writing code; part of the ext2fs
  13. * journaling system.
  14. *
  15. * This file manages journals: areas of disk reserved for logging
  16. * transactional updates. This includes the kernel journaling thread
  17. * which is responsible for scheduling updates to the log.
  18. *
  19. * We do not actually manage the physical storage of the journal in this
  20. * file: that is left to a per-journal policy function, which allows us
  21. * to store the journal within a filesystem-specified area for ext2
  22. * journaling (ext2 can use a reserved inode for storing the log).
  23. */
  24. #include <linux/module.h>
  25. #include <linux/time.h>
  26. #include <linux/fs.h>
  27. #include <linux/jbd2.h>
  28. #include <linux/errno.h>
  29. #include <linux/slab.h>
  30. #include <linux/init.h>
  31. #include <linux/mm.h>
  32. #include <linux/freezer.h>
  33. #include <linux/pagemap.h>
  34. #include <linux/kthread.h>
  35. #include <linux/poison.h>
  36. #include <linux/proc_fs.h>
  37. #include <linux/debugfs.h>
  38. #include <linux/seq_file.h>
  39. #include <asm/uaccess.h>
  40. #include <asm/page.h>
  41. EXPORT_SYMBOL(jbd2_journal_start);
  42. EXPORT_SYMBOL(jbd2_journal_restart);
  43. EXPORT_SYMBOL(jbd2_journal_extend);
  44. EXPORT_SYMBOL(jbd2_journal_stop);
  45. EXPORT_SYMBOL(jbd2_journal_lock_updates);
  46. EXPORT_SYMBOL(jbd2_journal_unlock_updates);
  47. EXPORT_SYMBOL(jbd2_journal_get_write_access);
  48. EXPORT_SYMBOL(jbd2_journal_get_create_access);
  49. EXPORT_SYMBOL(jbd2_journal_get_undo_access);
  50. EXPORT_SYMBOL(jbd2_journal_set_triggers);
  51. EXPORT_SYMBOL(jbd2_journal_dirty_metadata);
  52. EXPORT_SYMBOL(jbd2_journal_release_buffer);
  53. EXPORT_SYMBOL(jbd2_journal_forget);
  54. #if 0
  55. EXPORT_SYMBOL(journal_sync_buffer);
  56. #endif
  57. EXPORT_SYMBOL(jbd2_journal_flush);
  58. EXPORT_SYMBOL(jbd2_journal_revoke);
  59. EXPORT_SYMBOL(jbd2_journal_init_dev);
  60. EXPORT_SYMBOL(jbd2_journal_init_inode);
  61. EXPORT_SYMBOL(jbd2_journal_update_format);
  62. EXPORT_SYMBOL(jbd2_journal_check_used_features);
  63. EXPORT_SYMBOL(jbd2_journal_check_available_features);
  64. EXPORT_SYMBOL(jbd2_journal_set_features);
  65. EXPORT_SYMBOL(jbd2_journal_create);
  66. EXPORT_SYMBOL(jbd2_journal_load);
  67. EXPORT_SYMBOL(jbd2_journal_destroy);
  68. EXPORT_SYMBOL(jbd2_journal_abort);
  69. EXPORT_SYMBOL(jbd2_journal_errno);
  70. EXPORT_SYMBOL(jbd2_journal_ack_err);
  71. EXPORT_SYMBOL(jbd2_journal_clear_err);
  72. EXPORT_SYMBOL(jbd2_log_wait_commit);
  73. EXPORT_SYMBOL(jbd2_journal_start_commit);
  74. EXPORT_SYMBOL(jbd2_journal_force_commit_nested);
  75. EXPORT_SYMBOL(jbd2_journal_wipe);
  76. EXPORT_SYMBOL(jbd2_journal_blocks_per_page);
  77. EXPORT_SYMBOL(jbd2_journal_invalidatepage);
  78. EXPORT_SYMBOL(jbd2_journal_try_to_free_buffers);
  79. EXPORT_SYMBOL(jbd2_journal_force_commit);
  80. EXPORT_SYMBOL(jbd2_journal_file_inode);
  81. EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
  82. EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
  83. EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
  84. static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *);
  85. static void __journal_abort_soft (journal_t *journal, int errno);
  86. /*
  87. * Helper function used to manage commit timeouts
  88. */
  89. static void commit_timeout(unsigned long __data)
  90. {
  91. struct task_struct * p = (struct task_struct *) __data;
  92. wake_up_process(p);
  93. }
  94. /*
  95. * kjournald2: The main thread function used to manage a logging device
  96. * journal.
  97. *
  98. * This kernel thread is responsible for two things:
  99. *
  100. * 1) COMMIT: Every so often we need to commit the current state of the
  101. * filesystem to disk. The journal thread is responsible for writing
  102. * all of the metadata buffers to disk.
  103. *
  104. * 2) CHECKPOINT: We cannot reuse a used section of the log file until all
  105. * of the data in that part of the log has been rewritten elsewhere on
  106. * the disk. Flushing these old buffers to reclaim space in the log is
  107. * known as checkpointing, and this thread is responsible for that job.
  108. */
  109. static int kjournald2(void *arg)
  110. {
  111. journal_t *journal = arg;
  112. transaction_t *transaction;
  113. /*
  114. * Set up an interval timer which can be used to trigger a commit wakeup
  115. * after the commit interval expires
  116. */
  117. setup_timer(&journal->j_commit_timer, commit_timeout,
  118. (unsigned long)current);
  119. /* Record that the journal thread is running */
  120. journal->j_task = current;
  121. wake_up(&journal->j_wait_done_commit);
  122. printk(KERN_INFO "kjournald2 starting. Commit interval %ld seconds\n",
  123. journal->j_commit_interval / HZ);
  124. /*
  125. * And now, wait forever for commit wakeup events.
  126. */
  127. spin_lock(&journal->j_state_lock);
  128. loop:
  129. if (journal->j_flags & JBD2_UNMOUNT)
  130. goto end_loop;
  131. jbd_debug(1, "commit_sequence=%d, commit_request=%d\n",
  132. journal->j_commit_sequence, journal->j_commit_request);
  133. if (journal->j_commit_sequence != journal->j_commit_request) {
  134. jbd_debug(1, "OK, requests differ\n");
  135. spin_unlock(&journal->j_state_lock);
  136. del_timer_sync(&journal->j_commit_timer);
  137. jbd2_journal_commit_transaction(journal);
  138. spin_lock(&journal->j_state_lock);
  139. goto loop;
  140. }
  141. wake_up(&journal->j_wait_done_commit);
  142. if (freezing(current)) {
  143. /*
  144. * The simpler the better. Flushing journal isn't a
  145. * good idea, because that depends on threads that may
  146. * be already stopped.
  147. */
  148. jbd_debug(1, "Now suspending kjournald2\n");
  149. spin_unlock(&journal->j_state_lock);
  150. refrigerator();
  151. spin_lock(&journal->j_state_lock);
  152. } else {
  153. /*
  154. * We assume on resume that commits are already there,
  155. * so we don't sleep
  156. */
  157. DEFINE_WAIT(wait);
  158. int should_sleep = 1;
  159. prepare_to_wait(&journal->j_wait_commit, &wait,
  160. TASK_INTERRUPTIBLE);
  161. if (journal->j_commit_sequence != journal->j_commit_request)
  162. should_sleep = 0;
  163. transaction = journal->j_running_transaction;
  164. if (transaction && time_after_eq(jiffies,
  165. transaction->t_expires))
  166. should_sleep = 0;
  167. if (journal->j_flags & JBD2_UNMOUNT)
  168. should_sleep = 0;
  169. if (should_sleep) {
  170. spin_unlock(&journal->j_state_lock);
  171. schedule();
  172. spin_lock(&journal->j_state_lock);
  173. }
  174. finish_wait(&journal->j_wait_commit, &wait);
  175. }
  176. jbd_debug(1, "kjournald2 wakes\n");
  177. /*
  178. * Were we woken up by a commit wakeup event?
  179. */
  180. transaction = journal->j_running_transaction;
  181. if (transaction && time_after_eq(jiffies, transaction->t_expires)) {
  182. journal->j_commit_request = transaction->t_tid;
  183. jbd_debug(1, "woke because of timeout\n");
  184. }
  185. goto loop;
  186. end_loop:
  187. spin_unlock(&journal->j_state_lock);
  188. del_timer_sync(&journal->j_commit_timer);
  189. journal->j_task = NULL;
  190. wake_up(&journal->j_wait_done_commit);
  191. jbd_debug(1, "Journal thread exiting.\n");
  192. return 0;
  193. }
  194. static int jbd2_journal_start_thread(journal_t *journal)
  195. {
  196. struct task_struct *t;
  197. t = kthread_run(kjournald2, journal, "kjournald2");
  198. if (IS_ERR(t))
  199. return PTR_ERR(t);
  200. wait_event(journal->j_wait_done_commit, journal->j_task != NULL);
  201. return 0;
  202. }
  203. static void journal_kill_thread(journal_t *journal)
  204. {
  205. spin_lock(&journal->j_state_lock);
  206. journal->j_flags |= JBD2_UNMOUNT;
  207. while (journal->j_task) {
  208. wake_up(&journal->j_wait_commit);
  209. spin_unlock(&journal->j_state_lock);
  210. wait_event(journal->j_wait_done_commit, journal->j_task == NULL);
  211. spin_lock(&journal->j_state_lock);
  212. }
  213. spin_unlock(&journal->j_state_lock);
  214. }
  215. /*
  216. * jbd2_journal_write_metadata_buffer: write a metadata buffer to the journal.
  217. *
  218. * Writes a metadata buffer to a given disk block. The actual IO is not
  219. * performed but a new buffer_head is constructed which labels the data
  220. * to be written with the correct destination disk block.
  221. *
  222. * Any magic-number escaping which needs to be done will cause a
  223. * copy-out here. If the buffer happens to start with the
  224. * JBD2_MAGIC_NUMBER, then we can't write it to the log directly: the
  225. * magic number is only written to the log for descripter blocks. In
  226. * this case, we copy the data and replace the first word with 0, and we
  227. * return a result code which indicates that this buffer needs to be
  228. * marked as an escaped buffer in the corresponding log descriptor
  229. * block. The missing word can then be restored when the block is read
  230. * during recovery.
  231. *
  232. * If the source buffer has already been modified by a new transaction
  233. * since we took the last commit snapshot, we use the frozen copy of
  234. * that data for IO. If we end up using the existing buffer_head's data
  235. * for the write, then we *have* to lock the buffer to prevent anyone
  236. * else from using and possibly modifying it while the IO is in
  237. * progress.
  238. *
  239. * The function returns a pointer to the buffer_heads to be used for IO.
  240. *
  241. * We assume that the journal has already been locked in this function.
  242. *
  243. * Return value:
  244. * <0: Error
  245. * >=0: Finished OK
  246. *
  247. * On success:
  248. * Bit 0 set == escape performed on the data
  249. * Bit 1 set == buffer copy-out performed (kfree the data after IO)
  250. */
  251. int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
  252. struct journal_head *jh_in,
  253. struct journal_head **jh_out,
  254. unsigned long long blocknr)
  255. {
  256. int need_copy_out = 0;
  257. int done_copy_out = 0;
  258. int do_escape = 0;
  259. char *mapped_data;
  260. struct buffer_head *new_bh;
  261. struct journal_head *new_jh;
  262. struct page *new_page;
  263. unsigned int new_offset;
  264. struct buffer_head *bh_in = jh2bh(jh_in);
  265. struct jbd2_buffer_trigger_type *triggers;
  266. /*
  267. * The buffer really shouldn't be locked: only the current committing
  268. * transaction is allowed to write it, so nobody else is allowed
  269. * to do any IO.
  270. *
  271. * akpm: except if we're journalling data, and write() output is
  272. * also part of a shared mapping, and another thread has
  273. * decided to launch a writepage() against this buffer.
  274. */
  275. J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
  276. new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL);
  277. /*
  278. * If a new transaction has already done a buffer copy-out, then
  279. * we use that version of the data for the commit.
  280. */
  281. jbd_lock_bh_state(bh_in);
  282. repeat:
  283. if (jh_in->b_frozen_data) {
  284. done_copy_out = 1;
  285. new_page = virt_to_page(jh_in->b_frozen_data);
  286. new_offset = offset_in_page(jh_in->b_frozen_data);
  287. triggers = jh_in->b_frozen_triggers;
  288. } else {
  289. new_page = jh2bh(jh_in)->b_page;
  290. new_offset = offset_in_page(jh2bh(jh_in)->b_data);
  291. triggers = jh_in->b_triggers;
  292. }
  293. mapped_data = kmap_atomic(new_page, KM_USER0);
  294. /*
  295. * Fire any commit trigger. Do this before checking for escaping,
  296. * as the trigger may modify the magic offset. If a copy-out
  297. * happens afterwards, it will have the correct data in the buffer.
  298. */
  299. jbd2_buffer_commit_trigger(jh_in, mapped_data + new_offset,
  300. triggers);
  301. /*
  302. * Check for escaping
  303. */
  304. if (*((__be32 *)(mapped_data + new_offset)) ==
  305. cpu_to_be32(JBD2_MAGIC_NUMBER)) {
  306. need_copy_out = 1;
  307. do_escape = 1;
  308. }
  309. kunmap_atomic(mapped_data, KM_USER0);
  310. /*
  311. * Do we need to do a data copy?
  312. */
  313. if (need_copy_out && !done_copy_out) {
  314. char *tmp;
  315. jbd_unlock_bh_state(bh_in);
  316. tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
  317. jbd_lock_bh_state(bh_in);
  318. if (jh_in->b_frozen_data) {
  319. jbd2_free(tmp, bh_in->b_size);
  320. goto repeat;
  321. }
  322. jh_in->b_frozen_data = tmp;
  323. mapped_data = kmap_atomic(new_page, KM_USER0);
  324. memcpy(tmp, mapped_data + new_offset, jh2bh(jh_in)->b_size);
  325. kunmap_atomic(mapped_data, KM_USER0);
  326. new_page = virt_to_page(tmp);
  327. new_offset = offset_in_page(tmp);
  328. done_copy_out = 1;
  329. /*
  330. * This isn't strictly necessary, as we're using frozen
  331. * data for the escaping, but it keeps consistency with
  332. * b_frozen_data usage.
  333. */
  334. jh_in->b_frozen_triggers = jh_in->b_triggers;
  335. }
  336. /*
  337. * Did we need to do an escaping? Now we've done all the
  338. * copying, we can finally do so.
  339. */
  340. if (do_escape) {
  341. mapped_data = kmap_atomic(new_page, KM_USER0);
  342. *((unsigned int *)(mapped_data + new_offset)) = 0;
  343. kunmap_atomic(mapped_data, KM_USER0);
  344. }
  345. /* keep subsequent assertions sane */
  346. new_bh->b_state = 0;
  347. init_buffer(new_bh, NULL, NULL);
  348. atomic_set(&new_bh->b_count, 1);
  349. jbd_unlock_bh_state(bh_in);
  350. new_jh = jbd2_journal_add_journal_head(new_bh); /* This sleeps */
  351. set_bh_page(new_bh, new_page, new_offset);
  352. new_jh->b_transaction = NULL;
  353. new_bh->b_size = jh2bh(jh_in)->b_size;
  354. new_bh->b_bdev = transaction->t_journal->j_dev;
  355. new_bh->b_blocknr = blocknr;
  356. set_buffer_mapped(new_bh);
  357. set_buffer_dirty(new_bh);
  358. *jh_out = new_jh;
  359. /*
  360. * The to-be-written buffer needs to get moved to the io queue,
  361. * and the original buffer whose contents we are shadowing or
  362. * copying is moved to the transaction's shadow queue.
  363. */
  364. JBUFFER_TRACE(jh_in, "file as BJ_Shadow");
  365. jbd2_journal_file_buffer(jh_in, transaction, BJ_Shadow);
  366. JBUFFER_TRACE(new_jh, "file as BJ_IO");
  367. jbd2_journal_file_buffer(new_jh, transaction, BJ_IO);
  368. return do_escape | (done_copy_out << 1);
  369. }
  370. /*
  371. * Allocation code for the journal file. Manage the space left in the
  372. * journal, so that we can begin checkpointing when appropriate.
  373. */
  374. /*
  375. * __jbd2_log_space_left: Return the number of free blocks left in the journal.
  376. *
  377. * Called with the journal already locked.
  378. *
  379. * Called under j_state_lock
  380. */
  381. int __jbd2_log_space_left(journal_t *journal)
  382. {
  383. int left = journal->j_free;
  384. assert_spin_locked(&journal->j_state_lock);
  385. /*
  386. * Be pessimistic here about the number of those free blocks which
  387. * might be required for log descriptor control blocks.
  388. */
  389. #define MIN_LOG_RESERVED_BLOCKS 32 /* Allow for rounding errors */
  390. left -= MIN_LOG_RESERVED_BLOCKS;
  391. if (left <= 0)
  392. return 0;
  393. left -= (left >> 3);
  394. return left;
  395. }
  396. /*
  397. * Called under j_state_lock. Returns true if a transaction was started.
  398. */
  399. int __jbd2_log_start_commit(journal_t *journal, tid_t target)
  400. {
  401. /*
  402. * Are we already doing a recent enough commit?
  403. */
  404. if (!tid_geq(journal->j_commit_request, target)) {
  405. /*
  406. * We want a new commit: OK, mark the request and wakup the
  407. * commit thread. We do _not_ do the commit ourselves.
  408. */
  409. journal->j_commit_request = target;
  410. jbd_debug(1, "JBD: requesting commit %d/%d\n",
  411. journal->j_commit_request,
  412. journal->j_commit_sequence);
  413. wake_up(&journal->j_wait_commit);
  414. return 1;
  415. }
  416. return 0;
  417. }
  418. int jbd2_log_start_commit(journal_t *journal, tid_t tid)
  419. {
  420. int ret;
  421. spin_lock(&journal->j_state_lock);
  422. ret = __jbd2_log_start_commit(journal, tid);
  423. spin_unlock(&journal->j_state_lock);
  424. return ret;
  425. }
  426. /*
  427. * Force and wait upon a commit if the calling process is not within
  428. * transaction. This is used for forcing out undo-protected data which contains
  429. * bitmaps, when the fs is running out of space.
  430. *
  431. * We can only force the running transaction if we don't have an active handle;
  432. * otherwise, we will deadlock.
  433. *
  434. * Returns true if a transaction was started.
  435. */
  436. int jbd2_journal_force_commit_nested(journal_t *journal)
  437. {
  438. transaction_t *transaction = NULL;
  439. tid_t tid;
  440. spin_lock(&journal->j_state_lock);
  441. if (journal->j_running_transaction && !current->journal_info) {
  442. transaction = journal->j_running_transaction;
  443. __jbd2_log_start_commit(journal, transaction->t_tid);
  444. } else if (journal->j_committing_transaction)
  445. transaction = journal->j_committing_transaction;
  446. if (!transaction) {
  447. spin_unlock(&journal->j_state_lock);
  448. return 0; /* Nothing to retry */
  449. }
  450. tid = transaction->t_tid;
  451. spin_unlock(&journal->j_state_lock);
  452. jbd2_log_wait_commit(journal, tid);
  453. return 1;
  454. }
  455. /*
  456. * Start a commit of the current running transaction (if any). Returns true
  457. * if a transaction was started, and fills its tid in at *ptid
  458. */
  459. int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
  460. {
  461. int ret = 0;
  462. spin_lock(&journal->j_state_lock);
  463. if (journal->j_running_transaction) {
  464. tid_t tid = journal->j_running_transaction->t_tid;
  465. ret = __jbd2_log_start_commit(journal, tid);
  466. if (ret && ptid)
  467. *ptid = tid;
  468. } else if (journal->j_committing_transaction && ptid) {
  469. /*
  470. * If ext3_write_super() recently started a commit, then we
  471. * have to wait for completion of that transaction
  472. */
  473. *ptid = journal->j_committing_transaction->t_tid;
  474. ret = 1;
  475. }
  476. spin_unlock(&journal->j_state_lock);
  477. return ret;
  478. }
  479. /*
  480. * Wait for a specified commit to complete.
  481. * The caller may not hold the journal lock.
  482. */
  483. int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
  484. {
  485. int err = 0;
  486. #ifdef CONFIG_JBD2_DEBUG
  487. spin_lock(&journal->j_state_lock);
  488. if (!tid_geq(journal->j_commit_request, tid)) {
  489. printk(KERN_EMERG
  490. "%s: error: j_commit_request=%d, tid=%d\n",
  491. __func__, journal->j_commit_request, tid);
  492. }
  493. spin_unlock(&journal->j_state_lock);
  494. #endif
  495. spin_lock(&journal->j_state_lock);
  496. while (tid_gt(tid, journal->j_commit_sequence)) {
  497. jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n",
  498. tid, journal->j_commit_sequence);
  499. wake_up(&journal->j_wait_commit);
  500. spin_unlock(&journal->j_state_lock);
  501. wait_event(journal->j_wait_done_commit,
  502. !tid_gt(tid, journal->j_commit_sequence));
  503. spin_lock(&journal->j_state_lock);
  504. }
  505. spin_unlock(&journal->j_state_lock);
  506. if (unlikely(is_journal_aborted(journal))) {
  507. printk(KERN_EMERG "journal commit I/O error\n");
  508. err = -EIO;
  509. }
  510. return err;
  511. }
  512. /*
  513. * Log buffer allocation routines:
  514. */
  515. int jbd2_journal_next_log_block(journal_t *journal, unsigned long long *retp)
  516. {
  517. unsigned long blocknr;
  518. spin_lock(&journal->j_state_lock);
  519. J_ASSERT(journal->j_free > 1);
  520. blocknr = journal->j_head;
  521. journal->j_head++;
  522. journal->j_free--;
  523. if (journal->j_head == journal->j_last)
  524. journal->j_head = journal->j_first;
  525. spin_unlock(&journal->j_state_lock);
  526. return jbd2_journal_bmap(journal, blocknr, retp);
  527. }
  528. /*
  529. * Conversion of logical to physical block numbers for the journal
  530. *
  531. * On external journals the journal blocks are identity-mapped, so
  532. * this is a no-op. If needed, we can use j_blk_offset - everything is
  533. * ready.
  534. */
  535. int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
  536. unsigned long long *retp)
  537. {
  538. int err = 0;
  539. unsigned long long ret;
  540. if (journal->j_inode) {
  541. ret = bmap(journal->j_inode, blocknr);
  542. if (ret)
  543. *retp = ret;
  544. else {
  545. printk(KERN_ALERT "%s: journal block not found "
  546. "at offset %lu on %s\n",
  547. __func__, blocknr, journal->j_devname);
  548. err = -EIO;
  549. __journal_abort_soft(journal, err);
  550. }
  551. } else {
  552. *retp = blocknr; /* +journal->j_blk_offset */
  553. }
  554. return err;
  555. }
  556. /*
  557. * We play buffer_head aliasing tricks to write data/metadata blocks to
  558. * the journal without copying their contents, but for journal
  559. * descriptor blocks we do need to generate bona fide buffers.
  560. *
  561. * After the caller of jbd2_journal_get_descriptor_buffer() has finished modifying
  562. * the buffer's contents they really should run flush_dcache_page(bh->b_page).
  563. * But we don't bother doing that, so there will be coherency problems with
  564. * mmaps of blockdevs which hold live JBD-controlled filesystems.
  565. */
  566. struct journal_head *jbd2_journal_get_descriptor_buffer(journal_t *journal)
  567. {
  568. struct buffer_head *bh;
  569. unsigned long long blocknr;
  570. int err;
  571. err = jbd2_journal_next_log_block(journal, &blocknr);
  572. if (err)
  573. return NULL;
  574. bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
  575. lock_buffer(bh);
  576. memset(bh->b_data, 0, journal->j_blocksize);
  577. set_buffer_uptodate(bh);
  578. unlock_buffer(bh);
  579. BUFFER_TRACE(bh, "return this buffer");
  580. return jbd2_journal_add_journal_head(bh);
  581. }
  582. struct jbd2_stats_proc_session {
  583. journal_t *journal;
  584. struct transaction_stats_s *stats;
  585. int start;
  586. int max;
  587. };
  588. static void *jbd2_history_skip_empty(struct jbd2_stats_proc_session *s,
  589. struct transaction_stats_s *ts,
  590. int first)
  591. {
  592. if (ts == s->stats + s->max)
  593. ts = s->stats;
  594. if (!first && ts == s->stats + s->start)
  595. return NULL;
  596. while (ts->ts_type == 0) {
  597. ts++;
  598. if (ts == s->stats + s->max)
  599. ts = s->stats;
  600. if (ts == s->stats + s->start)
  601. return NULL;
  602. }
  603. return ts;
  604. }
  605. static void *jbd2_seq_history_start(struct seq_file *seq, loff_t *pos)
  606. {
  607. struct jbd2_stats_proc_session *s = seq->private;
  608. struct transaction_stats_s *ts;
  609. int l = *pos;
  610. if (l == 0)
  611. return SEQ_START_TOKEN;
  612. ts = jbd2_history_skip_empty(s, s->stats + s->start, 1);
  613. if (!ts)
  614. return NULL;
  615. l--;
  616. while (l) {
  617. ts = jbd2_history_skip_empty(s, ++ts, 0);
  618. if (!ts)
  619. break;
  620. l--;
  621. }
  622. return ts;
  623. }
  624. static void *jbd2_seq_history_next(struct seq_file *seq, void *v, loff_t *pos)
  625. {
  626. struct jbd2_stats_proc_session *s = seq->private;
  627. struct transaction_stats_s *ts = v;
  628. ++*pos;
  629. if (v == SEQ_START_TOKEN)
  630. return jbd2_history_skip_empty(s, s->stats + s->start, 1);
  631. else
  632. return jbd2_history_skip_empty(s, ++ts, 0);
  633. }
  634. static int jbd2_seq_history_show(struct seq_file *seq, void *v)
  635. {
  636. struct transaction_stats_s *ts = v;
  637. if (v == SEQ_START_TOKEN) {
  638. seq_printf(seq, "%-4s %-5s %-5s %-5s %-5s %-5s %-5s %-6s %-5s "
  639. "%-5s %-5s %-5s %-5s %-5s\n", "R/C", "tid",
  640. "wait", "run", "lock", "flush", "log", "hndls",
  641. "block", "inlog", "ctime", "write", "drop",
  642. "close");
  643. return 0;
  644. }
  645. if (ts->ts_type == JBD2_STATS_RUN)
  646. seq_printf(seq, "%-4s %-5lu %-5u %-5u %-5u %-5u %-5u "
  647. "%-6lu %-5lu %-5lu\n", "R", ts->ts_tid,
  648. jiffies_to_msecs(ts->u.run.rs_wait),
  649. jiffies_to_msecs(ts->u.run.rs_running),
  650. jiffies_to_msecs(ts->u.run.rs_locked),
  651. jiffies_to_msecs(ts->u.run.rs_flushing),
  652. jiffies_to_msecs(ts->u.run.rs_logging),
  653. ts->u.run.rs_handle_count,
  654. ts->u.run.rs_blocks,
  655. ts->u.run.rs_blocks_logged);
  656. else if (ts->ts_type == JBD2_STATS_CHECKPOINT)
  657. seq_printf(seq, "%-4s %-5lu %48s %-5u %-5lu %-5lu %-5lu\n",
  658. "C", ts->ts_tid, " ",
  659. jiffies_to_msecs(ts->u.chp.cs_chp_time),
  660. ts->u.chp.cs_written, ts->u.chp.cs_dropped,
  661. ts->u.chp.cs_forced_to_close);
  662. else
  663. J_ASSERT(0);
  664. return 0;
  665. }
  666. static void jbd2_seq_history_stop(struct seq_file *seq, void *v)
  667. {
  668. }
  669. static struct seq_operations jbd2_seq_history_ops = {
  670. .start = jbd2_seq_history_start,
  671. .next = jbd2_seq_history_next,
  672. .stop = jbd2_seq_history_stop,
  673. .show = jbd2_seq_history_show,
  674. };
  675. static int jbd2_seq_history_open(struct inode *inode, struct file *file)
  676. {
  677. journal_t *journal = PDE(inode)->data;
  678. struct jbd2_stats_proc_session *s;
  679. int rc, size;
  680. s = kmalloc(sizeof(*s), GFP_KERNEL);
  681. if (s == NULL)
  682. return -ENOMEM;
  683. size = sizeof(struct transaction_stats_s) * journal->j_history_max;
  684. s->stats = kmalloc(size, GFP_KERNEL);
  685. if (s->stats == NULL) {
  686. kfree(s);
  687. return -ENOMEM;
  688. }
  689. spin_lock(&journal->j_history_lock);
  690. memcpy(s->stats, journal->j_history, size);
  691. s->max = journal->j_history_max;
  692. s->start = journal->j_history_cur % s->max;
  693. spin_unlock(&journal->j_history_lock);
  694. rc = seq_open(file, &jbd2_seq_history_ops);
  695. if (rc == 0) {
  696. struct seq_file *m = file->private_data;
  697. m->private = s;
  698. } else {
  699. kfree(s->stats);
  700. kfree(s);
  701. }
  702. return rc;
  703. }
  704. static int jbd2_seq_history_release(struct inode *inode, struct file *file)
  705. {
  706. struct seq_file *seq = file->private_data;
  707. struct jbd2_stats_proc_session *s = seq->private;
  708. kfree(s->stats);
  709. kfree(s);
  710. return seq_release(inode, file);
  711. }
  712. static struct file_operations jbd2_seq_history_fops = {
  713. .owner = THIS_MODULE,
  714. .open = jbd2_seq_history_open,
  715. .read = seq_read,
  716. .llseek = seq_lseek,
  717. .release = jbd2_seq_history_release,
  718. };
  719. static void *jbd2_seq_info_start(struct seq_file *seq, loff_t *pos)
  720. {
  721. return *pos ? NULL : SEQ_START_TOKEN;
  722. }
  723. static void *jbd2_seq_info_next(struct seq_file *seq, void *v, loff_t *pos)
  724. {
  725. return NULL;
  726. }
  727. static int jbd2_seq_info_show(struct seq_file *seq, void *v)
  728. {
  729. struct jbd2_stats_proc_session *s = seq->private;
  730. if (v != SEQ_START_TOKEN)
  731. return 0;
  732. seq_printf(seq, "%lu transaction, each upto %u blocks\n",
  733. s->stats->ts_tid,
  734. s->journal->j_max_transaction_buffers);
  735. if (s->stats->ts_tid == 0)
  736. return 0;
  737. seq_printf(seq, "average: \n %ums waiting for transaction\n",
  738. jiffies_to_msecs(s->stats->u.run.rs_wait / s->stats->ts_tid));
  739. seq_printf(seq, " %ums running transaction\n",
  740. jiffies_to_msecs(s->stats->u.run.rs_running / s->stats->ts_tid));
  741. seq_printf(seq, " %ums transaction was being locked\n",
  742. jiffies_to_msecs(s->stats->u.run.rs_locked / s->stats->ts_tid));
  743. seq_printf(seq, " %ums flushing data (in ordered mode)\n",
  744. jiffies_to_msecs(s->stats->u.run.rs_flushing / s->stats->ts_tid));
  745. seq_printf(seq, " %ums logging transaction\n",
  746. jiffies_to_msecs(s->stats->u.run.rs_logging / s->stats->ts_tid));
  747. seq_printf(seq, " %lu handles per transaction\n",
  748. s->stats->u.run.rs_handle_count / s->stats->ts_tid);
  749. seq_printf(seq, " %lu blocks per transaction\n",
  750. s->stats->u.run.rs_blocks / s->stats->ts_tid);
  751. seq_printf(seq, " %lu logged blocks per transaction\n",
  752. s->stats->u.run.rs_blocks_logged / s->stats->ts_tid);
  753. return 0;
  754. }
  755. static void jbd2_seq_info_stop(struct seq_file *seq, void *v)
  756. {
  757. }
  758. static struct seq_operations jbd2_seq_info_ops = {
  759. .start = jbd2_seq_info_start,
  760. .next = jbd2_seq_info_next,
  761. .stop = jbd2_seq_info_stop,
  762. .show = jbd2_seq_info_show,
  763. };
  764. static int jbd2_seq_info_open(struct inode *inode, struct file *file)
  765. {
  766. journal_t *journal = PDE(inode)->data;
  767. struct jbd2_stats_proc_session *s;
  768. int rc, size;
  769. s = kmalloc(sizeof(*s), GFP_KERNEL);
  770. if (s == NULL)
  771. return -ENOMEM;
  772. size = sizeof(struct transaction_stats_s);
  773. s->stats = kmalloc(size, GFP_KERNEL);
  774. if (s->stats == NULL) {
  775. kfree(s);
  776. return -ENOMEM;
  777. }
  778. spin_lock(&journal->j_history_lock);
  779. memcpy(s->stats, &journal->j_stats, size);
  780. s->journal = journal;
  781. spin_unlock(&journal->j_history_lock);
  782. rc = seq_open(file, &jbd2_seq_info_ops);
  783. if (rc == 0) {
  784. struct seq_file *m = file->private_data;
  785. m->private = s;
  786. } else {
  787. kfree(s->stats);
  788. kfree(s);
  789. }
  790. return rc;
  791. }
  792. static int jbd2_seq_info_release(struct inode *inode, struct file *file)
  793. {
  794. struct seq_file *seq = file->private_data;
  795. struct jbd2_stats_proc_session *s = seq->private;
  796. kfree(s->stats);
  797. kfree(s);
  798. return seq_release(inode, file);
  799. }
  800. static struct file_operations jbd2_seq_info_fops = {
  801. .owner = THIS_MODULE,
  802. .open = jbd2_seq_info_open,
  803. .read = seq_read,
  804. .llseek = seq_lseek,
  805. .release = jbd2_seq_info_release,
  806. };
  807. static struct proc_dir_entry *proc_jbd2_stats;
  808. static void jbd2_stats_proc_init(journal_t *journal)
  809. {
  810. journal->j_proc_entry = proc_mkdir(journal->j_devname, proc_jbd2_stats);
  811. if (journal->j_proc_entry) {
  812. proc_create_data("history", S_IRUGO, journal->j_proc_entry,
  813. &jbd2_seq_history_fops, journal);
  814. proc_create_data("info", S_IRUGO, journal->j_proc_entry,
  815. &jbd2_seq_info_fops, journal);
  816. }
  817. }
  818. static void jbd2_stats_proc_exit(journal_t *journal)
  819. {
  820. remove_proc_entry("info", journal->j_proc_entry);
  821. remove_proc_entry("history", journal->j_proc_entry);
  822. remove_proc_entry(journal->j_devname, proc_jbd2_stats);
  823. }
  824. static void journal_init_stats(journal_t *journal)
  825. {
  826. int size;
  827. if (!proc_jbd2_stats)
  828. return;
  829. journal->j_history_max = 100;
  830. size = sizeof(struct transaction_stats_s) * journal->j_history_max;
  831. journal->j_history = kzalloc(size, GFP_KERNEL);
  832. if (!journal->j_history) {
  833. journal->j_history_max = 0;
  834. return;
  835. }
  836. spin_lock_init(&journal->j_history_lock);
  837. }
  838. /*
  839. * Management for journal control blocks: functions to create and
  840. * destroy journal_t structures, and to initialise and read existing
  841. * journal blocks from disk. */
  842. /* First: create and setup a journal_t object in memory. We initialise
  843. * very few fields yet: that has to wait until we have created the
  844. * journal structures from from scratch, or loaded them from disk. */
  845. static journal_t * journal_init_common (void)
  846. {
  847. journal_t *journal;
  848. int err;
  849. journal = kzalloc(sizeof(*journal), GFP_KERNEL|__GFP_NOFAIL);
  850. if (!journal)
  851. goto fail;
  852. init_waitqueue_head(&journal->j_wait_transaction_locked);
  853. init_waitqueue_head(&journal->j_wait_logspace);
  854. init_waitqueue_head(&journal->j_wait_done_commit);
  855. init_waitqueue_head(&journal->j_wait_checkpoint);
  856. init_waitqueue_head(&journal->j_wait_commit);
  857. init_waitqueue_head(&journal->j_wait_updates);
  858. mutex_init(&journal->j_barrier);
  859. mutex_init(&journal->j_checkpoint_mutex);
  860. spin_lock_init(&journal->j_revoke_lock);
  861. spin_lock_init(&journal->j_list_lock);
  862. spin_lock_init(&journal->j_state_lock);
  863. journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
  864. /* The journal is marked for error until we succeed with recovery! */
  865. journal->j_flags = JBD2_ABORT;
  866. /* Set up a default-sized revoke table for the new mount. */
  867. err = jbd2_journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH);
  868. if (err) {
  869. kfree(journal);
  870. goto fail;
  871. }
  872. journal_init_stats(journal);
  873. return journal;
  874. fail:
  875. return NULL;
  876. }
  877. /* jbd2_journal_init_dev and jbd2_journal_init_inode:
  878. *
  879. * Create a journal structure assigned some fixed set of disk blocks to
  880. * the journal. We don't actually touch those disk blocks yet, but we
  881. * need to set up all of the mapping information to tell the journaling
  882. * system where the journal blocks are.
  883. *
  884. */
  885. /**
  886. * journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure
  887. * @bdev: Block device on which to create the journal
  888. * @fs_dev: Device which hold journalled filesystem for this journal.
  889. * @start: Block nr Start of journal.
  890. * @len: Length of the journal in blocks.
  891. * @blocksize: blocksize of journalling device
  892. *
  893. * Returns: a newly created journal_t *
  894. *
  895. * jbd2_journal_init_dev creates a journal which maps a fixed contiguous
  896. * range of blocks on an arbitrary block device.
  897. *
  898. */
  899. journal_t * jbd2_journal_init_dev(struct block_device *bdev,
  900. struct block_device *fs_dev,
  901. unsigned long long start, int len, int blocksize)
  902. {
  903. journal_t *journal = journal_init_common();
  904. struct buffer_head *bh;
  905. char *p;
  906. int n;
  907. if (!journal)
  908. return NULL;
  909. /* journal descriptor can store up to n blocks -bzzz */
  910. journal->j_blocksize = blocksize;
  911. n = journal->j_blocksize / sizeof(journal_block_tag_t);
  912. journal->j_wbufsize = n;
  913. journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
  914. if (!journal->j_wbuf) {
  915. printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
  916. __func__);
  917. kfree(journal);
  918. journal = NULL;
  919. goto out;
  920. }
  921. journal->j_dev = bdev;
  922. journal->j_fs_dev = fs_dev;
  923. journal->j_blk_offset = start;
  924. journal->j_maxlen = len;
  925. bdevname(journal->j_dev, journal->j_devname);
  926. p = journal->j_devname;
  927. while ((p = strchr(p, '/')))
  928. *p = '!';
  929. jbd2_stats_proc_init(journal);
  930. bh = __getblk(journal->j_dev, start, journal->j_blocksize);
  931. J_ASSERT(bh != NULL);
  932. journal->j_sb_buffer = bh;
  933. journal->j_superblock = (journal_superblock_t *)bh->b_data;
  934. out:
  935. return journal;
  936. }
  937. /**
  938. * journal_t * jbd2_journal_init_inode () - creates a journal which maps to a inode.
  939. * @inode: An inode to create the journal in
  940. *
  941. * jbd2_journal_init_inode creates a journal which maps an on-disk inode as
  942. * the journal. The inode must exist already, must support bmap() and
  943. * must have all data blocks preallocated.
  944. */
  945. journal_t * jbd2_journal_init_inode (struct inode *inode)
  946. {
  947. struct buffer_head *bh;
  948. journal_t *journal = journal_init_common();
  949. char *p;
  950. int err;
  951. int n;
  952. unsigned long long blocknr;
  953. if (!journal)
  954. return NULL;
  955. journal->j_dev = journal->j_fs_dev = inode->i_sb->s_bdev;
  956. journal->j_inode = inode;
  957. bdevname(journal->j_dev, journal->j_devname);
  958. p = journal->j_devname;
  959. while ((p = strchr(p, '/')))
  960. *p = '!';
  961. p = journal->j_devname + strlen(journal->j_devname);
  962. sprintf(p, ":%lu", journal->j_inode->i_ino);
  963. jbd_debug(1,
  964. "journal %p: inode %s/%ld, size %Ld, bits %d, blksize %ld\n",
  965. journal, inode->i_sb->s_id, inode->i_ino,
  966. (long long) inode->i_size,
  967. inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize);
  968. journal->j_maxlen = inode->i_size >> inode->i_sb->s_blocksize_bits;
  969. journal->j_blocksize = inode->i_sb->s_blocksize;
  970. jbd2_stats_proc_init(journal);
  971. /* journal descriptor can store up to n blocks -bzzz */
  972. n = journal->j_blocksize / sizeof(journal_block_tag_t);
  973. journal->j_wbufsize = n;
  974. journal->j_wbuf = kmalloc(n * sizeof(struct buffer_head*), GFP_KERNEL);
  975. if (!journal->j_wbuf) {
  976. printk(KERN_ERR "%s: Cant allocate bhs for commit thread\n",
  977. __func__);
  978. jbd2_stats_proc_exit(journal);
  979. kfree(journal);
  980. return NULL;
  981. }
  982. err = jbd2_journal_bmap(journal, 0, &blocknr);
  983. /* If that failed, give up */
  984. if (err) {
  985. printk(KERN_ERR "%s: Cannnot locate journal superblock\n",
  986. __func__);
  987. jbd2_stats_proc_exit(journal);
  988. kfree(journal);
  989. return NULL;
  990. }
  991. bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
  992. J_ASSERT(bh != NULL);
  993. journal->j_sb_buffer = bh;
  994. journal->j_superblock = (journal_superblock_t *)bh->b_data;
  995. return journal;
  996. }
  997. /*
  998. * If the journal init or create aborts, we need to mark the journal
  999. * superblock as being NULL to prevent the journal destroy from writing
  1000. * back a bogus superblock.
  1001. */
  1002. static void journal_fail_superblock (journal_t *journal)
  1003. {
  1004. struct buffer_head *bh = journal->j_sb_buffer;
  1005. brelse(bh);
  1006. journal->j_sb_buffer = NULL;
  1007. }
  1008. /*
  1009. * Given a journal_t structure, initialise the various fields for
  1010. * startup of a new journaling session. We use this both when creating
  1011. * a journal, and after recovering an old journal to reset it for
  1012. * subsequent use.
  1013. */
  1014. static int journal_reset(journal_t *journal)
  1015. {
  1016. journal_superblock_t *sb = journal->j_superblock;
  1017. unsigned long long first, last;
  1018. first = be32_to_cpu(sb->s_first);
  1019. last = be32_to_cpu(sb->s_maxlen);
  1020. journal->j_first = first;
  1021. journal->j_last = last;
  1022. journal->j_head = first;
  1023. journal->j_tail = first;
  1024. journal->j_free = last - first;
  1025. journal->j_tail_sequence = journal->j_transaction_sequence;
  1026. journal->j_commit_sequence = journal->j_transaction_sequence - 1;
  1027. journal->j_commit_request = journal->j_commit_sequence;
  1028. journal->j_max_transaction_buffers = journal->j_maxlen / 4;
  1029. /* Add the dynamic fields and write it to disk. */
  1030. jbd2_journal_update_superblock(journal, 1);
  1031. return jbd2_journal_start_thread(journal);
  1032. }
  1033. /**
  1034. * int jbd2_journal_create() - Initialise the new journal file
  1035. * @journal: Journal to create. This structure must have been initialised
  1036. *
  1037. * Given a journal_t structure which tells us which disk blocks we can
  1038. * use, create a new journal superblock and initialise all of the
  1039. * journal fields from scratch.
  1040. **/
  1041. int jbd2_journal_create(journal_t *journal)
  1042. {
  1043. unsigned long long blocknr;
  1044. struct buffer_head *bh;
  1045. journal_superblock_t *sb;
  1046. int i, err;
  1047. if (journal->j_maxlen < JBD2_MIN_JOURNAL_BLOCKS) {
  1048. printk (KERN_ERR "Journal length (%d blocks) too short.\n",
  1049. journal->j_maxlen);
  1050. journal_fail_superblock(journal);
  1051. return -EINVAL;
  1052. }
  1053. if (journal->j_inode == NULL) {
  1054. /*
  1055. * We don't know what block to start at!
  1056. */
  1057. printk(KERN_EMERG
  1058. "%s: creation of journal on external device!\n",
  1059. __func__);
  1060. BUG();
  1061. }
  1062. /* Zero out the entire journal on disk. We cannot afford to
  1063. have any blocks on disk beginning with JBD2_MAGIC_NUMBER. */
  1064. jbd_debug(1, "JBD: Zeroing out journal blocks...\n");
  1065. for (i = 0; i < journal->j_maxlen; i++) {
  1066. err = jbd2_journal_bmap(journal, i, &blocknr);
  1067. if (err)
  1068. return err;
  1069. bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
  1070. lock_buffer(bh);
  1071. memset (bh->b_data, 0, journal->j_blocksize);
  1072. BUFFER_TRACE(bh, "marking dirty");
  1073. mark_buffer_dirty(bh);
  1074. BUFFER_TRACE(bh, "marking uptodate");
  1075. set_buffer_uptodate(bh);
  1076. unlock_buffer(bh);
  1077. __brelse(bh);
  1078. }
  1079. sync_blockdev(journal->j_dev);
  1080. jbd_debug(1, "JBD: journal cleared.\n");
  1081. /* OK, fill in the initial static fields in the new superblock */
  1082. sb = journal->j_superblock;
  1083. sb->s_header.h_magic = cpu_to_be32(JBD2_MAGIC_NUMBER);
  1084. sb->s_header.h_blocktype = cpu_to_be32(JBD2_SUPERBLOCK_V2);
  1085. sb->s_blocksize = cpu_to_be32(journal->j_blocksize);
  1086. sb->s_maxlen = cpu_to_be32(journal->j_maxlen);
  1087. sb->s_first = cpu_to_be32(1);
  1088. journal->j_transaction_sequence = 1;
  1089. journal->j_flags &= ~JBD2_ABORT;
  1090. journal->j_format_version = 2;
  1091. return journal_reset(journal);
  1092. }
  1093. /**
  1094. * void jbd2_journal_update_superblock() - Update journal sb on disk.
  1095. * @journal: The journal to update.
  1096. * @wait: Set to '0' if you don't want to wait for IO completion.
  1097. *
  1098. * Update a journal's dynamic superblock fields and write it to disk,
  1099. * optionally waiting for the IO to complete.
  1100. */
  1101. void jbd2_journal_update_superblock(journal_t *journal, int wait)
  1102. {
  1103. journal_superblock_t *sb = journal->j_superblock;
  1104. struct buffer_head *bh = journal->j_sb_buffer;
  1105. /*
  1106. * As a special case, if the on-disk copy is already marked as needing
  1107. * no recovery (s_start == 0) and there are no outstanding transactions
  1108. * in the filesystem, then we can safely defer the superblock update
  1109. * until the next commit by setting JBD2_FLUSHED. This avoids
  1110. * attempting a write to a potential-readonly device.
  1111. */
  1112. if (sb->s_start == 0 && journal->j_tail_sequence ==
  1113. journal->j_transaction_sequence) {
  1114. jbd_debug(1,"JBD: Skipping superblock update on recovered sb "
  1115. "(start %ld, seq %d, errno %d)\n",
  1116. journal->j_tail, journal->j_tail_sequence,
  1117. journal->j_errno);
  1118. goto out;
  1119. }
  1120. if (buffer_write_io_error(bh)) {
  1121. /*
  1122. * Oh, dear. A previous attempt to write the journal
  1123. * superblock failed. This could happen because the
  1124. * USB device was yanked out. Or it could happen to
  1125. * be a transient write error and maybe the block will
  1126. * be remapped. Nothing we can do but to retry the
  1127. * write and hope for the best.
  1128. */
  1129. printk(KERN_ERR "JBD2: previous I/O error detected "
  1130. "for journal superblock update for %s.\n",
  1131. journal->j_devname);
  1132. clear_buffer_write_io_error(bh);
  1133. set_buffer_uptodate(bh);
  1134. }
  1135. spin_lock(&journal->j_state_lock);
  1136. jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n",
  1137. journal->j_tail, journal->j_tail_sequence, journal->j_errno);
  1138. sb->s_sequence = cpu_to_be32(journal->j_tail_sequence);
  1139. sb->s_start = cpu_to_be32(journal->j_tail);
  1140. sb->s_errno = cpu_to_be32(journal->j_errno);
  1141. spin_unlock(&journal->j_state_lock);
  1142. BUFFER_TRACE(bh, "marking dirty");
  1143. mark_buffer_dirty(bh);
  1144. if (wait) {
  1145. sync_dirty_buffer(bh);
  1146. if (buffer_write_io_error(bh)) {
  1147. printk(KERN_ERR "JBD2: I/O error detected "
  1148. "when updating journal superblock for %s.\n",
  1149. journal->j_devname);
  1150. clear_buffer_write_io_error(bh);
  1151. set_buffer_uptodate(bh);
  1152. }
  1153. } else
  1154. ll_rw_block(SWRITE, 1, &bh);
  1155. out:
  1156. /* If we have just flushed the log (by marking s_start==0), then
  1157. * any future commit will have to be careful to update the
  1158. * superblock again to re-record the true start of the log. */
  1159. spin_lock(&journal->j_state_lock);
  1160. if (sb->s_start)
  1161. journal->j_flags &= ~JBD2_FLUSHED;
  1162. else
  1163. journal->j_flags |= JBD2_FLUSHED;
  1164. spin_unlock(&journal->j_state_lock);
  1165. }
  1166. /*
  1167. * Read the superblock for a given journal, performing initial
  1168. * validation of the format.
  1169. */
  1170. static int journal_get_superblock(journal_t *journal)
  1171. {
  1172. struct buffer_head *bh;
  1173. journal_superblock_t *sb;
  1174. int err = -EIO;
  1175. bh = journal->j_sb_buffer;
  1176. J_ASSERT(bh != NULL);
  1177. if (!buffer_uptodate(bh)) {
  1178. ll_rw_block(READ, 1, &bh);
  1179. wait_on_buffer(bh);
  1180. if (!buffer_uptodate(bh)) {
  1181. printk (KERN_ERR
  1182. "JBD: IO error reading journal superblock\n");
  1183. goto out;
  1184. }
  1185. }
  1186. sb = journal->j_superblock;
  1187. err = -EINVAL;
  1188. if (sb->s_header.h_magic != cpu_to_be32(JBD2_MAGIC_NUMBER) ||
  1189. sb->s_blocksize != cpu_to_be32(journal->j_blocksize)) {
  1190. printk(KERN_WARNING "JBD: no valid journal superblock found\n");
  1191. goto out;
  1192. }
  1193. switch(be32_to_cpu(sb->s_header.h_blocktype)) {
  1194. case JBD2_SUPERBLOCK_V1:
  1195. journal->j_format_version = 1;
  1196. break;
  1197. case JBD2_SUPERBLOCK_V2:
  1198. journal->j_format_version = 2;
  1199. break;
  1200. default:
  1201. printk(KERN_WARNING "JBD: unrecognised superblock format ID\n");
  1202. goto out;
  1203. }
  1204. if (be32_to_cpu(sb->s_maxlen) < journal->j_maxlen)
  1205. journal->j_maxlen = be32_to_cpu(sb->s_maxlen);
  1206. else if (be32_to_cpu(sb->s_maxlen) > journal->j_maxlen) {
  1207. printk (KERN_WARNING "JBD: journal file too short\n");
  1208. goto out;
  1209. }
  1210. return 0;
  1211. out:
  1212. journal_fail_superblock(journal);
  1213. return err;
  1214. }
  1215. /*
  1216. * Load the on-disk journal superblock and read the key fields into the
  1217. * journal_t.
  1218. */
  1219. static int load_superblock(journal_t *journal)
  1220. {
  1221. int err;
  1222. journal_superblock_t *sb;
  1223. err = journal_get_superblock(journal);
  1224. if (err)
  1225. return err;
  1226. sb = journal->j_superblock;
  1227. journal->j_tail_sequence = be32_to_cpu(sb->s_sequence);
  1228. journal->j_tail = be32_to_cpu(sb->s_start);
  1229. journal->j_first = be32_to_cpu(sb->s_first);
  1230. journal->j_last = be32_to_cpu(sb->s_maxlen);
  1231. journal->j_errno = be32_to_cpu(sb->s_errno);
  1232. return 0;
  1233. }
  1234. /**
  1235. * int jbd2_journal_load() - Read journal from disk.
  1236. * @journal: Journal to act on.
  1237. *
  1238. * Given a journal_t structure which tells us which disk blocks contain
  1239. * a journal, read the journal from disk to initialise the in-memory
  1240. * structures.
  1241. */
  1242. int jbd2_journal_load(journal_t *journal)
  1243. {
  1244. int err;
  1245. journal_superblock_t *sb;
  1246. err = load_superblock(journal);
  1247. if (err)
  1248. return err;
  1249. sb = journal->j_superblock;
  1250. /* If this is a V2 superblock, then we have to check the
  1251. * features flags on it. */
  1252. if (journal->j_format_version >= 2) {
  1253. if ((sb->s_feature_ro_compat &
  1254. ~cpu_to_be32(JBD2_KNOWN_ROCOMPAT_FEATURES)) ||
  1255. (sb->s_feature_incompat &
  1256. ~cpu_to_be32(JBD2_KNOWN_INCOMPAT_FEATURES))) {
  1257. printk (KERN_WARNING
  1258. "JBD: Unrecognised features on journal\n");
  1259. return -EINVAL;
  1260. }
  1261. }
  1262. /* Let the recovery code check whether it needs to recover any
  1263. * data from the journal. */
  1264. if (jbd2_journal_recover(journal))
  1265. goto recovery_error;
  1266. /* OK, we've finished with the dynamic journal bits:
  1267. * reinitialise the dynamic contents of the superblock in memory
  1268. * and reset them on disk. */
  1269. if (journal_reset(journal))
  1270. goto recovery_error;
  1271. journal->j_flags &= ~JBD2_ABORT;
  1272. journal->j_flags |= JBD2_LOADED;
  1273. return 0;
  1274. recovery_error:
  1275. printk (KERN_WARNING "JBD: recovery failed\n");
  1276. return -EIO;
  1277. }
  1278. /**
  1279. * void jbd2_journal_destroy() - Release a journal_t structure.
  1280. * @journal: Journal to act on.
  1281. *
  1282. * Release a journal_t structure once it is no longer in use by the
  1283. * journaled object.
  1284. * Return <0 if we couldn't clean up the journal.
  1285. */
  1286. int jbd2_journal_destroy(journal_t *journal)
  1287. {
  1288. int err = 0;
  1289. /* Wait for the commit thread to wake up and die. */
  1290. journal_kill_thread(journal);
  1291. /* Force a final log commit */
  1292. if (journal->j_running_transaction)
  1293. jbd2_journal_commit_transaction(journal);
  1294. /* Force any old transactions to disk */
  1295. /* Totally anal locking here... */
  1296. spin_lock(&journal->j_list_lock);
  1297. while (journal->j_checkpoint_transactions != NULL) {
  1298. spin_unlock(&journal->j_list_lock);
  1299. jbd2_log_do_checkpoint(journal);
  1300. spin_lock(&journal->j_list_lock);
  1301. }
  1302. J_ASSERT(journal->j_running_transaction == NULL);
  1303. J_ASSERT(journal->j_committing_transaction == NULL);
  1304. J_ASSERT(journal->j_checkpoint_transactions == NULL);
  1305. spin_unlock(&journal->j_list_lock);
  1306. if (journal->j_sb_buffer) {
  1307. if (!is_journal_aborted(journal)) {
  1308. /* We can now mark the journal as empty. */
  1309. journal->j_tail = 0;
  1310. journal->j_tail_sequence =
  1311. ++journal->j_transaction_sequence;
  1312. jbd2_journal_update_superblock(journal, 1);
  1313. } else {
  1314. err = -EIO;
  1315. }
  1316. brelse(journal->j_sb_buffer);
  1317. }
  1318. if (journal->j_proc_entry)
  1319. jbd2_stats_proc_exit(journal);
  1320. if (journal->j_inode)
  1321. iput(journal->j_inode);
  1322. if (journal->j_revoke)
  1323. jbd2_journal_destroy_revoke(journal);
  1324. kfree(journal->j_wbuf);
  1325. kfree(journal);
  1326. return err;
  1327. }
  1328. /**
  1329. *int jbd2_journal_check_used_features () - Check if features specified are used.
  1330. * @journal: Journal to check.
  1331. * @compat: bitmask of compatible features
  1332. * @ro: bitmask of features that force read-only mount
  1333. * @incompat: bitmask of incompatible features
  1334. *
  1335. * Check whether the journal uses all of a given set of
  1336. * features. Return true (non-zero) if it does.
  1337. **/
  1338. int jbd2_journal_check_used_features (journal_t *journal, unsigned long compat,
  1339. unsigned long ro, unsigned long incompat)
  1340. {
  1341. journal_superblock_t *sb;
  1342. if (!compat && !ro && !incompat)
  1343. return 1;
  1344. if (journal->j_format_version == 1)
  1345. return 0;
  1346. sb = journal->j_superblock;
  1347. if (((be32_to_cpu(sb->s_feature_compat) & compat) == compat) &&
  1348. ((be32_to_cpu(sb->s_feature_ro_compat) & ro) == ro) &&
  1349. ((be32_to_cpu(sb->s_feature_incompat) & incompat) == incompat))
  1350. return 1;
  1351. return 0;
  1352. }
  1353. /**
  1354. * int jbd2_journal_check_available_features() - Check feature set in journalling layer
  1355. * @journal: Journal to check.
  1356. * @compat: bitmask of compatible features
  1357. * @ro: bitmask of features that force read-only mount
  1358. * @incompat: bitmask of incompatible features
  1359. *
  1360. * Check whether the journaling code supports the use of
  1361. * all of a given set of features on this journal. Return true
  1362. * (non-zero) if it can. */
  1363. int jbd2_journal_check_available_features (journal_t *journal, unsigned long compat,
  1364. unsigned long ro, unsigned long incompat)
  1365. {
  1366. journal_superblock_t *sb;
  1367. if (!compat && !ro && !incompat)
  1368. return 1;
  1369. sb = journal->j_superblock;
  1370. /* We can support any known requested features iff the
  1371. * superblock is in version 2. Otherwise we fail to support any
  1372. * extended sb features. */
  1373. if (journal->j_format_version != 2)
  1374. return 0;
  1375. if ((compat & JBD2_KNOWN_COMPAT_FEATURES) == compat &&
  1376. (ro & JBD2_KNOWN_ROCOMPAT_FEATURES) == ro &&
  1377. (incompat & JBD2_KNOWN_INCOMPAT_FEATURES) == incompat)
  1378. return 1;
  1379. return 0;
  1380. }
  1381. /**
  1382. * int jbd2_journal_set_features () - Mark a given journal feature in the superblock
  1383. * @journal: Journal to act on.
  1384. * @compat: bitmask of compatible features
  1385. * @ro: bitmask of features that force read-only mount
  1386. * @incompat: bitmask of incompatible features
  1387. *
  1388. * Mark a given journal feature as present on the
  1389. * superblock. Returns true if the requested features could be set.
  1390. *
  1391. */
  1392. int jbd2_journal_set_features (journal_t *journal, unsigned long compat,
  1393. unsigned long ro, unsigned long incompat)
  1394. {
  1395. journal_superblock_t *sb;
  1396. if (jbd2_journal_check_used_features(journal, compat, ro, incompat))
  1397. return 1;
  1398. if (!jbd2_journal_check_available_features(journal, compat, ro, incompat))
  1399. return 0;
  1400. jbd_debug(1, "Setting new features 0x%lx/0x%lx/0x%lx\n",
  1401. compat, ro, incompat);
  1402. sb = journal->j_superblock;
  1403. sb->s_feature_compat |= cpu_to_be32(compat);
  1404. sb->s_feature_ro_compat |= cpu_to_be32(ro);
  1405. sb->s_feature_incompat |= cpu_to_be32(incompat);
  1406. return 1;
  1407. }
  1408. /*
  1409. * jbd2_journal_clear_features () - Clear a given journal feature in the
  1410. * superblock
  1411. * @journal: Journal to act on.
  1412. * @compat: bitmask of compatible features
  1413. * @ro: bitmask of features that force read-only mount
  1414. * @incompat: bitmask of incompatible features
  1415. *
  1416. * Clear a given journal feature as present on the
  1417. * superblock.
  1418. */
  1419. void jbd2_journal_clear_features(journal_t *journal, unsigned long compat,
  1420. unsigned long ro, unsigned long incompat)
  1421. {
  1422. journal_superblock_t *sb;
  1423. jbd_debug(1, "Clear features 0x%lx/0x%lx/0x%lx\n",
  1424. compat, ro, incompat);
  1425. sb = journal->j_superblock;
  1426. sb->s_feature_compat &= ~cpu_to_be32(compat);
  1427. sb->s_feature_ro_compat &= ~cpu_to_be32(ro);
  1428. sb->s_feature_incompat &= ~cpu_to_be32(incompat);
  1429. }
  1430. EXPORT_SYMBOL(jbd2_journal_clear_features);
  1431. /**
  1432. * int jbd2_journal_update_format () - Update on-disk journal structure.
  1433. * @journal: Journal to act on.
  1434. *
  1435. * Given an initialised but unloaded journal struct, poke about in the
  1436. * on-disk structure to update it to the most recent supported version.
  1437. */
  1438. int jbd2_journal_update_format (journal_t *journal)
  1439. {
  1440. journal_superblock_t *sb;
  1441. int err;
  1442. err = journal_get_superblock(journal);
  1443. if (err)
  1444. return err;
  1445. sb = journal->j_superblock;
  1446. switch (be32_to_cpu(sb->s_header.h_blocktype)) {
  1447. case JBD2_SUPERBLOCK_V2:
  1448. return 0;
  1449. case JBD2_SUPERBLOCK_V1:
  1450. return journal_convert_superblock_v1(journal, sb);
  1451. default:
  1452. break;
  1453. }
  1454. return -EINVAL;
  1455. }
  1456. static int journal_convert_superblock_v1(journal_t *journal,
  1457. journal_superblock_t *sb)
  1458. {
  1459. int offset, blocksize;
  1460. struct buffer_head *bh;
  1461. printk(KERN_WARNING
  1462. "JBD: Converting superblock from version 1 to 2.\n");
  1463. /* Pre-initialise new fields to zero */
  1464. offset = ((char *) &(sb->s_feature_compat)) - ((char *) sb);
  1465. blocksize = be32_to_cpu(sb->s_blocksize);
  1466. memset(&sb->s_feature_compat, 0, blocksize-offset);
  1467. sb->s_nr_users = cpu_to_be32(1);
  1468. sb->s_header.h_blocktype = cpu_to_be32(JBD2_SUPERBLOCK_V2);
  1469. journal->j_format_version = 2;
  1470. bh = journal->j_sb_buffer;
  1471. BUFFER_TRACE(bh, "marking dirty");
  1472. mark_buffer_dirty(bh);
  1473. sync_dirty_buffer(bh);
  1474. return 0;
  1475. }
  1476. /**
  1477. * int jbd2_journal_flush () - Flush journal
  1478. * @journal: Journal to act on.
  1479. *
  1480. * Flush all data for a given journal to disk and empty the journal.
  1481. * Filesystems can use this when remounting readonly to ensure that
  1482. * recovery does not need to happen on remount.
  1483. */
  1484. int jbd2_journal_flush(journal_t *journal)
  1485. {
  1486. int err = 0;
  1487. transaction_t *transaction = NULL;
  1488. unsigned long old_tail;
  1489. spin_lock(&journal->j_state_lock);
  1490. /* Force everything buffered to the log... */
  1491. if (journal->j_running_transaction) {
  1492. transaction = journal->j_running_transaction;
  1493. __jbd2_log_start_commit(journal, transaction->t_tid);
  1494. } else if (journal->j_committing_transaction)
  1495. transaction = journal->j_committing_transaction;
  1496. /* Wait for the log commit to complete... */
  1497. if (transaction) {
  1498. tid_t tid = transaction->t_tid;
  1499. spin_unlock(&journal->j_state_lock);
  1500. jbd2_log_wait_commit(journal, tid);
  1501. } else {
  1502. spin_unlock(&journal->j_state_lock);
  1503. }
  1504. /* ...and flush everything in the log out to disk. */
  1505. spin_lock(&journal->j_list_lock);
  1506. while (!err && journal->j_checkpoint_transactions != NULL) {
  1507. spin_unlock(&journal->j_list_lock);
  1508. mutex_lock(&journal->j_checkpoint_mutex);
  1509. err = jbd2_log_do_checkpoint(journal);
  1510. mutex_unlock(&journal->j_checkpoint_mutex);
  1511. spin_lock(&journal->j_list_lock);
  1512. }
  1513. spin_unlock(&journal->j_list_lock);
  1514. if (is_journal_aborted(journal))
  1515. return -EIO;
  1516. jbd2_cleanup_journal_tail(journal);
  1517. /* Finally, mark the journal as really needing no recovery.
  1518. * This sets s_start==0 in the underlying superblock, which is
  1519. * the magic code for a fully-recovered superblock. Any future
  1520. * commits of data to the journal will restore the current
  1521. * s_start value. */
  1522. spin_lock(&journal->j_state_lock);
  1523. old_tail = journal->j_tail;
  1524. journal->j_tail = 0;
  1525. spin_unlock(&journal->j_state_lock);
  1526. jbd2_journal_update_superblock(journal, 1);
  1527. spin_lock(&journal->j_state_lock);
  1528. journal->j_tail = old_tail;
  1529. J_ASSERT(!journal->j_running_transaction);
  1530. J_ASSERT(!journal->j_committing_transaction);
  1531. J_ASSERT(!journal->j_checkpoint_transactions);
  1532. J_ASSERT(journal->j_head == journal->j_tail);
  1533. J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence);
  1534. spin_unlock(&journal->j_state_lock);
  1535. return 0;
  1536. }
  1537. /**
  1538. * int jbd2_journal_wipe() - Wipe journal contents
  1539. * @journal: Journal to act on.
  1540. * @write: flag (see below)
  1541. *
  1542. * Wipe out all of the contents of a journal, safely. This will produce
  1543. * a warning if the journal contains any valid recovery information.
  1544. * Must be called between journal_init_*() and jbd2_journal_load().
  1545. *
  1546. * If 'write' is non-zero, then we wipe out the journal on disk; otherwise
  1547. * we merely suppress recovery.
  1548. */
  1549. int jbd2_journal_wipe(journal_t *journal, int write)
  1550. {
  1551. journal_superblock_t *sb;
  1552. int err = 0;
  1553. J_ASSERT (!(journal->j_flags & JBD2_LOADED));
  1554. err = load_superblock(journal);
  1555. if (err)
  1556. return err;
  1557. sb = journal->j_superblock;
  1558. if (!journal->j_tail)
  1559. goto no_recovery;
  1560. printk (KERN_WARNING "JBD: %s recovery information on journal\n",
  1561. write ? "Clearing" : "Ignoring");
  1562. err = jbd2_journal_skip_recovery(journal);
  1563. if (write)
  1564. jbd2_journal_update_superblock(journal, 1);
  1565. no_recovery:
  1566. return err;
  1567. }
  1568. /*
  1569. * Journal abort has very specific semantics, which we describe
  1570. * for journal abort.
  1571. *
  1572. * Two internal function, which provide abort to te jbd layer
  1573. * itself are here.
  1574. */
  1575. /*
  1576. * Quick version for internal journal use (doesn't lock the journal).
  1577. * Aborts hard --- we mark the abort as occurred, but do _nothing_ else,
  1578. * and don't attempt to make any other journal updates.
  1579. */
  1580. void __jbd2_journal_abort_hard(journal_t *journal)
  1581. {
  1582. transaction_t *transaction;
  1583. if (journal->j_flags & JBD2_ABORT)
  1584. return;
  1585. printk(KERN_ERR "Aborting journal on device %s.\n",
  1586. journal->j_devname);
  1587. spin_lock(&journal->j_state_lock);
  1588. journal->j_flags |= JBD2_ABORT;
  1589. transaction = journal->j_running_transaction;
  1590. if (transaction)
  1591. __jbd2_log_start_commit(journal, transaction->t_tid);
  1592. spin_unlock(&journal->j_state_lock);
  1593. }
  1594. /* Soft abort: record the abort error status in the journal superblock,
  1595. * but don't do any other IO. */
  1596. static void __journal_abort_soft (journal_t *journal, int errno)
  1597. {
  1598. if (journal->j_flags & JBD2_ABORT)
  1599. return;
  1600. if (!journal->j_errno)
  1601. journal->j_errno = errno;
  1602. __jbd2_journal_abort_hard(journal);
  1603. if (errno)
  1604. jbd2_journal_update_superblock(journal, 1);
  1605. }
  1606. /**
  1607. * void jbd2_journal_abort () - Shutdown the journal immediately.
  1608. * @journal: the journal to shutdown.
  1609. * @errno: an error number to record in the journal indicating
  1610. * the reason for the shutdown.
  1611. *
  1612. * Perform a complete, immediate shutdown of the ENTIRE
  1613. * journal (not of a single transaction). This operation cannot be
  1614. * undone without closing and reopening the journal.
  1615. *
  1616. * The jbd2_journal_abort function is intended to support higher level error
  1617. * recovery mechanisms such as the ext2/ext3 remount-readonly error
  1618. * mode.
  1619. *
  1620. * Journal abort has very specific semantics. Any existing dirty,
  1621. * unjournaled buffers in the main filesystem will still be written to
  1622. * disk by bdflush, but the journaling mechanism will be suspended
  1623. * immediately and no further transaction commits will be honoured.
  1624. *
  1625. * Any dirty, journaled buffers will be written back to disk without
  1626. * hitting the journal. Atomicity cannot be guaranteed on an aborted
  1627. * filesystem, but we _do_ attempt to leave as much data as possible
  1628. * behind for fsck to use for cleanup.
  1629. *
  1630. * Any attempt to get a new transaction handle on a journal which is in
  1631. * ABORT state will just result in an -EROFS error return. A
  1632. * jbd2_journal_stop on an existing handle will return -EIO if we have
  1633. * entered abort state during the update.
  1634. *
  1635. * Recursive transactions are not disturbed by journal abort until the
  1636. * final jbd2_journal_stop, which will receive the -EIO error.
  1637. *
  1638. * Finally, the jbd2_journal_abort call allows the caller to supply an errno
  1639. * which will be recorded (if possible) in the journal superblock. This
  1640. * allows a client to record failure conditions in the middle of a
  1641. * transaction without having to complete the transaction to record the
  1642. * failure to disk. ext3_error, for example, now uses this
  1643. * functionality.
  1644. *
  1645. * Errors which originate from within the journaling layer will NOT
  1646. * supply an errno; a null errno implies that absolutely no further
  1647. * writes are done to the journal (unless there are any already in
  1648. * progress).
  1649. *
  1650. */
  1651. void jbd2_journal_abort(journal_t *journal, int errno)
  1652. {
  1653. __journal_abort_soft(journal, errno);
  1654. }
  1655. /**
  1656. * int jbd2_journal_errno () - returns the journal's error state.
  1657. * @journal: journal to examine.
  1658. *
  1659. * This is the errno numbet set with jbd2_journal_abort(), the last
  1660. * time the journal was mounted - if the journal was stopped
  1661. * without calling abort this will be 0.
  1662. *
  1663. * If the journal has been aborted on this mount time -EROFS will
  1664. * be returned.
  1665. */
  1666. int jbd2_journal_errno(journal_t *journal)
  1667. {
  1668. int err;
  1669. spin_lock(&journal->j_state_lock);
  1670. if (journal->j_flags & JBD2_ABORT)
  1671. err = -EROFS;
  1672. else
  1673. err = journal->j_errno;
  1674. spin_unlock(&journal->j_state_lock);
  1675. return err;
  1676. }
  1677. /**
  1678. * int jbd2_journal_clear_err () - clears the journal's error state
  1679. * @journal: journal to act on.
  1680. *
  1681. * An error must be cleared or Acked to take a FS out of readonly
  1682. * mode.
  1683. */
  1684. int jbd2_journal_clear_err(journal_t *journal)
  1685. {
  1686. int err = 0;
  1687. spin_lock(&journal->j_state_lock);
  1688. if (journal->j_flags & JBD2_ABORT)
  1689. err = -EROFS;
  1690. else
  1691. journal->j_errno = 0;
  1692. spin_unlock(&journal->j_state_lock);
  1693. return err;
  1694. }
  1695. /**
  1696. * void jbd2_journal_ack_err() - Ack journal err.
  1697. * @journal: journal to act on.
  1698. *
  1699. * An error must be cleared or Acked to take a FS out of readonly
  1700. * mode.
  1701. */
  1702. void jbd2_journal_ack_err(journal_t *journal)
  1703. {
  1704. spin_lock(&journal->j_state_lock);
  1705. if (journal->j_errno)
  1706. journal->j_flags |= JBD2_ACK_ERR;
  1707. spin_unlock(&journal->j_state_lock);
  1708. }
  1709. int jbd2_journal_blocks_per_page(struct inode *inode)
  1710. {
  1711. return 1 << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
  1712. }
  1713. /*
  1714. * helper functions to deal with 32 or 64bit block numbers.
  1715. */
  1716. size_t journal_tag_bytes(journal_t *journal)
  1717. {
  1718. if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_64BIT))
  1719. return JBD2_TAG_SIZE64;
  1720. else
  1721. return JBD2_TAG_SIZE32;
  1722. }
  1723. /*
  1724. * Journal_head storage management
  1725. */
  1726. static struct kmem_cache *jbd2_journal_head_cache;
  1727. #ifdef CONFIG_JBD2_DEBUG
  1728. static atomic_t nr_journal_heads = ATOMIC_INIT(0);
  1729. #endif
  1730. static int journal_init_jbd2_journal_head_cache(void)
  1731. {
  1732. int retval;
  1733. J_ASSERT(jbd2_journal_head_cache == NULL);
  1734. jbd2_journal_head_cache = kmem_cache_create("jbd2_journal_head",
  1735. sizeof(struct journal_head),
  1736. 0, /* offset */
  1737. SLAB_TEMPORARY, /* flags */
  1738. NULL); /* ctor */
  1739. retval = 0;
  1740. if (!jbd2_journal_head_cache) {
  1741. retval = -ENOMEM;
  1742. printk(KERN_EMERG "JBD: no memory for journal_head cache\n");
  1743. }
  1744. return retval;
  1745. }
  1746. static void jbd2_journal_destroy_jbd2_journal_head_cache(void)
  1747. {
  1748. if (jbd2_journal_head_cache) {
  1749. kmem_cache_destroy(jbd2_journal_head_cache);
  1750. jbd2_journal_head_cache = NULL;
  1751. }
  1752. }
  1753. /*
  1754. * journal_head splicing and dicing
  1755. */
  1756. static struct journal_head *journal_alloc_journal_head(void)
  1757. {
  1758. struct journal_head *ret;
  1759. static unsigned long last_warning;
  1760. #ifdef CONFIG_JBD2_DEBUG
  1761. atomic_inc(&nr_journal_heads);
  1762. #endif
  1763. ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
  1764. if (!ret) {
  1765. jbd_debug(1, "out of memory for journal_head\n");
  1766. if (time_after(jiffies, last_warning + 5*HZ)) {
  1767. printk(KERN_NOTICE "ENOMEM in %s, retrying.\n",
  1768. __func__);
  1769. last_warning = jiffies;
  1770. }
  1771. while (!ret) {
  1772. yield();
  1773. ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
  1774. }
  1775. }
  1776. return ret;
  1777. }
  1778. static void journal_free_journal_head(struct journal_head *jh)
  1779. {
  1780. #ifdef CONFIG_JBD2_DEBUG
  1781. atomic_dec(&nr_journal_heads);
  1782. memset(jh, JBD2_POISON_FREE, sizeof(*jh));
  1783. #endif
  1784. kmem_cache_free(jbd2_journal_head_cache, jh);
  1785. }
  1786. /*
  1787. * A journal_head is attached to a buffer_head whenever JBD has an
  1788. * interest in the buffer.
  1789. *
  1790. * Whenever a buffer has an attached journal_head, its ->b_state:BH_JBD bit
  1791. * is set. This bit is tested in core kernel code where we need to take
  1792. * JBD-specific actions. Testing the zeroness of ->b_private is not reliable
  1793. * there.
  1794. *
  1795. * When a buffer has its BH_JBD bit set, its ->b_count is elevated by one.
  1796. *
  1797. * When a buffer has its BH_JBD bit set it is immune from being released by
  1798. * core kernel code, mainly via ->b_count.
  1799. *
  1800. * A journal_head may be detached from its buffer_head when the journal_head's
  1801. * b_transaction, b_cp_transaction and b_next_transaction pointers are NULL.
  1802. * Various places in JBD call jbd2_journal_remove_journal_head() to indicate that the
  1803. * journal_head can be dropped if needed.
  1804. *
  1805. * Various places in the kernel want to attach a journal_head to a buffer_head
  1806. * _before_ attaching the journal_head to a transaction. To protect the
  1807. * journal_head in this situation, jbd2_journal_add_journal_head elevates the
  1808. * journal_head's b_jcount refcount by one. The caller must call
  1809. * jbd2_journal_put_journal_head() to undo this.
  1810. *
  1811. * So the typical usage would be:
  1812. *
  1813. * (Attach a journal_head if needed. Increments b_jcount)
  1814. * struct journal_head *jh = jbd2_journal_add_journal_head(bh);
  1815. * ...
  1816. * jh->b_transaction = xxx;
  1817. * jbd2_journal_put_journal_head(jh);
  1818. *
  1819. * Now, the journal_head's b_jcount is zero, but it is safe from being released
  1820. * because it has a non-zero b_transaction.
  1821. */
  1822. /*
  1823. * Give a buffer_head a journal_head.
  1824. *
  1825. * Doesn't need the journal lock.
  1826. * May sleep.
  1827. */
  1828. struct journal_head *jbd2_journal_add_journal_head(struct buffer_head *bh)
  1829. {
  1830. struct journal_head *jh;
  1831. struct journal_head *new_jh = NULL;
  1832. repeat:
  1833. if (!buffer_jbd(bh)) {
  1834. new_jh = journal_alloc_journal_head();
  1835. memset(new_jh, 0, sizeof(*new_jh));
  1836. }
  1837. jbd_lock_bh_journal_head(bh);
  1838. if (buffer_jbd(bh)) {
  1839. jh = bh2jh(bh);
  1840. } else {
  1841. J_ASSERT_BH(bh,
  1842. (atomic_read(&bh->b_count) > 0) ||
  1843. (bh->b_page && bh->b_page->mapping));
  1844. if (!new_jh) {
  1845. jbd_unlock_bh_journal_head(bh);
  1846. goto repeat;
  1847. }
  1848. jh = new_jh;
  1849. new_jh = NULL; /* We consumed it */
  1850. set_buffer_jbd(bh);
  1851. bh->b_private = jh;
  1852. jh->b_bh = bh;
  1853. get_bh(bh);
  1854. BUFFER_TRACE(bh, "added journal_head");
  1855. }
  1856. jh->b_jcount++;
  1857. jbd_unlock_bh_journal_head(bh);
  1858. if (new_jh)
  1859. journal_free_journal_head(new_jh);
  1860. return bh->b_private;
  1861. }
  1862. /*
  1863. * Grab a ref against this buffer_head's journal_head. If it ended up not
  1864. * having a journal_head, return NULL
  1865. */
  1866. struct journal_head *jbd2_journal_grab_journal_head(struct buffer_head *bh)
  1867. {
  1868. struct journal_head *jh = NULL;
  1869. jbd_lock_bh_journal_head(bh);
  1870. if (buffer_jbd(bh)) {
  1871. jh = bh2jh(bh);
  1872. jh->b_jcount++;
  1873. }
  1874. jbd_unlock_bh_journal_head(bh);
  1875. return jh;
  1876. }
  1877. static void __journal_remove_journal_head(struct buffer_head *bh)
  1878. {
  1879. struct journal_head *jh = bh2jh(bh);
  1880. J_ASSERT_JH(jh, jh->b_jcount >= 0);
  1881. get_bh(bh);
  1882. if (jh->b_jcount == 0) {
  1883. if (jh->b_transaction == NULL &&
  1884. jh->b_next_transaction == NULL &&
  1885. jh->b_cp_transaction == NULL) {
  1886. J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
  1887. J_ASSERT_BH(bh, buffer_jbd(bh));
  1888. J_ASSERT_BH(bh, jh2bh(jh) == bh);
  1889. BUFFER_TRACE(bh, "remove journal_head");
  1890. if (jh->b_frozen_data) {
  1891. printk(KERN_WARNING "%s: freeing "
  1892. "b_frozen_data\n",
  1893. __func__);
  1894. jbd2_free(jh->b_frozen_data, bh->b_size);
  1895. }
  1896. if (jh->b_committed_data) {
  1897. printk(KERN_WARNING "%s: freeing "
  1898. "b_committed_data\n",
  1899. __func__);
  1900. jbd2_free(jh->b_committed_data, bh->b_size);
  1901. }
  1902. bh->b_private = NULL;
  1903. jh->b_bh = NULL; /* debug, really */
  1904. clear_buffer_jbd(bh);
  1905. __brelse(bh);
  1906. journal_free_journal_head(jh);
  1907. } else {
  1908. BUFFER_TRACE(bh, "journal_head was locked");
  1909. }
  1910. }
  1911. }
  1912. /*
  1913. * jbd2_journal_remove_journal_head(): if the buffer isn't attached to a transaction
  1914. * and has a zero b_jcount then remove and release its journal_head. If we did
  1915. * see that the buffer is not used by any transaction we also "logically"
  1916. * decrement ->b_count.
  1917. *
  1918. * We in fact take an additional increment on ->b_count as a convenience,
  1919. * because the caller usually wants to do additional things with the bh
  1920. * after calling here.
  1921. * The caller of jbd2_journal_remove_journal_head() *must* run __brelse(bh) at some
  1922. * time. Once the caller has run __brelse(), the buffer is eligible for
  1923. * reaping by try_to_free_buffers().
  1924. */
  1925. void jbd2_journal_remove_journal_head(struct buffer_head *bh)
  1926. {
  1927. jbd_lock_bh_journal_head(bh);
  1928. __journal_remove_journal_head(bh);
  1929. jbd_unlock_bh_journal_head(bh);
  1930. }
  1931. /*
  1932. * Drop a reference on the passed journal_head. If it fell to zero then try to
  1933. * release the journal_head from the buffer_head.
  1934. */
  1935. void jbd2_journal_put_journal_head(struct journal_head *jh)
  1936. {
  1937. struct buffer_head *bh = jh2bh(jh);
  1938. jbd_lock_bh_journal_head(bh);
  1939. J_ASSERT_JH(jh, jh->b_jcount > 0);
  1940. --jh->b_jcount;
  1941. if (!jh->b_jcount && !jh->b_transaction) {
  1942. __journal_remove_journal_head(bh);
  1943. __brelse(bh);
  1944. }
  1945. jbd_unlock_bh_journal_head(bh);
  1946. }
  1947. /*
  1948. * Initialize jbd inode head
  1949. */
  1950. void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode)
  1951. {
  1952. jinode->i_transaction = NULL;
  1953. jinode->i_next_transaction = NULL;
  1954. jinode->i_vfs_inode = inode;
  1955. jinode->i_flags = 0;
  1956. INIT_LIST_HEAD(&jinode->i_list);
  1957. }
  1958. /*
  1959. * Function to be called before we start removing inode from memory (i.e.,
  1960. * clear_inode() is a fine place to be called from). It removes inode from
  1961. * transaction's lists.
  1962. */
  1963. void jbd2_journal_release_jbd_inode(journal_t *journal,
  1964. struct jbd2_inode *jinode)
  1965. {
  1966. int writeout = 0;
  1967. if (!journal)
  1968. return;
  1969. restart:
  1970. spin_lock(&journal->j_list_lock);
  1971. /* Is commit writing out inode - we have to wait */
  1972. if (jinode->i_flags & JI_COMMIT_RUNNING) {
  1973. wait_queue_head_t *wq;
  1974. DEFINE_WAIT_BIT(wait, &jinode->i_flags, __JI_COMMIT_RUNNING);
  1975. wq = bit_waitqueue(&jinode->i_flags, __JI_COMMIT_RUNNING);
  1976. prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
  1977. spin_unlock(&journal->j_list_lock);
  1978. schedule();
  1979. finish_wait(wq, &wait.wait);
  1980. goto restart;
  1981. }
  1982. /* Do we need to wait for data writeback? */
  1983. if (journal->j_committing_transaction == jinode->i_transaction)
  1984. writeout = 1;
  1985. if (jinode->i_transaction) {
  1986. list_del(&jinode->i_list);
  1987. jinode->i_transaction = NULL;
  1988. }
  1989. spin_unlock(&journal->j_list_lock);
  1990. }
  1991. /*
  1992. * debugfs tunables
  1993. */
  1994. #ifdef CONFIG_JBD2_DEBUG
  1995. u8 jbd2_journal_enable_debug __read_mostly;
  1996. EXPORT_SYMBOL(jbd2_journal_enable_debug);
  1997. #define JBD2_DEBUG_NAME "jbd2-debug"
  1998. static struct dentry *jbd2_debugfs_dir;
  1999. static struct dentry *jbd2_debug;
  2000. static void __init jbd2_create_debugfs_entry(void)
  2001. {
  2002. jbd2_debugfs_dir = debugfs_create_dir("jbd2", NULL);
  2003. if (jbd2_debugfs_dir)
  2004. jbd2_debug = debugfs_create_u8(JBD2_DEBUG_NAME, S_IRUGO,
  2005. jbd2_debugfs_dir,
  2006. &jbd2_journal_enable_debug);
  2007. }
  2008. static void __exit jbd2_remove_debugfs_entry(void)
  2009. {
  2010. debugfs_remove(jbd2_debug);
  2011. debugfs_remove(jbd2_debugfs_dir);
  2012. }
  2013. #else
  2014. static void __init jbd2_create_debugfs_entry(void)
  2015. {
  2016. }
  2017. static void __exit jbd2_remove_debugfs_entry(void)
  2018. {
  2019. }
  2020. #endif
  2021. #ifdef CONFIG_PROC_FS
  2022. #define JBD2_STATS_PROC_NAME "fs/jbd2"
  2023. static void __init jbd2_create_jbd_stats_proc_entry(void)
  2024. {
  2025. proc_jbd2_stats = proc_mkdir(JBD2_STATS_PROC_NAME, NULL);
  2026. }
  2027. static void __exit jbd2_remove_jbd_stats_proc_entry(void)
  2028. {
  2029. if (proc_jbd2_stats)
  2030. remove_proc_entry(JBD2_STATS_PROC_NAME, NULL);
  2031. }
  2032. #else
  2033. #define jbd2_create_jbd_stats_proc_entry() do {} while (0)
  2034. #define jbd2_remove_jbd_stats_proc_entry() do {} while (0)
  2035. #endif
  2036. struct kmem_cache *jbd2_handle_cache;
  2037. static int __init journal_init_handle_cache(void)
  2038. {
  2039. jbd2_handle_cache = kmem_cache_create("jbd2_journal_handle",
  2040. sizeof(handle_t),
  2041. 0, /* offset */
  2042. SLAB_TEMPORARY, /* flags */
  2043. NULL); /* ctor */
  2044. if (jbd2_handle_cache == NULL) {
  2045. printk(KERN_EMERG "JBD: failed to create handle cache\n");
  2046. return -ENOMEM;
  2047. }
  2048. return 0;
  2049. }
  2050. static void jbd2_journal_destroy_handle_cache(void)
  2051. {
  2052. if (jbd2_handle_cache)
  2053. kmem_cache_destroy(jbd2_handle_cache);
  2054. }
  2055. /*
  2056. * Module startup and shutdown
  2057. */
  2058. static int __init journal_init_caches(void)
  2059. {
  2060. int ret;
  2061. ret = jbd2_journal_init_revoke_caches();
  2062. if (ret == 0)
  2063. ret = journal_init_jbd2_journal_head_cache();
  2064. if (ret == 0)
  2065. ret = journal_init_handle_cache();
  2066. return ret;
  2067. }
  2068. static void jbd2_journal_destroy_caches(void)
  2069. {
  2070. jbd2_journal_destroy_revoke_caches();
  2071. jbd2_journal_destroy_jbd2_journal_head_cache();
  2072. jbd2_journal_destroy_handle_cache();
  2073. }
  2074. static int __init journal_init(void)
  2075. {
  2076. int ret;
  2077. BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024);
  2078. ret = journal_init_caches();
  2079. if (ret == 0) {
  2080. jbd2_create_debugfs_entry();
  2081. jbd2_create_jbd_stats_proc_entry();
  2082. } else {
  2083. jbd2_journal_destroy_caches();
  2084. }
  2085. return ret;
  2086. }
  2087. static void __exit journal_exit(void)
  2088. {
  2089. #ifdef CONFIG_JBD2_DEBUG
  2090. int n = atomic_read(&nr_journal_heads);
  2091. if (n)
  2092. printk(KERN_EMERG "JBD: leaked %d journal_heads!\n", n);
  2093. #endif
  2094. jbd2_remove_debugfs_entry();
  2095. jbd2_remove_jbd_stats_proc_entry();
  2096. jbd2_journal_destroy_caches();
  2097. }
  2098. MODULE_LICENSE("GPL");
  2099. module_init(journal_init);
  2100. module_exit(journal_exit);