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. #include <linux/ratelimit.h>
  46. #define CREATE_TRACE_POINTS
  47. #include <trace/events/jbd2.h>
  48. #include <asm/uaccess.h>
  49. #include <asm/page.h>
  50. #include <asm/system.h>
  51. EXPORT_SYMBOL(jbd2_journal_extend);
  52. EXPORT_SYMBOL(jbd2_journal_stop);
  53. EXPORT_SYMBOL(jbd2_journal_lock_updates);
  54. EXPORT_SYMBOL(jbd2_journal_unlock_updates);
  55. EXPORT_SYMBOL(jbd2_journal_get_write_access);
  56. EXPORT_SYMBOL(jbd2_journal_get_create_access);
  57. EXPORT_SYMBOL(jbd2_journal_get_undo_access);
  58. EXPORT_SYMBOL(jbd2_journal_set_triggers);
  59. EXPORT_SYMBOL(jbd2_journal_dirty_metadata);
  60. EXPORT_SYMBOL(jbd2_journal_release_buffer);
  61. EXPORT_SYMBOL(jbd2_journal_forget);
  62. #if 0
  63. EXPORT_SYMBOL(journal_sync_buffer);
  64. #endif
  65. EXPORT_SYMBOL(jbd2_journal_flush);
  66. EXPORT_SYMBOL(jbd2_journal_revoke);
  67. EXPORT_SYMBOL(jbd2_journal_init_dev);
  68. EXPORT_SYMBOL(jbd2_journal_init_inode);
  69. EXPORT_SYMBOL(jbd2_journal_update_format);
  70. EXPORT_SYMBOL(jbd2_journal_check_used_features);
  71. EXPORT_SYMBOL(jbd2_journal_check_available_features);
  72. EXPORT_SYMBOL(jbd2_journal_set_features);
  73. EXPORT_SYMBOL(jbd2_journal_load);
  74. EXPORT_SYMBOL(jbd2_journal_destroy);
  75. EXPORT_SYMBOL(jbd2_journal_abort);
  76. EXPORT_SYMBOL(jbd2_journal_errno);
  77. EXPORT_SYMBOL(jbd2_journal_ack_err);
  78. EXPORT_SYMBOL(jbd2_journal_clear_err);
  79. EXPORT_SYMBOL(jbd2_log_wait_commit);
  80. EXPORT_SYMBOL(jbd2_log_start_commit);
  81. EXPORT_SYMBOL(jbd2_journal_start_commit);
  82. EXPORT_SYMBOL(jbd2_journal_force_commit_nested);
  83. EXPORT_SYMBOL(jbd2_journal_wipe);
  84. EXPORT_SYMBOL(jbd2_journal_blocks_per_page);
  85. EXPORT_SYMBOL(jbd2_journal_invalidatepage);
  86. EXPORT_SYMBOL(jbd2_journal_try_to_free_buffers);
  87. EXPORT_SYMBOL(jbd2_journal_force_commit);
  88. EXPORT_SYMBOL(jbd2_journal_file_inode);
  89. EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
  90. EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
  91. EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
  92. EXPORT_SYMBOL(jbd2_inode_cache);
  93. static int journal_convert_superblock_v1(journal_t *, journal_superblock_t *);
  94. static void __journal_abort_soft (journal_t *journal, int errno);
  95. static int jbd2_journal_create_slab(size_t slab_size);
  96. /*
  97. * Helper function used to manage commit timeouts
  98. */
  99. static void commit_timeout(unsigned long __data)
  100. {
  101. struct task_struct * p = (struct task_struct *) __data;
  102. wake_up_process(p);
  103. }
  104. /*
  105. * kjournald2: The main thread function used to manage a logging device
  106. * journal.
  107. *
  108. * This kernel thread is responsible for two things:
  109. *
  110. * 1) COMMIT: Every so often we need to commit the current state of the
  111. * filesystem to disk. The journal thread is responsible for writing
  112. * all of the metadata buffers to disk.
  113. *
  114. * 2) CHECKPOINT: We cannot reuse a used section of the log file until all
  115. * of the data in that part of the log has been rewritten elsewhere on
  116. * the disk. Flushing these old buffers to reclaim space in the log is
  117. * known as checkpointing, and this thread is responsible for that job.
  118. */
  119. static int kjournald2(void *arg)
  120. {
  121. journal_t *journal = arg;
  122. transaction_t *transaction;
  123. /*
  124. * Set up an interval timer which can be used to trigger a commit wakeup
  125. * after the commit interval expires
  126. */
  127. setup_timer(&journal->j_commit_timer, commit_timeout,
  128. (unsigned long)current);
  129. /* Record that the journal thread is running */
  130. journal->j_task = current;
  131. wake_up(&journal->j_wait_done_commit);
  132. /*
  133. * And now, wait forever for commit wakeup events.
  134. */
  135. write_lock(&journal->j_state_lock);
  136. loop:
  137. if (journal->j_flags & JBD2_UNMOUNT)
  138. goto end_loop;
  139. jbd_debug(1, "commit_sequence=%d, commit_request=%d\n",
  140. journal->j_commit_sequence, journal->j_commit_request);
  141. if (journal->j_commit_sequence != journal->j_commit_request) {
  142. jbd_debug(1, "OK, requests differ\n");
  143. write_unlock(&journal->j_state_lock);
  144. del_timer_sync(&journal->j_commit_timer);
  145. jbd2_journal_commit_transaction(journal);
  146. write_lock(&journal->j_state_lock);
  147. goto loop;
  148. }
  149. wake_up(&journal->j_wait_done_commit);
  150. if (freezing(current)) {
  151. /*
  152. * The simpler the better. Flushing journal isn't a
  153. * good idea, because that depends on threads that may
  154. * be already stopped.
  155. */
  156. jbd_debug(1, "Now suspending kjournald2\n");
  157. write_unlock(&journal->j_state_lock);
  158. refrigerator();
  159. write_lock(&journal->j_state_lock);
  160. } else {
  161. /*
  162. * We assume on resume that commits are already there,
  163. * so we don't sleep
  164. */
  165. DEFINE_WAIT(wait);
  166. int should_sleep = 1;
  167. prepare_to_wait(&journal->j_wait_commit, &wait,
  168. TASK_INTERRUPTIBLE);
  169. if (journal->j_commit_sequence != journal->j_commit_request)
  170. should_sleep = 0;
  171. transaction = journal->j_running_transaction;
  172. if (transaction && time_after_eq(jiffies,
  173. transaction->t_expires))
  174. should_sleep = 0;
  175. if (journal->j_flags & JBD2_UNMOUNT)
  176. should_sleep = 0;
  177. if (should_sleep) {
  178. write_unlock(&journal->j_state_lock);
  179. schedule();
  180. write_lock(&journal->j_state_lock);
  181. }
  182. finish_wait(&journal->j_wait_commit, &wait);
  183. }
  184. jbd_debug(1, "kjournald2 wakes\n");
  185. /*
  186. * Were we woken up by a commit wakeup event?
  187. */
  188. transaction = journal->j_running_transaction;
  189. if (transaction && time_after_eq(jiffies, transaction->t_expires)) {
  190. journal->j_commit_request = transaction->t_tid;
  191. jbd_debug(1, "woke because of timeout\n");
  192. }
  193. goto loop;
  194. end_loop:
  195. write_unlock(&journal->j_state_lock);
  196. del_timer_sync(&journal->j_commit_timer);
  197. journal->j_task = NULL;
  198. wake_up(&journal->j_wait_done_commit);
  199. jbd_debug(1, "Journal thread exiting.\n");
  200. return 0;
  201. }
  202. static int jbd2_journal_start_thread(journal_t *journal)
  203. {
  204. struct task_struct *t;
  205. t = kthread_run(kjournald2, journal, "jbd2/%s",
  206. journal->j_devname);
  207. if (IS_ERR(t))
  208. return PTR_ERR(t);
  209. wait_event(journal->j_wait_done_commit, journal->j_task != NULL);
  210. return 0;
  211. }
  212. static void journal_kill_thread(journal_t *journal)
  213. {
  214. write_lock(&journal->j_state_lock);
  215. journal->j_flags |= JBD2_UNMOUNT;
  216. while (journal->j_task) {
  217. wake_up(&journal->j_wait_commit);
  218. write_unlock(&journal->j_state_lock);
  219. wait_event(journal->j_wait_done_commit, journal->j_task == NULL);
  220. write_lock(&journal->j_state_lock);
  221. }
  222. write_unlock(&journal->j_state_lock);
  223. }
  224. /*
  225. * jbd2_journal_write_metadata_buffer: write a metadata buffer to the journal.
  226. *
  227. * Writes a metadata buffer to a given disk block. The actual IO is not
  228. * performed but a new buffer_head is constructed which labels the data
  229. * to be written with the correct destination disk block.
  230. *
  231. * Any magic-number escaping which needs to be done will cause a
  232. * copy-out here. If the buffer happens to start with the
  233. * JBD2_MAGIC_NUMBER, then we can't write it to the log directly: the
  234. * magic number is only written to the log for descripter blocks. In
  235. * this case, we copy the data and replace the first word with 0, and we
  236. * return a result code which indicates that this buffer needs to be
  237. * marked as an escaped buffer in the corresponding log descriptor
  238. * block. The missing word can then be restored when the block is read
  239. * during recovery.
  240. *
  241. * If the source buffer has already been modified by a new transaction
  242. * since we took the last commit snapshot, we use the frozen copy of
  243. * that data for IO. If we end up using the existing buffer_head's data
  244. * for the write, then we *have* to lock the buffer to prevent anyone
  245. * else from using and possibly modifying it while the IO is in
  246. * progress.
  247. *
  248. * The function returns a pointer to the buffer_heads to be used for IO.
  249. *
  250. * We assume that the journal has already been locked in this function.
  251. *
  252. * Return value:
  253. * <0: Error
  254. * >=0: Finished OK
  255. *
  256. * On success:
  257. * Bit 0 set == escape performed on the data
  258. * Bit 1 set == buffer copy-out performed (kfree the data after IO)
  259. */
  260. int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
  261. struct journal_head *jh_in,
  262. struct journal_head **jh_out,
  263. unsigned long long blocknr)
  264. {
  265. int need_copy_out = 0;
  266. int done_copy_out = 0;
  267. int do_escape = 0;
  268. char *mapped_data;
  269. struct buffer_head *new_bh;
  270. struct journal_head *new_jh;
  271. struct page *new_page;
  272. unsigned int new_offset;
  273. struct buffer_head *bh_in = jh2bh(jh_in);
  274. journal_t *journal = transaction->t_journal;
  275. /*
  276. * The buffer really shouldn't be locked: only the current committing
  277. * transaction is allowed to write it, so nobody else is allowed
  278. * to do any IO.
  279. *
  280. * akpm: except if we're journalling data, and write() output is
  281. * also part of a shared mapping, and another thread has
  282. * decided to launch a writepage() against this buffer.
  283. */
  284. J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
  285. retry_alloc:
  286. new_bh = alloc_buffer_head(GFP_NOFS);
  287. if (!new_bh) {
  288. /*
  289. * Failure is not an option, but __GFP_NOFAIL is going
  290. * away; so we retry ourselves here.
  291. */
  292. congestion_wait(BLK_RW_ASYNC, HZ/50);
  293. goto retry_alloc;
  294. }
  295. /* keep subsequent assertions sane */
  296. new_bh->b_state = 0;
  297. init_buffer(new_bh, NULL, NULL);
  298. atomic_set(&new_bh->b_count, 1);
  299. new_jh = jbd2_journal_add_journal_head(new_bh); /* This sleeps */
  300. /*
  301. * If a new transaction has already done a buffer copy-out, then
  302. * we use that version of the data for the commit.
  303. */
  304. jbd_lock_bh_state(bh_in);
  305. repeat:
  306. if (jh_in->b_frozen_data) {
  307. done_copy_out = 1;
  308. new_page = virt_to_page(jh_in->b_frozen_data);
  309. new_offset = offset_in_page(jh_in->b_frozen_data);
  310. } else {
  311. new_page = jh2bh(jh_in)->b_page;
  312. new_offset = offset_in_page(jh2bh(jh_in)->b_data);
  313. }
  314. mapped_data = kmap_atomic(new_page, KM_USER0);
  315. /*
  316. * Fire data frozen trigger if data already wasn't frozen. Do this
  317. * before checking for escaping, as the trigger may modify the magic
  318. * offset. If a copy-out happens afterwards, it will have the correct
  319. * data in the buffer.
  320. */
  321. if (!done_copy_out)
  322. jbd2_buffer_frozen_trigger(jh_in, mapped_data + new_offset,
  323. jh_in->b_triggers);
  324. /*
  325. * Check for escaping
  326. */
  327. if (*((__be32 *)(mapped_data + new_offset)) ==
  328. cpu_to_be32(JBD2_MAGIC_NUMBER)) {
  329. need_copy_out = 1;
  330. do_escape = 1;
  331. }
  332. kunmap_atomic(mapped_data, KM_USER0);
  333. /*
  334. * Do we need to do a data copy?
  335. */
  336. if (need_copy_out && !done_copy_out) {
  337. char *tmp;
  338. jbd_unlock_bh_state(bh_in);
  339. tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
  340. if (!tmp) {
  341. jbd2_journal_put_journal_head(new_jh);
  342. return -ENOMEM;
  343. }
  344. jbd_lock_bh_state(bh_in);
  345. if (jh_in->b_frozen_data) {
  346. jbd2_free(tmp, bh_in->b_size);
  347. goto repeat;
  348. }
  349. jh_in->b_frozen_data = tmp;
  350. mapped_data = kmap_atomic(new_page, KM_USER0);
  351. memcpy(tmp, mapped_data + new_offset, jh2bh(jh_in)->b_size);
  352. kunmap_atomic(mapped_data, KM_USER0);
  353. new_page = virt_to_page(tmp);
  354. new_offset = offset_in_page(tmp);
  355. done_copy_out = 1;
  356. /*
  357. * This isn't strictly necessary, as we're using frozen
  358. * data for the escaping, but it keeps consistency with
  359. * b_frozen_data usage.
  360. */
  361. jh_in->b_frozen_triggers = jh_in->b_triggers;
  362. }
  363. /*
  364. * Did we need to do an escaping? Now we've done all the
  365. * copying, we can finally do so.
  366. */
  367. if (do_escape) {
  368. mapped_data = kmap_atomic(new_page, KM_USER0);
  369. *((unsigned int *)(mapped_data + new_offset)) = 0;
  370. kunmap_atomic(mapped_data, KM_USER0);
  371. }
  372. set_bh_page(new_bh, new_page, new_offset);
  373. new_jh->b_transaction = NULL;
  374. new_bh->b_size = jh2bh(jh_in)->b_size;
  375. new_bh->b_bdev = transaction->t_journal->j_dev;
  376. new_bh->b_blocknr = blocknr;
  377. set_buffer_mapped(new_bh);
  378. set_buffer_dirty(new_bh);
  379. *jh_out = new_jh;
  380. /*
  381. * The to-be-written buffer needs to get moved to the io queue,
  382. * and the original buffer whose contents we are shadowing or
  383. * copying is moved to the transaction's shadow queue.
  384. */
  385. JBUFFER_TRACE(jh_in, "file as BJ_Shadow");
  386. spin_lock(&journal->j_list_lock);
  387. __jbd2_journal_file_buffer(jh_in, transaction, BJ_Shadow);
  388. spin_unlock(&journal->j_list_lock);
  389. jbd_unlock_bh_state(bh_in);
  390. JBUFFER_TRACE(new_jh, "file as BJ_IO");
  391. jbd2_journal_file_buffer(new_jh, transaction, BJ_IO);
  392. return do_escape | (done_copy_out << 1);
  393. }
  394. /*
  395. * Allocation code for the journal file. Manage the space left in the
  396. * journal, so that we can begin checkpointing when appropriate.
  397. */
  398. /*
  399. * __jbd2_log_space_left: Return the number of free blocks left in the journal.
  400. *
  401. * Called with the journal already locked.
  402. *
  403. * Called under j_state_lock
  404. */
  405. int __jbd2_log_space_left(journal_t *journal)
  406. {
  407. int left = journal->j_free;
  408. /* assert_spin_locked(&journal->j_state_lock); */
  409. /*
  410. * Be pessimistic here about the number of those free blocks which
  411. * might be required for log descriptor control blocks.
  412. */
  413. #define MIN_LOG_RESERVED_BLOCKS 32 /* Allow for rounding errors */
  414. left -= MIN_LOG_RESERVED_BLOCKS;
  415. if (left <= 0)
  416. return 0;
  417. left -= (left >> 3);
  418. return left;
  419. }
  420. /*
  421. * Called under j_state_lock. Returns true if a transaction commit was started.
  422. */
  423. int __jbd2_log_start_commit(journal_t *journal, tid_t target)
  424. {
  425. /*
  426. * Are we already doing a recent enough commit?
  427. */
  428. if (!tid_geq(journal->j_commit_request, target)) {
  429. /*
  430. * We want a new commit: OK, mark the request and wakeup the
  431. * commit thread. We do _not_ do the commit ourselves.
  432. */
  433. journal->j_commit_request = target;
  434. jbd_debug(1, "JBD: requesting commit %d/%d\n",
  435. journal->j_commit_request,
  436. journal->j_commit_sequence);
  437. wake_up(&journal->j_wait_commit);
  438. return 1;
  439. }
  440. return 0;
  441. }
  442. int jbd2_log_start_commit(journal_t *journal, tid_t tid)
  443. {
  444. int ret;
  445. write_lock(&journal->j_state_lock);
  446. ret = __jbd2_log_start_commit(journal, tid);
  447. write_unlock(&journal->j_state_lock);
  448. return ret;
  449. }
  450. /*
  451. * Force and wait upon a commit if the calling process is not within
  452. * transaction. This is used for forcing out undo-protected data which contains
  453. * bitmaps, when the fs is running out of space.
  454. *
  455. * We can only force the running transaction if we don't have an active handle;
  456. * otherwise, we will deadlock.
  457. *
  458. * Returns true if a transaction was started.
  459. */
  460. int jbd2_journal_force_commit_nested(journal_t *journal)
  461. {
  462. transaction_t *transaction = NULL;
  463. tid_t tid;
  464. read_lock(&journal->j_state_lock);
  465. if (journal->j_running_transaction && !current->journal_info) {
  466. transaction = journal->j_running_transaction;
  467. __jbd2_log_start_commit(journal, transaction->t_tid);
  468. } else if (journal->j_committing_transaction)
  469. transaction = journal->j_committing_transaction;
  470. if (!transaction) {
  471. read_unlock(&journal->j_state_lock);
  472. return 0; /* Nothing to retry */
  473. }
  474. tid = transaction->t_tid;
  475. read_unlock(&journal->j_state_lock);
  476. jbd2_log_wait_commit(journal, tid);
  477. return 1;
  478. }
  479. /*
  480. * Start a commit of the current running transaction (if any). Returns true
  481. * if a transaction is going to be committed (or is currently already
  482. * committing), and fills its tid in at *ptid
  483. */
  484. int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
  485. {
  486. int ret = 0;
  487. write_lock(&journal->j_state_lock);
  488. if (journal->j_running_transaction) {
  489. tid_t tid = journal->j_running_transaction->t_tid;
  490. __jbd2_log_start_commit(journal, tid);
  491. /* There's a running transaction and we've just made sure
  492. * it's commit has been scheduled. */
  493. if (ptid)
  494. *ptid = tid;
  495. ret = 1;
  496. } else if (journal->j_committing_transaction) {
  497. /*
  498. * If ext3_write_super() recently started a commit, then we
  499. * have to wait for completion of that transaction
  500. */
  501. if (ptid)
  502. *ptid = journal->j_committing_transaction->t_tid;
  503. ret = 1;
  504. }
  505. write_unlock(&journal->j_state_lock);
  506. return ret;
  507. }
  508. /*
  509. * Wait for a specified commit to complete.
  510. * The caller may not hold the journal lock.
  511. */
  512. int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
  513. {
  514. int err = 0;
  515. read_lock(&journal->j_state_lock);
  516. #ifdef CONFIG_JBD2_DEBUG
  517. if (!tid_geq(journal->j_commit_request, tid)) {
  518. printk(KERN_EMERG
  519. "%s: error: j_commit_request=%d, tid=%d\n",
  520. __func__, journal->j_commit_request, tid);
  521. }
  522. #endif
  523. while (tid_gt(tid, journal->j_commit_sequence)) {
  524. jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n",
  525. tid, journal->j_commit_sequence);
  526. wake_up(&journal->j_wait_commit);
  527. read_unlock(&journal->j_state_lock);
  528. wait_event(journal->j_wait_done_commit,
  529. !tid_gt(tid, journal->j_commit_sequence));
  530. read_lock(&journal->j_state_lock);
  531. }
  532. read_unlock(&journal->j_state_lock);
  533. if (unlikely(is_journal_aborted(journal))) {
  534. printk(KERN_EMERG "journal commit I/O error\n");
  535. err = -EIO;
  536. }
  537. return err;
  538. }
  539. /*
  540. * Log buffer allocation routines:
  541. */
  542. int jbd2_journal_next_log_block(journal_t *journal, unsigned long long *retp)
  543. {
  544. unsigned long blocknr;
  545. write_lock(&journal->j_state_lock);
  546. J_ASSERT(journal->j_free > 1);
  547. blocknr = journal->j_head;
  548. journal->j_head++;
  549. journal->j_free--;
  550. if (journal->j_head == journal->j_last)
  551. journal->j_head = journal->j_first;
  552. write_unlock(&journal->j_state_lock);
  553. return jbd2_journal_bmap(journal, blocknr, retp);
  554. }
  555. /*
  556. * Conversion of logical to physical block numbers for the journal
  557. *
  558. * On external journals the journal blocks are identity-mapped, so
  559. * this is a no-op. If needed, we can use j_blk_offset - everything is
  560. * ready.
  561. */
  562. int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
  563. unsigned long long *retp)
  564. {
  565. int err = 0;
  566. unsigned long long ret;
  567. if (journal->j_inode) {
  568. ret = bmap(journal->j_inode, blocknr);
  569. if (ret)
  570. *retp = ret;
  571. else {
  572. printk(KERN_ALERT "%s: journal block not found "
  573. "at offset %lu on %s\n",
  574. __func__, blocknr, journal->j_devname);
  575. err = -EIO;
  576. __journal_abort_soft(journal, err);
  577. }
  578. } else {
  579. *retp = blocknr; /* +journal->j_blk_offset */
  580. }
  581. return err;
  582. }
  583. /*
  584. * We play buffer_head aliasing tricks to write data/metadata blocks to
  585. * the journal without copying their contents, but for journal
  586. * descriptor blocks we do need to generate bona fide buffers.
  587. *
  588. * After the caller of jbd2_journal_get_descriptor_buffer() has finished modifying
  589. * the buffer's contents they really should run flush_dcache_page(bh->b_page).
  590. * But we don't bother doing that, so there will be coherency problems with
  591. * mmaps of blockdevs which hold live JBD-controlled filesystems.
  592. */
  593. struct journal_head *jbd2_journal_get_descriptor_buffer(journal_t *journal)
  594. {
  595. struct buffer_head *bh;
  596. unsigned long long blocknr;
  597. int err;
  598. err = jbd2_journal_next_log_block(journal, &blocknr);
  599. if (err)
  600. return NULL;
  601. bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize);
  602. if (!bh)
  603. return NULL;
  604. lock_buffer(bh);
  605. memset(bh->b_data, 0, journal->j_blocksize);
  606. set_buffer_uptodate(bh);
  607. unlock_buffer(bh);
  608. BUFFER_TRACE(bh, "return this buffer");
  609. return jbd2_journal_add_journal_head(bh);
  610. }
  611. struct jbd2_stats_proc_session {
  612. journal_t *journal;
  613. struct transaction_stats_s *stats;
  614. int start;
  615. int max;
  616. };
  617. static void *jbd2_seq_info_start(struct seq_file *seq, loff_t *pos)
  618. {
  619. return *pos ? NULL : SEQ_START_TOKEN;
  620. }
  621. static void *jbd2_seq_info_next(struct seq_file *seq, void *v, loff_t *pos)
  622. {
  623. return NULL;
  624. }
  625. static int jbd2_seq_info_show(struct seq_file *seq, void *v)
  626. {
  627. struct jbd2_stats_proc_session *s = seq->private;
  628. if (v != SEQ_START_TOKEN)
  629. return 0;
  630. seq_printf(seq, "%lu transaction, each up to %u blocks\n",
  631. s->stats->ts_tid,
  632. s->journal->j_max_transaction_buffers);
  633. if (s->stats->ts_tid == 0)
  634. return 0;
  635. seq_printf(seq, "average: \n %ums waiting for transaction\n",
  636. jiffies_to_msecs(s->stats->run.rs_wait / s->stats->ts_tid));
  637. seq_printf(seq, " %ums running transaction\n",
  638. jiffies_to_msecs(s->stats->run.rs_running / s->stats->ts_tid));
  639. seq_printf(seq, " %ums transaction was being locked\n",
  640. jiffies_to_msecs(s->stats->run.rs_locked / s->stats->ts_tid));
  641. seq_printf(seq, " %ums flushing data (in ordered mode)\n",
  642. jiffies_to_msecs(s->stats->run.rs_flushing / s->stats->ts_tid));
  643. seq_printf(seq, " %ums logging transaction\n",
  644. jiffies_to_msecs(s->stats->run.rs_logging / s->stats->ts_tid));
  645. seq_printf(seq, " %lluus average transaction commit time\n",
  646. div_u64(s->journal->j_average_commit_time, 1000));
  647. seq_printf(seq, " %lu handles per transaction\n",
  648. s->stats->run.rs_handle_count / s->stats->ts_tid);
  649. seq_printf(seq, " %lu blocks per transaction\n",
  650. s->stats->run.rs_blocks / s->stats->ts_tid);
  651. seq_printf(seq, " %lu logged blocks per transaction\n",
  652. s->stats->run.rs_blocks_logged / s->stats->ts_tid);
  653. return 0;
  654. }
  655. static void jbd2_seq_info_stop(struct seq_file *seq, void *v)
  656. {
  657. }
  658. static const struct seq_operations jbd2_seq_info_ops = {
  659. .start = jbd2_seq_info_start,
  660. .next = jbd2_seq_info_next,
  661. .stop = jbd2_seq_info_stop,
  662. .show = jbd2_seq_info_show,
  663. };
  664. static int jbd2_seq_info_open(struct inode *inode, struct file *file)
  665. {
  666. journal_t *journal = PDE(inode)->data;
  667. struct jbd2_stats_proc_session *s;
  668. int rc, size;
  669. s = kmalloc(sizeof(*s), GFP_KERNEL);
  670. if (s == NULL)
  671. return -ENOMEM;
  672. size = sizeof(struct transaction_stats_s);
  673. s->stats = kmalloc(size, GFP_KERNEL);
  674. if (s->stats == NULL) {
  675. kfree(s);
  676. return -ENOMEM;
  677. }
  678. spin_lock(&journal->j_history_lock);
  679. memcpy(s->stats, &journal->j_stats, size);
  680. s->journal = journal;
  681. spin_unlock(&journal->j_history_lock);
  682. rc = seq_open(file, &jbd2_seq_info_ops);
  683. if (rc == 0) {
  684. struct seq_file *m = file->private_data;
  685. m->private = s;
  686. } else {
  687. kfree(s->stats);
  688. kfree(s);
  689. }
  690. return rc;
  691. }
  692. static int jbd2_seq_info_release(struct inode *inode, struct file *file)
  693. {
  694. struct seq_file *seq = file->private_data;
  695. struct jbd2_stats_proc_session *s = seq->private;
  696. kfree(s->stats);
  697. kfree(s);
  698. return seq_release(inode, file);
  699. }
  700. static const struct file_operations jbd2_seq_info_fops = {
  701. .owner = THIS_MODULE,
  702. .open = jbd2_seq_info_open,
  703. .read = seq_read,
  704. .llseek = seq_lseek,
  705. .release = jbd2_seq_info_release,
  706. };
  707. static struct proc_dir_entry *proc_jbd2_stats;
  708. static void jbd2_stats_proc_init(journal_t *journal)
  709. {
  710. journal->j_proc_entry = proc_mkdir(journal->j_devname, proc_jbd2_stats);
  711. if (journal->j_proc_entry) {
  712. proc_create_data("info", S_IRUGO, journal->j_proc_entry,
  713. &jbd2_seq_info_fops, journal);
  714. }
  715. }
  716. static void jbd2_stats_proc_exit(journal_t *journal)
  717. {
  718. remove_proc_entry("info", journal->j_proc_entry);
  719. remove_proc_entry(journal->j_devname, proc_jbd2_stats);
  720. }
  721. /*
  722. * Management for journal control blocks: functions to create and
  723. * destroy journal_t structures, and to initialise and read existing
  724. * journal blocks from disk. */
  725. /* First: create and setup a journal_t object in memory. We initialise
  726. * very few fields yet: that has to wait until we have created the
  727. * journal structures from from scratch, or loaded them from disk. */
  728. static journal_t * journal_init_common (void)
  729. {
  730. journal_t *journal;
  731. int err;
  732. journal = kzalloc(sizeof(*journal), GFP_KERNEL);
  733. if (!journal)
  734. return NULL;
  735. init_waitqueue_head(&journal->j_wait_transaction_locked);
  736. init_waitqueue_head(&journal->j_wait_logspace);
  737. init_waitqueue_head(&journal->j_wait_done_commit);
  738. init_waitqueue_head(&journal->j_wait_checkpoint);
  739. init_waitqueue_head(&journal->j_wait_commit);
  740. init_waitqueue_head(&journal->j_wait_updates);
  741. mutex_init(&journal->j_barrier);
  742. mutex_init(&journal->j_checkpoint_mutex);
  743. spin_lock_init(&journal->j_revoke_lock);
  744. spin_lock_init(&journal->j_list_lock);
  745. rwlock_init(&journal->j_state_lock);
  746. journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
  747. journal->j_min_batch_time = 0;
  748. journal->j_max_batch_time = 15000; /* 15ms */
  749. /* The journal is marked for error until we succeed with recovery! */
  750. journal->j_flags = JBD2_ABORT;
  751. /* Set up a default-sized revoke table for the new mount. */
  752. err = jbd2_journal_init_revoke(journal, JOURNAL_REVOKE_DEFAULT_HASH);
  753. if (err) {
  754. kfree(journal);
  755. return NULL;
  756. }
  757. spin_lock_init(&journal->j_history_lock);
  758. return journal;
  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. #ifdef CONFIG_JBD2_DEBUG
  1717. atomic_inc(&nr_journal_heads);
  1718. #endif
  1719. ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
  1720. if (!ret) {
  1721. jbd_debug(1, "out of memory for journal_head\n");
  1722. pr_notice_ratelimited("ENOMEM in %s, retrying.\n", __func__);
  1723. while (!ret) {
  1724. yield();
  1725. ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
  1726. }
  1727. }
  1728. return ret;
  1729. }
  1730. static void journal_free_journal_head(struct journal_head *jh)
  1731. {
  1732. #ifdef CONFIG_JBD2_DEBUG
  1733. atomic_dec(&nr_journal_heads);
  1734. memset(jh, JBD2_POISON_FREE, sizeof(*jh));
  1735. #endif
  1736. kmem_cache_free(jbd2_journal_head_cache, jh);
  1737. }
  1738. /*
  1739. * A journal_head is attached to a buffer_head whenever JBD has an
  1740. * interest in the buffer.
  1741. *
  1742. * Whenever a buffer has an attached journal_head, its ->b_state:BH_JBD bit
  1743. * is set. This bit is tested in core kernel code where we need to take
  1744. * JBD-specific actions. Testing the zeroness of ->b_private is not reliable
  1745. * there.
  1746. *
  1747. * When a buffer has its BH_JBD bit set, its ->b_count is elevated by one.
  1748. *
  1749. * When a buffer has its BH_JBD bit set it is immune from being released by
  1750. * core kernel code, mainly via ->b_count.
  1751. *
  1752. * A journal_head may be detached from its buffer_head when the journal_head's
  1753. * b_transaction, b_cp_transaction and b_next_transaction pointers are NULL.
  1754. * Various places in JBD call jbd2_journal_remove_journal_head() to indicate that the
  1755. * journal_head can be dropped if needed.
  1756. *
  1757. * Various places in the kernel want to attach a journal_head to a buffer_head
  1758. * _before_ attaching the journal_head to a transaction. To protect the
  1759. * journal_head in this situation, jbd2_journal_add_journal_head elevates the
  1760. * journal_head's b_jcount refcount by one. The caller must call
  1761. * jbd2_journal_put_journal_head() to undo this.
  1762. *
  1763. * So the typical usage would be:
  1764. *
  1765. * (Attach a journal_head if needed. Increments b_jcount)
  1766. * struct journal_head *jh = jbd2_journal_add_journal_head(bh);
  1767. * ...
  1768. * jh->b_transaction = xxx;
  1769. * jbd2_journal_put_journal_head(jh);
  1770. *
  1771. * Now, the journal_head's b_jcount is zero, but it is safe from being released
  1772. * because it has a non-zero b_transaction.
  1773. */
  1774. /*
  1775. * Give a buffer_head a journal_head.
  1776. *
  1777. * Doesn't need the journal lock.
  1778. * May sleep.
  1779. */
  1780. struct journal_head *jbd2_journal_add_journal_head(struct buffer_head *bh)
  1781. {
  1782. struct journal_head *jh;
  1783. struct journal_head *new_jh = NULL;
  1784. repeat:
  1785. if (!buffer_jbd(bh)) {
  1786. new_jh = journal_alloc_journal_head();
  1787. memset(new_jh, 0, sizeof(*new_jh));
  1788. }
  1789. jbd_lock_bh_journal_head(bh);
  1790. if (buffer_jbd(bh)) {
  1791. jh = bh2jh(bh);
  1792. } else {
  1793. J_ASSERT_BH(bh,
  1794. (atomic_read(&bh->b_count) > 0) ||
  1795. (bh->b_page && bh->b_page->mapping));
  1796. if (!new_jh) {
  1797. jbd_unlock_bh_journal_head(bh);
  1798. goto repeat;
  1799. }
  1800. jh = new_jh;
  1801. new_jh = NULL; /* We consumed it */
  1802. set_buffer_jbd(bh);
  1803. bh->b_private = jh;
  1804. jh->b_bh = bh;
  1805. get_bh(bh);
  1806. BUFFER_TRACE(bh, "added journal_head");
  1807. }
  1808. jh->b_jcount++;
  1809. jbd_unlock_bh_journal_head(bh);
  1810. if (new_jh)
  1811. journal_free_journal_head(new_jh);
  1812. return bh->b_private;
  1813. }
  1814. /*
  1815. * Grab a ref against this buffer_head's journal_head. If it ended up not
  1816. * having a journal_head, return NULL
  1817. */
  1818. struct journal_head *jbd2_journal_grab_journal_head(struct buffer_head *bh)
  1819. {
  1820. struct journal_head *jh = NULL;
  1821. jbd_lock_bh_journal_head(bh);
  1822. if (buffer_jbd(bh)) {
  1823. jh = bh2jh(bh);
  1824. jh->b_jcount++;
  1825. }
  1826. jbd_unlock_bh_journal_head(bh);
  1827. return jh;
  1828. }
  1829. static void __journal_remove_journal_head(struct buffer_head *bh)
  1830. {
  1831. struct journal_head *jh = bh2jh(bh);
  1832. J_ASSERT_JH(jh, jh->b_jcount >= 0);
  1833. get_bh(bh);
  1834. if (jh->b_jcount == 0) {
  1835. if (jh->b_transaction == NULL &&
  1836. jh->b_next_transaction == NULL &&
  1837. jh->b_cp_transaction == NULL) {
  1838. J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
  1839. J_ASSERT_BH(bh, buffer_jbd(bh));
  1840. J_ASSERT_BH(bh, jh2bh(jh) == bh);
  1841. BUFFER_TRACE(bh, "remove journal_head");
  1842. if (jh->b_frozen_data) {
  1843. printk(KERN_WARNING "%s: freeing "
  1844. "b_frozen_data\n",
  1845. __func__);
  1846. jbd2_free(jh->b_frozen_data, bh->b_size);
  1847. }
  1848. if (jh->b_committed_data) {
  1849. printk(KERN_WARNING "%s: freeing "
  1850. "b_committed_data\n",
  1851. __func__);
  1852. jbd2_free(jh->b_committed_data, bh->b_size);
  1853. }
  1854. bh->b_private = NULL;
  1855. jh->b_bh = NULL; /* debug, really */
  1856. clear_buffer_jbd(bh);
  1857. __brelse(bh);
  1858. journal_free_journal_head(jh);
  1859. } else {
  1860. BUFFER_TRACE(bh, "journal_head was locked");
  1861. }
  1862. }
  1863. }
  1864. /*
  1865. * jbd2_journal_remove_journal_head(): if the buffer isn't attached to a transaction
  1866. * and has a zero b_jcount then remove and release its journal_head. If we did
  1867. * see that the buffer is not used by any transaction we also "logically"
  1868. * decrement ->b_count.
  1869. *
  1870. * We in fact take an additional increment on ->b_count as a convenience,
  1871. * because the caller usually wants to do additional things with the bh
  1872. * after calling here.
  1873. * The caller of jbd2_journal_remove_journal_head() *must* run __brelse(bh) at some
  1874. * time. Once the caller has run __brelse(), the buffer is eligible for
  1875. * reaping by try_to_free_buffers().
  1876. */
  1877. void jbd2_journal_remove_journal_head(struct buffer_head *bh)
  1878. {
  1879. jbd_lock_bh_journal_head(bh);
  1880. __journal_remove_journal_head(bh);
  1881. jbd_unlock_bh_journal_head(bh);
  1882. }
  1883. /*
  1884. * Drop a reference on the passed journal_head. If it fell to zero then try to
  1885. * release the journal_head from the buffer_head.
  1886. */
  1887. void jbd2_journal_put_journal_head(struct journal_head *jh)
  1888. {
  1889. struct buffer_head *bh = jh2bh(jh);
  1890. jbd_lock_bh_journal_head(bh);
  1891. J_ASSERT_JH(jh, jh->b_jcount > 0);
  1892. --jh->b_jcount;
  1893. if (!jh->b_jcount && !jh->b_transaction) {
  1894. __journal_remove_journal_head(bh);
  1895. __brelse(bh);
  1896. }
  1897. jbd_unlock_bh_journal_head(bh);
  1898. }
  1899. /*
  1900. * Initialize jbd inode head
  1901. */
  1902. void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode)
  1903. {
  1904. jinode->i_transaction = NULL;
  1905. jinode->i_next_transaction = NULL;
  1906. jinode->i_vfs_inode = inode;
  1907. jinode->i_flags = 0;
  1908. INIT_LIST_HEAD(&jinode->i_list);
  1909. }
  1910. /*
  1911. * Function to be called before we start removing inode from memory (i.e.,
  1912. * clear_inode() is a fine place to be called from). It removes inode from
  1913. * transaction's lists.
  1914. */
  1915. void jbd2_journal_release_jbd_inode(journal_t *journal,
  1916. struct jbd2_inode *jinode)
  1917. {
  1918. if (!journal)
  1919. return;
  1920. restart:
  1921. spin_lock(&journal->j_list_lock);
  1922. /* Is commit writing out inode - we have to wait */
  1923. if (test_bit(__JI_COMMIT_RUNNING, &jinode->i_flags)) {
  1924. wait_queue_head_t *wq;
  1925. DEFINE_WAIT_BIT(wait, &jinode->i_flags, __JI_COMMIT_RUNNING);
  1926. wq = bit_waitqueue(&jinode->i_flags, __JI_COMMIT_RUNNING);
  1927. prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
  1928. spin_unlock(&journal->j_list_lock);
  1929. schedule();
  1930. finish_wait(wq, &wait.wait);
  1931. goto restart;
  1932. }
  1933. if (jinode->i_transaction) {
  1934. list_del(&jinode->i_list);
  1935. jinode->i_transaction = NULL;
  1936. }
  1937. spin_unlock(&journal->j_list_lock);
  1938. }
  1939. /*
  1940. * debugfs tunables
  1941. */
  1942. #ifdef CONFIG_JBD2_DEBUG
  1943. u8 jbd2_journal_enable_debug __read_mostly;
  1944. EXPORT_SYMBOL(jbd2_journal_enable_debug);
  1945. #define JBD2_DEBUG_NAME "jbd2-debug"
  1946. static struct dentry *jbd2_debugfs_dir;
  1947. static struct dentry *jbd2_debug;
  1948. static void __init jbd2_create_debugfs_entry(void)
  1949. {
  1950. jbd2_debugfs_dir = debugfs_create_dir("jbd2", NULL);
  1951. if (jbd2_debugfs_dir)
  1952. jbd2_debug = debugfs_create_u8(JBD2_DEBUG_NAME,
  1953. S_IRUGO | S_IWUSR,
  1954. jbd2_debugfs_dir,
  1955. &jbd2_journal_enable_debug);
  1956. }
  1957. static void __exit jbd2_remove_debugfs_entry(void)
  1958. {
  1959. debugfs_remove(jbd2_debug);
  1960. debugfs_remove(jbd2_debugfs_dir);
  1961. }
  1962. #else
  1963. static void __init jbd2_create_debugfs_entry(void)
  1964. {
  1965. }
  1966. static void __exit jbd2_remove_debugfs_entry(void)
  1967. {
  1968. }
  1969. #endif
  1970. #ifdef CONFIG_PROC_FS
  1971. #define JBD2_STATS_PROC_NAME "fs/jbd2"
  1972. static void __init jbd2_create_jbd_stats_proc_entry(void)
  1973. {
  1974. proc_jbd2_stats = proc_mkdir(JBD2_STATS_PROC_NAME, NULL);
  1975. }
  1976. static void __exit jbd2_remove_jbd_stats_proc_entry(void)
  1977. {
  1978. if (proc_jbd2_stats)
  1979. remove_proc_entry(JBD2_STATS_PROC_NAME, NULL);
  1980. }
  1981. #else
  1982. #define jbd2_create_jbd_stats_proc_entry() do {} while (0)
  1983. #define jbd2_remove_jbd_stats_proc_entry() do {} while (0)
  1984. #endif
  1985. struct kmem_cache *jbd2_handle_cache, *jbd2_inode_cache;
  1986. static int __init journal_init_handle_cache(void)
  1987. {
  1988. jbd2_handle_cache = KMEM_CACHE(jbd2_journal_handle, SLAB_TEMPORARY);
  1989. if (jbd2_handle_cache == NULL) {
  1990. printk(KERN_EMERG "JBD2: failed to create handle cache\n");
  1991. return -ENOMEM;
  1992. }
  1993. jbd2_inode_cache = KMEM_CACHE(jbd2_inode, 0);
  1994. if (jbd2_inode_cache == NULL) {
  1995. printk(KERN_EMERG "JBD2: failed to create inode cache\n");
  1996. kmem_cache_destroy(jbd2_handle_cache);
  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. if (jbd2_inode_cache)
  2006. kmem_cache_destroy(jbd2_inode_cache);
  2007. }
  2008. /*
  2009. * Module startup and shutdown
  2010. */
  2011. static int __init journal_init_caches(void)
  2012. {
  2013. int ret;
  2014. ret = jbd2_journal_init_revoke_caches();
  2015. if (ret == 0)
  2016. ret = journal_init_jbd2_journal_head_cache();
  2017. if (ret == 0)
  2018. ret = journal_init_handle_cache();
  2019. return ret;
  2020. }
  2021. static void jbd2_journal_destroy_caches(void)
  2022. {
  2023. jbd2_journal_destroy_revoke_caches();
  2024. jbd2_journal_destroy_jbd2_journal_head_cache();
  2025. jbd2_journal_destroy_handle_cache();
  2026. jbd2_journal_destroy_slabs();
  2027. }
  2028. static int __init journal_init(void)
  2029. {
  2030. int ret;
  2031. BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024);
  2032. ret = journal_init_caches();
  2033. if (ret == 0) {
  2034. jbd2_create_debugfs_entry();
  2035. jbd2_create_jbd_stats_proc_entry();
  2036. } else {
  2037. jbd2_journal_destroy_caches();
  2038. }
  2039. return ret;
  2040. }
  2041. static void __exit journal_exit(void)
  2042. {
  2043. #ifdef CONFIG_JBD2_DEBUG
  2044. int n = atomic_read(&nr_journal_heads);
  2045. if (n)
  2046. printk(KERN_EMERG "JBD: leaked %d journal_heads!\n", n);
  2047. #endif
  2048. jbd2_remove_debugfs_entry();
  2049. jbd2_remove_jbd_stats_proc_entry();
  2050. jbd2_journal_destroy_caches();
  2051. }
  2052. /*
  2053. * jbd2_dev_to_name is a utility function used by the jbd2 and ext4
  2054. * tracing infrastructure to map a dev_t to a device name.
  2055. *
  2056. * The caller should use rcu_read_lock() in order to make sure the
  2057. * device name stays valid until its done with it. We use
  2058. * rcu_read_lock() as well to make sure we're safe in case the caller
  2059. * gets sloppy, and because rcu_read_lock() is cheap and can be safely
  2060. * nested.
  2061. */
  2062. struct devname_cache {
  2063. struct rcu_head rcu;
  2064. dev_t device;
  2065. char devname[BDEVNAME_SIZE];
  2066. };
  2067. #define CACHE_SIZE_BITS 6
  2068. static struct devname_cache *devcache[1 << CACHE_SIZE_BITS];
  2069. static DEFINE_SPINLOCK(devname_cache_lock);
  2070. static void free_devcache(struct rcu_head *rcu)
  2071. {
  2072. kfree(rcu);
  2073. }
  2074. const char *jbd2_dev_to_name(dev_t device)
  2075. {
  2076. int i = hash_32(device, CACHE_SIZE_BITS);
  2077. char *ret;
  2078. struct block_device *bd;
  2079. static struct devname_cache *new_dev;
  2080. rcu_read_lock();
  2081. if (devcache[i] && devcache[i]->device == device) {
  2082. ret = devcache[i]->devname;
  2083. rcu_read_unlock();
  2084. return ret;
  2085. }
  2086. rcu_read_unlock();
  2087. new_dev = kmalloc(sizeof(struct devname_cache), GFP_KERNEL);
  2088. if (!new_dev)
  2089. return "NODEV-ALLOCFAILURE"; /* Something non-NULL */
  2090. spin_lock(&devname_cache_lock);
  2091. if (devcache[i]) {
  2092. if (devcache[i]->device == device) {
  2093. kfree(new_dev);
  2094. ret = devcache[i]->devname;
  2095. spin_unlock(&devname_cache_lock);
  2096. return ret;
  2097. }
  2098. call_rcu(&devcache[i]->rcu, free_devcache);
  2099. }
  2100. devcache[i] = new_dev;
  2101. devcache[i]->device = device;
  2102. bd = bdget(device);
  2103. if (bd) {
  2104. bdevname(bd, devcache[i]->devname);
  2105. bdput(bd);
  2106. } else
  2107. __bdevname(device, devcache[i]->devname);
  2108. ret = devcache[i]->devname;
  2109. spin_unlock(&devname_cache_lock);
  2110. return ret;
  2111. }
  2112. EXPORT_SYMBOL(jbd2_dev_to_name);
  2113. MODULE_LICENSE("GPL");
  2114. module_init(journal_init);
  2115. module_exit(journal_exit);