journal.c 66 KB

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