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