super.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262
  1. /*
  2. * linux/fs/ext4/super.c
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * from
  10. *
  11. * linux/fs/minix/inode.c
  12. *
  13. * Copyright (C) 1991, 1992 Linus Torvalds
  14. *
  15. * Big-endian to little-endian byte-swapping/bitmaps by
  16. * David S. Miller (davem@caip.rutgers.edu), 1995
  17. */
  18. #include <linux/module.h>
  19. #include <linux/string.h>
  20. #include <linux/fs.h>
  21. #include <linux/time.h>
  22. #include <linux/vmalloc.h>
  23. #include <linux/jbd2.h>
  24. #include <linux/slab.h>
  25. #include <linux/init.h>
  26. #include <linux/blkdev.h>
  27. #include <linux/parser.h>
  28. #include <linux/smp_lock.h>
  29. #include <linux/buffer_head.h>
  30. #include <linux/exportfs.h>
  31. #include <linux/vfs.h>
  32. #include <linux/random.h>
  33. #include <linux/mount.h>
  34. #include <linux/namei.h>
  35. #include <linux/quotaops.h>
  36. #include <linux/seq_file.h>
  37. #include <linux/proc_fs.h>
  38. #include <linux/ctype.h>
  39. #include <linux/log2.h>
  40. #include <linux/crc16.h>
  41. #include <asm/uaccess.h>
  42. #include "ext4.h"
  43. #include "ext4_jbd2.h"
  44. #include "xattr.h"
  45. #include "acl.h"
  46. #include "mballoc.h"
  47. #define CREATE_TRACE_POINTS
  48. #include <trace/events/ext4.h>
  49. struct proc_dir_entry *ext4_proc_root;
  50. static struct kset *ext4_kset;
  51. static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
  52. unsigned long journal_devnum);
  53. static int ext4_commit_super(struct super_block *sb, int sync);
  54. static void ext4_mark_recovery_complete(struct super_block *sb,
  55. struct ext4_super_block *es);
  56. static void ext4_clear_journal_err(struct super_block *sb,
  57. struct ext4_super_block *es);
  58. static int ext4_sync_fs(struct super_block *sb, int wait);
  59. static const char *ext4_decode_error(struct super_block *sb, int errno,
  60. char nbuf[16]);
  61. static int ext4_remount(struct super_block *sb, int *flags, char *data);
  62. static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf);
  63. static int ext4_unfreeze(struct super_block *sb);
  64. static void ext4_write_super(struct super_block *sb);
  65. static int ext4_freeze(struct super_block *sb);
  66. static int ext4_get_sb(struct file_system_type *fs_type, int flags,
  67. const char *dev_name, void *data, struct vfsmount *mnt);
  68. #if !defined(CONFIG_EXT3_FS) && !defined(CONFIG_EXT3_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
  69. static struct file_system_type ext3_fs_type = {
  70. .owner = THIS_MODULE,
  71. .name = "ext3",
  72. .get_sb = ext4_get_sb,
  73. .kill_sb = kill_block_super,
  74. .fs_flags = FS_REQUIRES_DEV,
  75. };
  76. #define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
  77. #else
  78. #define IS_EXT3_SB(sb) (0)
  79. #endif
  80. ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
  81. struct ext4_group_desc *bg)
  82. {
  83. return le32_to_cpu(bg->bg_block_bitmap_lo) |
  84. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  85. (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
  86. }
  87. ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
  88. struct ext4_group_desc *bg)
  89. {
  90. return le32_to_cpu(bg->bg_inode_bitmap_lo) |
  91. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  92. (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
  93. }
  94. ext4_fsblk_t ext4_inode_table(struct super_block *sb,
  95. struct ext4_group_desc *bg)
  96. {
  97. return le32_to_cpu(bg->bg_inode_table_lo) |
  98. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  99. (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
  100. }
  101. __u32 ext4_free_blks_count(struct super_block *sb,
  102. struct ext4_group_desc *bg)
  103. {
  104. return le16_to_cpu(bg->bg_free_blocks_count_lo) |
  105. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  106. (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
  107. }
  108. __u32 ext4_free_inodes_count(struct super_block *sb,
  109. struct ext4_group_desc *bg)
  110. {
  111. return le16_to_cpu(bg->bg_free_inodes_count_lo) |
  112. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  113. (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
  114. }
  115. __u32 ext4_used_dirs_count(struct super_block *sb,
  116. struct ext4_group_desc *bg)
  117. {
  118. return le16_to_cpu(bg->bg_used_dirs_count_lo) |
  119. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  120. (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
  121. }
  122. __u32 ext4_itable_unused_count(struct super_block *sb,
  123. struct ext4_group_desc *bg)
  124. {
  125. return le16_to_cpu(bg->bg_itable_unused_lo) |
  126. (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
  127. (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
  128. }
  129. void ext4_block_bitmap_set(struct super_block *sb,
  130. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  131. {
  132. bg->bg_block_bitmap_lo = cpu_to_le32((u32)blk);
  133. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  134. bg->bg_block_bitmap_hi = cpu_to_le32(blk >> 32);
  135. }
  136. void ext4_inode_bitmap_set(struct super_block *sb,
  137. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  138. {
  139. bg->bg_inode_bitmap_lo = cpu_to_le32((u32)blk);
  140. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  141. bg->bg_inode_bitmap_hi = cpu_to_le32(blk >> 32);
  142. }
  143. void ext4_inode_table_set(struct super_block *sb,
  144. struct ext4_group_desc *bg, ext4_fsblk_t blk)
  145. {
  146. bg->bg_inode_table_lo = cpu_to_le32((u32)blk);
  147. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  148. bg->bg_inode_table_hi = cpu_to_le32(blk >> 32);
  149. }
  150. void ext4_free_blks_set(struct super_block *sb,
  151. struct ext4_group_desc *bg, __u32 count)
  152. {
  153. bg->bg_free_blocks_count_lo = cpu_to_le16((__u16)count);
  154. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  155. bg->bg_free_blocks_count_hi = cpu_to_le16(count >> 16);
  156. }
  157. void ext4_free_inodes_set(struct super_block *sb,
  158. struct ext4_group_desc *bg, __u32 count)
  159. {
  160. bg->bg_free_inodes_count_lo = cpu_to_le16((__u16)count);
  161. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  162. bg->bg_free_inodes_count_hi = cpu_to_le16(count >> 16);
  163. }
  164. void ext4_used_dirs_set(struct super_block *sb,
  165. struct ext4_group_desc *bg, __u32 count)
  166. {
  167. bg->bg_used_dirs_count_lo = cpu_to_le16((__u16)count);
  168. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  169. bg->bg_used_dirs_count_hi = cpu_to_le16(count >> 16);
  170. }
  171. void ext4_itable_unused_set(struct super_block *sb,
  172. struct ext4_group_desc *bg, __u32 count)
  173. {
  174. bg->bg_itable_unused_lo = cpu_to_le16((__u16)count);
  175. if (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT)
  176. bg->bg_itable_unused_hi = cpu_to_le16(count >> 16);
  177. }
  178. /* Just increment the non-pointer handle value */
  179. static handle_t *ext4_get_nojournal(void)
  180. {
  181. handle_t *handle = current->journal_info;
  182. unsigned long ref_cnt = (unsigned long)handle;
  183. BUG_ON(ref_cnt >= EXT4_NOJOURNAL_MAX_REF_COUNT);
  184. ref_cnt++;
  185. handle = (handle_t *)ref_cnt;
  186. current->journal_info = handle;
  187. return handle;
  188. }
  189. /* Decrement the non-pointer handle value */
  190. static void ext4_put_nojournal(handle_t *handle)
  191. {
  192. unsigned long ref_cnt = (unsigned long)handle;
  193. BUG_ON(ref_cnt == 0);
  194. ref_cnt--;
  195. handle = (handle_t *)ref_cnt;
  196. current->journal_info = handle;
  197. }
  198. /*
  199. * Wrappers for jbd2_journal_start/end.
  200. *
  201. * The only special thing we need to do here is to make sure that all
  202. * journal_end calls result in the superblock being marked dirty, so
  203. * that sync() will call the filesystem's write_super callback if
  204. * appropriate.
  205. */
  206. handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
  207. {
  208. journal_t *journal;
  209. if (sb->s_flags & MS_RDONLY)
  210. return ERR_PTR(-EROFS);
  211. vfs_check_frozen(sb, SB_FREEZE_WRITE);
  212. /* Special case here: if the journal has aborted behind our
  213. * backs (eg. EIO in the commit thread), then we still need to
  214. * take the FS itself readonly cleanly. */
  215. journal = EXT4_SB(sb)->s_journal;
  216. if (journal) {
  217. if (is_journal_aborted(journal)) {
  218. ext4_abort(sb, "Detected aborted journal");
  219. return ERR_PTR(-EROFS);
  220. }
  221. return jbd2_journal_start(journal, nblocks);
  222. }
  223. return ext4_get_nojournal();
  224. }
  225. /*
  226. * The only special thing we need to do here is to make sure that all
  227. * jbd2_journal_stop calls result in the superblock being marked dirty, so
  228. * that sync() will call the filesystem's write_super callback if
  229. * appropriate.
  230. */
  231. int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
  232. {
  233. struct super_block *sb;
  234. int err;
  235. int rc;
  236. if (!ext4_handle_valid(handle)) {
  237. ext4_put_nojournal(handle);
  238. return 0;
  239. }
  240. sb = handle->h_transaction->t_journal->j_private;
  241. err = handle->h_err;
  242. rc = jbd2_journal_stop(handle);
  243. if (!err)
  244. err = rc;
  245. if (err)
  246. __ext4_std_error(sb, where, line, err);
  247. return err;
  248. }
  249. void ext4_journal_abort_handle(const char *caller, unsigned int line,
  250. const char *err_fn, struct buffer_head *bh,
  251. handle_t *handle, int err)
  252. {
  253. char nbuf[16];
  254. const char *errstr = ext4_decode_error(NULL, err, nbuf);
  255. BUG_ON(!ext4_handle_valid(handle));
  256. if (bh)
  257. BUFFER_TRACE(bh, "abort");
  258. if (!handle->h_err)
  259. handle->h_err = err;
  260. if (is_handle_aborted(handle))
  261. return;
  262. printk(KERN_ERR "%s:%d: aborting transaction: %s in %s\n",
  263. caller, line, errstr, err_fn);
  264. jbd2_journal_abort_handle(handle);
  265. }
  266. static void __save_error_info(struct super_block *sb, const char *func,
  267. unsigned int line)
  268. {
  269. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  270. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  271. es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
  272. es->s_last_error_time = cpu_to_le32(get_seconds());
  273. strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
  274. es->s_last_error_line = cpu_to_le32(line);
  275. if (!es->s_first_error_time) {
  276. es->s_first_error_time = es->s_last_error_time;
  277. strncpy(es->s_first_error_func, func,
  278. sizeof(es->s_first_error_func));
  279. es->s_first_error_line = cpu_to_le32(line);
  280. es->s_first_error_ino = es->s_last_error_ino;
  281. es->s_first_error_block = es->s_last_error_block;
  282. }
  283. es->s_error_count = cpu_to_le32(le32_to_cpu(es->s_error_count) + 1);
  284. }
  285. static void save_error_info(struct super_block *sb, const char *func,
  286. unsigned int line)
  287. {
  288. __save_error_info(sb, func, line);
  289. ext4_commit_super(sb, 1);
  290. }
  291. /* Deal with the reporting of failure conditions on a filesystem such as
  292. * inconsistencies detected or read IO failures.
  293. *
  294. * On ext2, we can store the error state of the filesystem in the
  295. * superblock. That is not possible on ext4, because we may have other
  296. * write ordering constraints on the superblock which prevent us from
  297. * writing it out straight away; and given that the journal is about to
  298. * be aborted, we can't rely on the current, or future, transactions to
  299. * write out the superblock safely.
  300. *
  301. * We'll just use the jbd2_journal_abort() error code to record an error in
  302. * the journal instead. On recovery, the journal will complain about
  303. * that error until we've noted it down and cleared it.
  304. */
  305. static void ext4_handle_error(struct super_block *sb)
  306. {
  307. if (sb->s_flags & MS_RDONLY)
  308. return;
  309. if (!test_opt(sb, ERRORS_CONT)) {
  310. journal_t *journal = EXT4_SB(sb)->s_journal;
  311. EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
  312. if (journal)
  313. jbd2_journal_abort(journal, -EIO);
  314. }
  315. if (test_opt(sb, ERRORS_RO)) {
  316. ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
  317. sb->s_flags |= MS_RDONLY;
  318. }
  319. if (test_opt(sb, ERRORS_PANIC))
  320. panic("EXT4-fs (device %s): panic forced after error\n",
  321. sb->s_id);
  322. }
  323. void __ext4_error(struct super_block *sb, const char *function,
  324. unsigned int line, const char *fmt, ...)
  325. {
  326. va_list args;
  327. va_start(args, fmt);
  328. printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: ",
  329. sb->s_id, function, line, current->comm);
  330. vprintk(fmt, args);
  331. printk("\n");
  332. va_end(args);
  333. ext4_handle_error(sb);
  334. }
  335. void ext4_error_inode(struct inode *inode, const char *function,
  336. unsigned int line, ext4_fsblk_t block,
  337. const char *fmt, ...)
  338. {
  339. va_list args;
  340. struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
  341. es->s_last_error_ino = cpu_to_le32(inode->i_ino);
  342. es->s_last_error_block = cpu_to_le64(block);
  343. save_error_info(inode->i_sb, function, line);
  344. va_start(args, fmt);
  345. printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: inode #%lu: ",
  346. inode->i_sb->s_id, function, line, inode->i_ino);
  347. if (block)
  348. printk("block %llu: ", block);
  349. printk("comm %s: ", current->comm);
  350. vprintk(fmt, args);
  351. printk("\n");
  352. va_end(args);
  353. ext4_handle_error(inode->i_sb);
  354. }
  355. void ext4_error_file(struct file *file, const char *function,
  356. unsigned int line, const char *fmt, ...)
  357. {
  358. va_list args;
  359. struct ext4_super_block *es;
  360. struct inode *inode = file->f_dentry->d_inode;
  361. char pathname[80], *path;
  362. es = EXT4_SB(inode->i_sb)->s_es;
  363. es->s_last_error_ino = cpu_to_le32(inode->i_ino);
  364. save_error_info(inode->i_sb, function, line);
  365. va_start(args, fmt);
  366. path = d_path(&(file->f_path), pathname, sizeof(pathname));
  367. if (!path)
  368. path = "(unknown)";
  369. printk(KERN_CRIT
  370. "EXT4-fs error (device %s): %s:%d: inode #%lu "
  371. "(comm %s path %s): ",
  372. inode->i_sb->s_id, function, line, inode->i_ino,
  373. current->comm, path);
  374. vprintk(fmt, args);
  375. printk("\n");
  376. va_end(args);
  377. ext4_handle_error(inode->i_sb);
  378. }
  379. static const char *ext4_decode_error(struct super_block *sb, int errno,
  380. char nbuf[16])
  381. {
  382. char *errstr = NULL;
  383. switch (errno) {
  384. case -EIO:
  385. errstr = "IO failure";
  386. break;
  387. case -ENOMEM:
  388. errstr = "Out of memory";
  389. break;
  390. case -EROFS:
  391. if (!sb || (EXT4_SB(sb)->s_journal &&
  392. EXT4_SB(sb)->s_journal->j_flags & JBD2_ABORT))
  393. errstr = "Journal has aborted";
  394. else
  395. errstr = "Readonly filesystem";
  396. break;
  397. default:
  398. /* If the caller passed in an extra buffer for unknown
  399. * errors, textualise them now. Else we just return
  400. * NULL. */
  401. if (nbuf) {
  402. /* Check for truncated error codes... */
  403. if (snprintf(nbuf, 16, "error %d", -errno) >= 0)
  404. errstr = nbuf;
  405. }
  406. break;
  407. }
  408. return errstr;
  409. }
  410. /* __ext4_std_error decodes expected errors from journaling functions
  411. * automatically and invokes the appropriate error response. */
  412. void __ext4_std_error(struct super_block *sb, const char *function,
  413. unsigned int line, int errno)
  414. {
  415. char nbuf[16];
  416. const char *errstr;
  417. /* Special case: if the error is EROFS, and we're not already
  418. * inside a transaction, then there's really no point in logging
  419. * an error. */
  420. if (errno == -EROFS && journal_current_handle() == NULL &&
  421. (sb->s_flags & MS_RDONLY))
  422. return;
  423. errstr = ext4_decode_error(sb, errno, nbuf);
  424. printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
  425. sb->s_id, function, line, errstr);
  426. save_error_info(sb, function, line);
  427. ext4_handle_error(sb);
  428. }
  429. /*
  430. * ext4_abort is a much stronger failure handler than ext4_error. The
  431. * abort function may be used to deal with unrecoverable failures such
  432. * as journal IO errors or ENOMEM at a critical moment in log management.
  433. *
  434. * We unconditionally force the filesystem into an ABORT|READONLY state,
  435. * unless the error response on the fs has been set to panic in which
  436. * case we take the easy way out and panic immediately.
  437. */
  438. void __ext4_abort(struct super_block *sb, const char *function,
  439. unsigned int line, const char *fmt, ...)
  440. {
  441. va_list args;
  442. save_error_info(sb, function, line);
  443. va_start(args, fmt);
  444. printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: ", sb->s_id,
  445. function, line);
  446. vprintk(fmt, args);
  447. printk("\n");
  448. va_end(args);
  449. if ((sb->s_flags & MS_RDONLY) == 0) {
  450. ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
  451. sb->s_flags |= MS_RDONLY;
  452. EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
  453. if (EXT4_SB(sb)->s_journal)
  454. jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
  455. save_error_info(sb, function, line);
  456. }
  457. if (test_opt(sb, ERRORS_PANIC))
  458. panic("EXT4-fs panic from previous error\n");
  459. }
  460. void ext4_msg (struct super_block * sb, const char *prefix,
  461. const char *fmt, ...)
  462. {
  463. va_list args;
  464. va_start(args, fmt);
  465. printk("%sEXT4-fs (%s): ", prefix, sb->s_id);
  466. vprintk(fmt, args);
  467. printk("\n");
  468. va_end(args);
  469. }
  470. void __ext4_warning(struct super_block *sb, const char *function,
  471. unsigned int line, const char *fmt, ...)
  472. {
  473. va_list args;
  474. va_start(args, fmt);
  475. printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: ",
  476. sb->s_id, function, line);
  477. vprintk(fmt, args);
  478. printk("\n");
  479. va_end(args);
  480. }
  481. void __ext4_grp_locked_error(const char *function, unsigned int line,
  482. struct super_block *sb, ext4_group_t grp,
  483. unsigned long ino, ext4_fsblk_t block,
  484. const char *fmt, ...)
  485. __releases(bitlock)
  486. __acquires(bitlock)
  487. {
  488. va_list args;
  489. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  490. es->s_last_error_ino = cpu_to_le32(ino);
  491. es->s_last_error_block = cpu_to_le64(block);
  492. __save_error_info(sb, function, line);
  493. va_start(args, fmt);
  494. printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u",
  495. sb->s_id, function, line, grp);
  496. if (ino)
  497. printk("inode %lu: ", ino);
  498. if (block)
  499. printk("block %llu:", (unsigned long long) block);
  500. vprintk(fmt, args);
  501. printk("\n");
  502. va_end(args);
  503. if (test_opt(sb, ERRORS_CONT)) {
  504. ext4_commit_super(sb, 0);
  505. return;
  506. }
  507. ext4_unlock_group(sb, grp);
  508. ext4_handle_error(sb);
  509. /*
  510. * We only get here in the ERRORS_RO case; relocking the group
  511. * may be dangerous, but nothing bad will happen since the
  512. * filesystem will have already been marked read/only and the
  513. * journal has been aborted. We return 1 as a hint to callers
  514. * who might what to use the return value from
  515. * ext4_grp_locked_error() to distinguish beween the
  516. * ERRORS_CONT and ERRORS_RO case, and perhaps return more
  517. * aggressively from the ext4 function in question, with a
  518. * more appropriate error code.
  519. */
  520. ext4_lock_group(sb, grp);
  521. return;
  522. }
  523. void ext4_update_dynamic_rev(struct super_block *sb)
  524. {
  525. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  526. if (le32_to_cpu(es->s_rev_level) > EXT4_GOOD_OLD_REV)
  527. return;
  528. ext4_warning(sb,
  529. "updating to rev %d because of new feature flag, "
  530. "running e2fsck is recommended",
  531. EXT4_DYNAMIC_REV);
  532. es->s_first_ino = cpu_to_le32(EXT4_GOOD_OLD_FIRST_INO);
  533. es->s_inode_size = cpu_to_le16(EXT4_GOOD_OLD_INODE_SIZE);
  534. es->s_rev_level = cpu_to_le32(EXT4_DYNAMIC_REV);
  535. /* leave es->s_feature_*compat flags alone */
  536. /* es->s_uuid will be set by e2fsck if empty */
  537. /*
  538. * The rest of the superblock fields should be zero, and if not it
  539. * means they are likely already in use, so leave them alone. We
  540. * can leave it up to e2fsck to clean up any inconsistencies there.
  541. */
  542. }
  543. /*
  544. * Open the external journal device
  545. */
  546. static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
  547. {
  548. struct block_device *bdev;
  549. char b[BDEVNAME_SIZE];
  550. bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE);
  551. if (IS_ERR(bdev))
  552. goto fail;
  553. return bdev;
  554. fail:
  555. ext4_msg(sb, KERN_ERR, "failed to open journal device %s: %ld",
  556. __bdevname(dev, b), PTR_ERR(bdev));
  557. return NULL;
  558. }
  559. /*
  560. * Release the journal device
  561. */
  562. static int ext4_blkdev_put(struct block_device *bdev)
  563. {
  564. bd_release(bdev);
  565. return blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
  566. }
  567. static int ext4_blkdev_remove(struct ext4_sb_info *sbi)
  568. {
  569. struct block_device *bdev;
  570. int ret = -ENODEV;
  571. bdev = sbi->journal_bdev;
  572. if (bdev) {
  573. ret = ext4_blkdev_put(bdev);
  574. sbi->journal_bdev = NULL;
  575. }
  576. return ret;
  577. }
  578. static inline struct inode *orphan_list_entry(struct list_head *l)
  579. {
  580. return &list_entry(l, struct ext4_inode_info, i_orphan)->vfs_inode;
  581. }
  582. static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
  583. {
  584. struct list_head *l;
  585. ext4_msg(sb, KERN_ERR, "sb orphan head is %d",
  586. le32_to_cpu(sbi->s_es->s_last_orphan));
  587. printk(KERN_ERR "sb_info orphan list:\n");
  588. list_for_each(l, &sbi->s_orphan) {
  589. struct inode *inode = orphan_list_entry(l);
  590. printk(KERN_ERR " "
  591. "inode %s:%lu at %p: mode %o, nlink %d, next %d\n",
  592. inode->i_sb->s_id, inode->i_ino, inode,
  593. inode->i_mode, inode->i_nlink,
  594. NEXT_ORPHAN(inode));
  595. }
  596. }
  597. static void ext4_put_super(struct super_block *sb)
  598. {
  599. struct ext4_sb_info *sbi = EXT4_SB(sb);
  600. struct ext4_super_block *es = sbi->s_es;
  601. int i, err;
  602. dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
  603. flush_workqueue(sbi->dio_unwritten_wq);
  604. destroy_workqueue(sbi->dio_unwritten_wq);
  605. lock_super(sb);
  606. lock_kernel();
  607. if (sb->s_dirt)
  608. ext4_commit_super(sb, 1);
  609. if (sbi->s_journal) {
  610. err = jbd2_journal_destroy(sbi->s_journal);
  611. sbi->s_journal = NULL;
  612. if (err < 0)
  613. ext4_abort(sb, "Couldn't clean up the journal");
  614. }
  615. ext4_release_system_zone(sb);
  616. ext4_mb_release(sb);
  617. ext4_ext_release(sb);
  618. ext4_xattr_put_super(sb);
  619. if (!(sb->s_flags & MS_RDONLY)) {
  620. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  621. es->s_state = cpu_to_le16(sbi->s_mount_state);
  622. ext4_commit_super(sb, 1);
  623. }
  624. if (sbi->s_proc) {
  625. remove_proc_entry(sb->s_id, ext4_proc_root);
  626. }
  627. kobject_del(&sbi->s_kobj);
  628. for (i = 0; i < sbi->s_gdb_count; i++)
  629. brelse(sbi->s_group_desc[i]);
  630. kfree(sbi->s_group_desc);
  631. if (is_vmalloc_addr(sbi->s_flex_groups))
  632. vfree(sbi->s_flex_groups);
  633. else
  634. kfree(sbi->s_flex_groups);
  635. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  636. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  637. percpu_counter_destroy(&sbi->s_dirs_counter);
  638. percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
  639. brelse(sbi->s_sbh);
  640. #ifdef CONFIG_QUOTA
  641. for (i = 0; i < MAXQUOTAS; i++)
  642. kfree(sbi->s_qf_names[i]);
  643. #endif
  644. /* Debugging code just in case the in-memory inode orphan list
  645. * isn't empty. The on-disk one can be non-empty if we've
  646. * detected an error and taken the fs readonly, but the
  647. * in-memory list had better be clean by this point. */
  648. if (!list_empty(&sbi->s_orphan))
  649. dump_orphan_list(sb, sbi);
  650. J_ASSERT(list_empty(&sbi->s_orphan));
  651. invalidate_bdev(sb->s_bdev);
  652. if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) {
  653. /*
  654. * Invalidate the journal device's buffers. We don't want them
  655. * floating about in memory - the physical journal device may
  656. * hotswapped, and it breaks the `ro-after' testing code.
  657. */
  658. sync_blockdev(sbi->journal_bdev);
  659. invalidate_bdev(sbi->journal_bdev);
  660. ext4_blkdev_remove(sbi);
  661. }
  662. sb->s_fs_info = NULL;
  663. /*
  664. * Now that we are completely done shutting down the
  665. * superblock, we need to actually destroy the kobject.
  666. */
  667. unlock_kernel();
  668. unlock_super(sb);
  669. kobject_put(&sbi->s_kobj);
  670. wait_for_completion(&sbi->s_kobj_unregister);
  671. kfree(sbi->s_blockgroup_lock);
  672. kfree(sbi);
  673. }
  674. static struct kmem_cache *ext4_inode_cachep;
  675. /*
  676. * Called inside transaction, so use GFP_NOFS
  677. */
  678. static struct inode *ext4_alloc_inode(struct super_block *sb)
  679. {
  680. struct ext4_inode_info *ei;
  681. ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS);
  682. if (!ei)
  683. return NULL;
  684. ei->vfs_inode.i_version = 1;
  685. ei->vfs_inode.i_data.writeback_index = 0;
  686. memset(&ei->i_cached_extent, 0, sizeof(struct ext4_ext_cache));
  687. INIT_LIST_HEAD(&ei->i_prealloc_list);
  688. spin_lock_init(&ei->i_prealloc_lock);
  689. /*
  690. * Note: We can be called before EXT4_SB(sb)->s_journal is set,
  691. * therefore it can be null here. Don't check it, just initialize
  692. * jinode.
  693. */
  694. jbd2_journal_init_jbd_inode(&ei->jinode, &ei->vfs_inode);
  695. ei->i_reserved_data_blocks = 0;
  696. ei->i_reserved_meta_blocks = 0;
  697. ei->i_allocated_meta_blocks = 0;
  698. ei->i_da_metadata_calc_len = 0;
  699. ei->i_delalloc_reserved_flag = 0;
  700. spin_lock_init(&(ei->i_block_reservation_lock));
  701. #ifdef CONFIG_QUOTA
  702. ei->i_reserved_quota = 0;
  703. #endif
  704. INIT_LIST_HEAD(&ei->i_completed_io_list);
  705. spin_lock_init(&ei->i_completed_io_lock);
  706. ei->cur_aio_dio = NULL;
  707. ei->i_sync_tid = 0;
  708. ei->i_datasync_tid = 0;
  709. return &ei->vfs_inode;
  710. }
  711. static void ext4_destroy_inode(struct inode *inode)
  712. {
  713. if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
  714. ext4_msg(inode->i_sb, KERN_ERR,
  715. "Inode %lu (%p): orphan list check failed!",
  716. inode->i_ino, EXT4_I(inode));
  717. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4,
  718. EXT4_I(inode), sizeof(struct ext4_inode_info),
  719. true);
  720. dump_stack();
  721. }
  722. kmem_cache_free(ext4_inode_cachep, EXT4_I(inode));
  723. }
  724. static void init_once(void *foo)
  725. {
  726. struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
  727. INIT_LIST_HEAD(&ei->i_orphan);
  728. #ifdef CONFIG_EXT4_FS_XATTR
  729. init_rwsem(&ei->xattr_sem);
  730. #endif
  731. init_rwsem(&ei->i_data_sem);
  732. inode_init_once(&ei->vfs_inode);
  733. }
  734. static int init_inodecache(void)
  735. {
  736. ext4_inode_cachep = kmem_cache_create("ext4_inode_cache",
  737. sizeof(struct ext4_inode_info),
  738. 0, (SLAB_RECLAIM_ACCOUNT|
  739. SLAB_MEM_SPREAD),
  740. init_once);
  741. if (ext4_inode_cachep == NULL)
  742. return -ENOMEM;
  743. return 0;
  744. }
  745. static void destroy_inodecache(void)
  746. {
  747. kmem_cache_destroy(ext4_inode_cachep);
  748. }
  749. static void ext4_clear_inode(struct inode *inode)
  750. {
  751. dquot_drop(inode);
  752. ext4_discard_preallocations(inode);
  753. if (EXT4_JOURNAL(inode))
  754. jbd2_journal_release_jbd_inode(EXT4_SB(inode->i_sb)->s_journal,
  755. &EXT4_I(inode)->jinode);
  756. }
  757. static inline void ext4_show_quota_options(struct seq_file *seq,
  758. struct super_block *sb)
  759. {
  760. #if defined(CONFIG_QUOTA)
  761. struct ext4_sb_info *sbi = EXT4_SB(sb);
  762. if (sbi->s_jquota_fmt) {
  763. char *fmtname = "";
  764. switch (sbi->s_jquota_fmt) {
  765. case QFMT_VFS_OLD:
  766. fmtname = "vfsold";
  767. break;
  768. case QFMT_VFS_V0:
  769. fmtname = "vfsv0";
  770. break;
  771. case QFMT_VFS_V1:
  772. fmtname = "vfsv1";
  773. break;
  774. }
  775. seq_printf(seq, ",jqfmt=%s", fmtname);
  776. }
  777. if (sbi->s_qf_names[USRQUOTA])
  778. seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]);
  779. if (sbi->s_qf_names[GRPQUOTA])
  780. seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]);
  781. if (test_opt(sb, USRQUOTA))
  782. seq_puts(seq, ",usrquota");
  783. if (test_opt(sb, GRPQUOTA))
  784. seq_puts(seq, ",grpquota");
  785. #endif
  786. }
  787. /*
  788. * Show an option if
  789. * - it's set to a non-default value OR
  790. * - if the per-sb default is different from the global default
  791. */
  792. static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
  793. {
  794. int def_errors;
  795. unsigned long def_mount_opts;
  796. struct super_block *sb = vfs->mnt_sb;
  797. struct ext4_sb_info *sbi = EXT4_SB(sb);
  798. struct ext4_super_block *es = sbi->s_es;
  799. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  800. def_errors = le16_to_cpu(es->s_errors);
  801. if (sbi->s_sb_block != 1)
  802. seq_printf(seq, ",sb=%llu", sbi->s_sb_block);
  803. if (test_opt(sb, MINIX_DF))
  804. seq_puts(seq, ",minixdf");
  805. if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS))
  806. seq_puts(seq, ",grpid");
  807. if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS))
  808. seq_puts(seq, ",nogrpid");
  809. if (sbi->s_resuid != EXT4_DEF_RESUID ||
  810. le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) {
  811. seq_printf(seq, ",resuid=%u", sbi->s_resuid);
  812. }
  813. if (sbi->s_resgid != EXT4_DEF_RESGID ||
  814. le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) {
  815. seq_printf(seq, ",resgid=%u", sbi->s_resgid);
  816. }
  817. if (test_opt(sb, ERRORS_RO)) {
  818. if (def_errors == EXT4_ERRORS_PANIC ||
  819. def_errors == EXT4_ERRORS_CONTINUE) {
  820. seq_puts(seq, ",errors=remount-ro");
  821. }
  822. }
  823. if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE)
  824. seq_puts(seq, ",errors=continue");
  825. if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC)
  826. seq_puts(seq, ",errors=panic");
  827. if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16))
  828. seq_puts(seq, ",nouid32");
  829. if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG))
  830. seq_puts(seq, ",debug");
  831. if (test_opt(sb, OLDALLOC))
  832. seq_puts(seq, ",oldalloc");
  833. #ifdef CONFIG_EXT4_FS_XATTR
  834. if (test_opt(sb, XATTR_USER) &&
  835. !(def_mount_opts & EXT4_DEFM_XATTR_USER))
  836. seq_puts(seq, ",user_xattr");
  837. if (!test_opt(sb, XATTR_USER) &&
  838. (def_mount_opts & EXT4_DEFM_XATTR_USER)) {
  839. seq_puts(seq, ",nouser_xattr");
  840. }
  841. #endif
  842. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  843. if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL))
  844. seq_puts(seq, ",acl");
  845. if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL))
  846. seq_puts(seq, ",noacl");
  847. #endif
  848. if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
  849. seq_printf(seq, ",commit=%u",
  850. (unsigned) (sbi->s_commit_interval / HZ));
  851. }
  852. if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) {
  853. seq_printf(seq, ",min_batch_time=%u",
  854. (unsigned) sbi->s_min_batch_time);
  855. }
  856. if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) {
  857. seq_printf(seq, ",max_batch_time=%u",
  858. (unsigned) sbi->s_min_batch_time);
  859. }
  860. /*
  861. * We're changing the default of barrier mount option, so
  862. * let's always display its mount state so it's clear what its
  863. * status is.
  864. */
  865. seq_puts(seq, ",barrier=");
  866. seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0");
  867. if (test_opt(sb, JOURNAL_ASYNC_COMMIT))
  868. seq_puts(seq, ",journal_async_commit");
  869. else if (test_opt(sb, JOURNAL_CHECKSUM))
  870. seq_puts(seq, ",journal_checksum");
  871. if (test_opt(sb, I_VERSION))
  872. seq_puts(seq, ",i_version");
  873. if (!test_opt(sb, DELALLOC))
  874. seq_puts(seq, ",nodelalloc");
  875. if (sbi->s_stripe)
  876. seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
  877. /*
  878. * journal mode get enabled in different ways
  879. * So just print the value even if we didn't specify it
  880. */
  881. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
  882. seq_puts(seq, ",data=journal");
  883. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
  884. seq_puts(seq, ",data=ordered");
  885. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
  886. seq_puts(seq, ",data=writeback");
  887. if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS)
  888. seq_printf(seq, ",inode_readahead_blks=%u",
  889. sbi->s_inode_readahead_blks);
  890. if (test_opt(sb, DATA_ERR_ABORT))
  891. seq_puts(seq, ",data_err=abort");
  892. if (test_opt(sb, NO_AUTO_DA_ALLOC))
  893. seq_puts(seq, ",noauto_da_alloc");
  894. if (test_opt(sb, DISCARD))
  895. seq_puts(seq, ",discard");
  896. if (test_opt(sb, NOLOAD))
  897. seq_puts(seq, ",norecovery");
  898. if (test_opt(sb, DIOREAD_NOLOCK))
  899. seq_puts(seq, ",dioread_nolock");
  900. ext4_show_quota_options(seq, sb);
  901. return 0;
  902. }
  903. static struct inode *ext4_nfs_get_inode(struct super_block *sb,
  904. u64 ino, u32 generation)
  905. {
  906. struct inode *inode;
  907. if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO)
  908. return ERR_PTR(-ESTALE);
  909. if (ino > le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count))
  910. return ERR_PTR(-ESTALE);
  911. /* iget isn't really right if the inode is currently unallocated!!
  912. *
  913. * ext4_read_inode will return a bad_inode if the inode had been
  914. * deleted, so we should be safe.
  915. *
  916. * Currently we don't know the generation for parent directory, so
  917. * a generation of 0 means "accept any"
  918. */
  919. inode = ext4_iget(sb, ino);
  920. if (IS_ERR(inode))
  921. return ERR_CAST(inode);
  922. if (generation && inode->i_generation != generation) {
  923. iput(inode);
  924. return ERR_PTR(-ESTALE);
  925. }
  926. return inode;
  927. }
  928. static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid,
  929. int fh_len, int fh_type)
  930. {
  931. return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
  932. ext4_nfs_get_inode);
  933. }
  934. static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
  935. int fh_len, int fh_type)
  936. {
  937. return generic_fh_to_parent(sb, fid, fh_len, fh_type,
  938. ext4_nfs_get_inode);
  939. }
  940. /*
  941. * Try to release metadata pages (indirect blocks, directories) which are
  942. * mapped via the block device. Since these pages could have journal heads
  943. * which would prevent try_to_free_buffers() from freeing them, we must use
  944. * jbd2 layer's try_to_free_buffers() function to release them.
  945. */
  946. static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
  947. gfp_t wait)
  948. {
  949. journal_t *journal = EXT4_SB(sb)->s_journal;
  950. WARN_ON(PageChecked(page));
  951. if (!page_has_buffers(page))
  952. return 0;
  953. if (journal)
  954. return jbd2_journal_try_to_free_buffers(journal, page,
  955. wait & ~__GFP_WAIT);
  956. return try_to_free_buffers(page);
  957. }
  958. #ifdef CONFIG_QUOTA
  959. #define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
  960. #define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
  961. static int ext4_write_dquot(struct dquot *dquot);
  962. static int ext4_acquire_dquot(struct dquot *dquot);
  963. static int ext4_release_dquot(struct dquot *dquot);
  964. static int ext4_mark_dquot_dirty(struct dquot *dquot);
  965. static int ext4_write_info(struct super_block *sb, int type);
  966. static int ext4_quota_on(struct super_block *sb, int type, int format_id,
  967. char *path);
  968. static int ext4_quota_on_mount(struct super_block *sb, int type);
  969. static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
  970. size_t len, loff_t off);
  971. static ssize_t ext4_quota_write(struct super_block *sb, int type,
  972. const char *data, size_t len, loff_t off);
  973. static const struct dquot_operations ext4_quota_operations = {
  974. #ifdef CONFIG_QUOTA
  975. .get_reserved_space = ext4_get_reserved_space,
  976. #endif
  977. .write_dquot = ext4_write_dquot,
  978. .acquire_dquot = ext4_acquire_dquot,
  979. .release_dquot = ext4_release_dquot,
  980. .mark_dirty = ext4_mark_dquot_dirty,
  981. .write_info = ext4_write_info,
  982. .alloc_dquot = dquot_alloc,
  983. .destroy_dquot = dquot_destroy,
  984. };
  985. static const struct quotactl_ops ext4_qctl_operations = {
  986. .quota_on = ext4_quota_on,
  987. .quota_off = dquot_quota_off,
  988. .quota_sync = dquot_quota_sync,
  989. .get_info = dquot_get_dqinfo,
  990. .set_info = dquot_set_dqinfo,
  991. .get_dqblk = dquot_get_dqblk,
  992. .set_dqblk = dquot_set_dqblk
  993. };
  994. #endif
  995. static const struct super_operations ext4_sops = {
  996. .alloc_inode = ext4_alloc_inode,
  997. .destroy_inode = ext4_destroy_inode,
  998. .write_inode = ext4_write_inode,
  999. .dirty_inode = ext4_dirty_inode,
  1000. .delete_inode = ext4_delete_inode,
  1001. .put_super = ext4_put_super,
  1002. .sync_fs = ext4_sync_fs,
  1003. .freeze_fs = ext4_freeze,
  1004. .unfreeze_fs = ext4_unfreeze,
  1005. .statfs = ext4_statfs,
  1006. .remount_fs = ext4_remount,
  1007. .clear_inode = ext4_clear_inode,
  1008. .show_options = ext4_show_options,
  1009. #ifdef CONFIG_QUOTA
  1010. .quota_read = ext4_quota_read,
  1011. .quota_write = ext4_quota_write,
  1012. #endif
  1013. .bdev_try_to_free_page = bdev_try_to_free_page,
  1014. };
  1015. static const struct super_operations ext4_nojournal_sops = {
  1016. .alloc_inode = ext4_alloc_inode,
  1017. .destroy_inode = ext4_destroy_inode,
  1018. .write_inode = ext4_write_inode,
  1019. .dirty_inode = ext4_dirty_inode,
  1020. .delete_inode = ext4_delete_inode,
  1021. .write_super = ext4_write_super,
  1022. .put_super = ext4_put_super,
  1023. .statfs = ext4_statfs,
  1024. .remount_fs = ext4_remount,
  1025. .clear_inode = ext4_clear_inode,
  1026. .show_options = ext4_show_options,
  1027. #ifdef CONFIG_QUOTA
  1028. .quota_read = ext4_quota_read,
  1029. .quota_write = ext4_quota_write,
  1030. #endif
  1031. .bdev_try_to_free_page = bdev_try_to_free_page,
  1032. };
  1033. static const struct export_operations ext4_export_ops = {
  1034. .fh_to_dentry = ext4_fh_to_dentry,
  1035. .fh_to_parent = ext4_fh_to_parent,
  1036. .get_parent = ext4_get_parent,
  1037. };
  1038. enum {
  1039. Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid,
  1040. Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro,
  1041. Opt_nouid32, Opt_debug, Opt_oldalloc, Opt_orlov,
  1042. Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
  1043. Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload, Opt_nobh, Opt_bh,
  1044. Opt_commit, Opt_min_batch_time, Opt_max_batch_time,
  1045. Opt_journal_update, Opt_journal_dev,
  1046. Opt_journal_checksum, Opt_journal_async_commit,
  1047. Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
  1048. Opt_data_err_abort, Opt_data_err_ignore,
  1049. Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
  1050. Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
  1051. Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
  1052. Opt_resize, Opt_usrquota, Opt_grpquota, Opt_i_version,
  1053. Opt_stripe, Opt_delalloc, Opt_nodelalloc,
  1054. Opt_block_validity, Opt_noblock_validity,
  1055. Opt_inode_readahead_blks, Opt_journal_ioprio,
  1056. Opt_dioread_nolock, Opt_dioread_lock,
  1057. Opt_discard, Opt_nodiscard,
  1058. };
  1059. static const match_table_t tokens = {
  1060. {Opt_bsd_df, "bsddf"},
  1061. {Opt_minix_df, "minixdf"},
  1062. {Opt_grpid, "grpid"},
  1063. {Opt_grpid, "bsdgroups"},
  1064. {Opt_nogrpid, "nogrpid"},
  1065. {Opt_nogrpid, "sysvgroups"},
  1066. {Opt_resgid, "resgid=%u"},
  1067. {Opt_resuid, "resuid=%u"},
  1068. {Opt_sb, "sb=%u"},
  1069. {Opt_err_cont, "errors=continue"},
  1070. {Opt_err_panic, "errors=panic"},
  1071. {Opt_err_ro, "errors=remount-ro"},
  1072. {Opt_nouid32, "nouid32"},
  1073. {Opt_debug, "debug"},
  1074. {Opt_oldalloc, "oldalloc"},
  1075. {Opt_orlov, "orlov"},
  1076. {Opt_user_xattr, "user_xattr"},
  1077. {Opt_nouser_xattr, "nouser_xattr"},
  1078. {Opt_acl, "acl"},
  1079. {Opt_noacl, "noacl"},
  1080. {Opt_noload, "noload"},
  1081. {Opt_noload, "norecovery"},
  1082. {Opt_nobh, "nobh"},
  1083. {Opt_bh, "bh"},
  1084. {Opt_commit, "commit=%u"},
  1085. {Opt_min_batch_time, "min_batch_time=%u"},
  1086. {Opt_max_batch_time, "max_batch_time=%u"},
  1087. {Opt_journal_update, "journal=update"},
  1088. {Opt_journal_dev, "journal_dev=%u"},
  1089. {Opt_journal_checksum, "journal_checksum"},
  1090. {Opt_journal_async_commit, "journal_async_commit"},
  1091. {Opt_abort, "abort"},
  1092. {Opt_data_journal, "data=journal"},
  1093. {Opt_data_ordered, "data=ordered"},
  1094. {Opt_data_writeback, "data=writeback"},
  1095. {Opt_data_err_abort, "data_err=abort"},
  1096. {Opt_data_err_ignore, "data_err=ignore"},
  1097. {Opt_offusrjquota, "usrjquota="},
  1098. {Opt_usrjquota, "usrjquota=%s"},
  1099. {Opt_offgrpjquota, "grpjquota="},
  1100. {Opt_grpjquota, "grpjquota=%s"},
  1101. {Opt_jqfmt_vfsold, "jqfmt=vfsold"},
  1102. {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"},
  1103. {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"},
  1104. {Opt_grpquota, "grpquota"},
  1105. {Opt_noquota, "noquota"},
  1106. {Opt_quota, "quota"},
  1107. {Opt_usrquota, "usrquota"},
  1108. {Opt_barrier, "barrier=%u"},
  1109. {Opt_barrier, "barrier"},
  1110. {Opt_nobarrier, "nobarrier"},
  1111. {Opt_i_version, "i_version"},
  1112. {Opt_stripe, "stripe=%u"},
  1113. {Opt_resize, "resize"},
  1114. {Opt_delalloc, "delalloc"},
  1115. {Opt_nodelalloc, "nodelalloc"},
  1116. {Opt_block_validity, "block_validity"},
  1117. {Opt_noblock_validity, "noblock_validity"},
  1118. {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
  1119. {Opt_journal_ioprio, "journal_ioprio=%u"},
  1120. {Opt_auto_da_alloc, "auto_da_alloc=%u"},
  1121. {Opt_auto_da_alloc, "auto_da_alloc"},
  1122. {Opt_noauto_da_alloc, "noauto_da_alloc"},
  1123. {Opt_dioread_nolock, "dioread_nolock"},
  1124. {Opt_dioread_lock, "dioread_lock"},
  1125. {Opt_discard, "discard"},
  1126. {Opt_nodiscard, "nodiscard"},
  1127. {Opt_err, NULL},
  1128. };
  1129. static ext4_fsblk_t get_sb_block(void **data)
  1130. {
  1131. ext4_fsblk_t sb_block;
  1132. char *options = (char *) *data;
  1133. if (!options || strncmp(options, "sb=", 3) != 0)
  1134. return 1; /* Default location */
  1135. options += 3;
  1136. /* TODO: use simple_strtoll with >32bit ext4 */
  1137. sb_block = simple_strtoul(options, &options, 0);
  1138. if (*options && *options != ',') {
  1139. printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
  1140. (char *) *data);
  1141. return 1;
  1142. }
  1143. if (*options == ',')
  1144. options++;
  1145. *data = (void *) options;
  1146. return sb_block;
  1147. }
  1148. #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
  1149. static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
  1150. "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
  1151. #ifdef CONFIG_QUOTA
  1152. static int set_qf_name(struct super_block *sb, int qtype, substring_t *args)
  1153. {
  1154. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1155. char *qname;
  1156. if (sb_any_quota_loaded(sb) &&
  1157. !sbi->s_qf_names[qtype]) {
  1158. ext4_msg(sb, KERN_ERR,
  1159. "Cannot change journaled "
  1160. "quota options when quota turned on");
  1161. return 0;
  1162. }
  1163. qname = match_strdup(args);
  1164. if (!qname) {
  1165. ext4_msg(sb, KERN_ERR,
  1166. "Not enough memory for storing quotafile name");
  1167. return 0;
  1168. }
  1169. if (sbi->s_qf_names[qtype] &&
  1170. strcmp(sbi->s_qf_names[qtype], qname)) {
  1171. ext4_msg(sb, KERN_ERR,
  1172. "%s quota file already specified", QTYPE2NAME(qtype));
  1173. kfree(qname);
  1174. return 0;
  1175. }
  1176. sbi->s_qf_names[qtype] = qname;
  1177. if (strchr(sbi->s_qf_names[qtype], '/')) {
  1178. ext4_msg(sb, KERN_ERR,
  1179. "quotafile must be on filesystem root");
  1180. kfree(sbi->s_qf_names[qtype]);
  1181. sbi->s_qf_names[qtype] = NULL;
  1182. return 0;
  1183. }
  1184. set_opt(sbi->s_mount_opt, QUOTA);
  1185. return 1;
  1186. }
  1187. static int clear_qf_name(struct super_block *sb, int qtype)
  1188. {
  1189. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1190. if (sb_any_quota_loaded(sb) &&
  1191. sbi->s_qf_names[qtype]) {
  1192. ext4_msg(sb, KERN_ERR, "Cannot change journaled quota options"
  1193. " when quota turned on");
  1194. return 0;
  1195. }
  1196. /*
  1197. * The space will be released later when all options are confirmed
  1198. * to be correct
  1199. */
  1200. sbi->s_qf_names[qtype] = NULL;
  1201. return 1;
  1202. }
  1203. #endif
  1204. static int parse_options(char *options, struct super_block *sb,
  1205. unsigned long *journal_devnum,
  1206. unsigned int *journal_ioprio,
  1207. ext4_fsblk_t *n_blocks_count, int is_remount)
  1208. {
  1209. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1210. char *p;
  1211. substring_t args[MAX_OPT_ARGS];
  1212. int data_opt = 0;
  1213. int option;
  1214. #ifdef CONFIG_QUOTA
  1215. int qfmt;
  1216. #endif
  1217. if (!options)
  1218. return 1;
  1219. while ((p = strsep(&options, ",")) != NULL) {
  1220. int token;
  1221. if (!*p)
  1222. continue;
  1223. /*
  1224. * Initialize args struct so we know whether arg was
  1225. * found; some options take optional arguments.
  1226. */
  1227. args[0].to = args[0].from = 0;
  1228. token = match_token(p, tokens, args);
  1229. switch (token) {
  1230. case Opt_bsd_df:
  1231. ext4_msg(sb, KERN_WARNING, deprecated_msg, p, "2.6.38");
  1232. clear_opt(sbi->s_mount_opt, MINIX_DF);
  1233. break;
  1234. case Opt_minix_df:
  1235. ext4_msg(sb, KERN_WARNING, deprecated_msg, p, "2.6.38");
  1236. set_opt(sbi->s_mount_opt, MINIX_DF);
  1237. break;
  1238. case Opt_grpid:
  1239. ext4_msg(sb, KERN_WARNING, deprecated_msg, p, "2.6.38");
  1240. set_opt(sbi->s_mount_opt, GRPID);
  1241. break;
  1242. case Opt_nogrpid:
  1243. ext4_msg(sb, KERN_WARNING, deprecated_msg, p, "2.6.38");
  1244. clear_opt(sbi->s_mount_opt, GRPID);
  1245. break;
  1246. case Opt_resuid:
  1247. if (match_int(&args[0], &option))
  1248. return 0;
  1249. sbi->s_resuid = option;
  1250. break;
  1251. case Opt_resgid:
  1252. if (match_int(&args[0], &option))
  1253. return 0;
  1254. sbi->s_resgid = option;
  1255. break;
  1256. case Opt_sb:
  1257. /* handled by get_sb_block() instead of here */
  1258. /* *sb_block = match_int(&args[0]); */
  1259. break;
  1260. case Opt_err_panic:
  1261. clear_opt(sbi->s_mount_opt, ERRORS_CONT);
  1262. clear_opt(sbi->s_mount_opt, ERRORS_RO);
  1263. set_opt(sbi->s_mount_opt, ERRORS_PANIC);
  1264. break;
  1265. case Opt_err_ro:
  1266. clear_opt(sbi->s_mount_opt, ERRORS_CONT);
  1267. clear_opt(sbi->s_mount_opt, ERRORS_PANIC);
  1268. set_opt(sbi->s_mount_opt, ERRORS_RO);
  1269. break;
  1270. case Opt_err_cont:
  1271. clear_opt(sbi->s_mount_opt, ERRORS_RO);
  1272. clear_opt(sbi->s_mount_opt, ERRORS_PANIC);
  1273. set_opt(sbi->s_mount_opt, ERRORS_CONT);
  1274. break;
  1275. case Opt_nouid32:
  1276. set_opt(sbi->s_mount_opt, NO_UID32);
  1277. break;
  1278. case Opt_debug:
  1279. set_opt(sbi->s_mount_opt, DEBUG);
  1280. break;
  1281. case Opt_oldalloc:
  1282. set_opt(sbi->s_mount_opt, OLDALLOC);
  1283. break;
  1284. case Opt_orlov:
  1285. clear_opt(sbi->s_mount_opt, OLDALLOC);
  1286. break;
  1287. #ifdef CONFIG_EXT4_FS_XATTR
  1288. case Opt_user_xattr:
  1289. set_opt(sbi->s_mount_opt, XATTR_USER);
  1290. break;
  1291. case Opt_nouser_xattr:
  1292. clear_opt(sbi->s_mount_opt, XATTR_USER);
  1293. break;
  1294. #else
  1295. case Opt_user_xattr:
  1296. case Opt_nouser_xattr:
  1297. ext4_msg(sb, KERN_ERR, "(no)user_xattr options not supported");
  1298. break;
  1299. #endif
  1300. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  1301. case Opt_acl:
  1302. set_opt(sbi->s_mount_opt, POSIX_ACL);
  1303. break;
  1304. case Opt_noacl:
  1305. clear_opt(sbi->s_mount_opt, POSIX_ACL);
  1306. break;
  1307. #else
  1308. case Opt_acl:
  1309. case Opt_noacl:
  1310. ext4_msg(sb, KERN_ERR, "(no)acl options not supported");
  1311. break;
  1312. #endif
  1313. case Opt_journal_update:
  1314. /* @@@ FIXME */
  1315. /* Eventually we will want to be able to create
  1316. a journal file here. For now, only allow the
  1317. user to specify an existing inode to be the
  1318. journal file. */
  1319. if (is_remount) {
  1320. ext4_msg(sb, KERN_ERR,
  1321. "Cannot specify journal on remount");
  1322. return 0;
  1323. }
  1324. set_opt(sbi->s_mount_opt, UPDATE_JOURNAL);
  1325. break;
  1326. case Opt_journal_dev:
  1327. if (is_remount) {
  1328. ext4_msg(sb, KERN_ERR,
  1329. "Cannot specify journal on remount");
  1330. return 0;
  1331. }
  1332. if (match_int(&args[0], &option))
  1333. return 0;
  1334. *journal_devnum = option;
  1335. break;
  1336. case Opt_journal_checksum:
  1337. set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM);
  1338. break;
  1339. case Opt_journal_async_commit:
  1340. set_opt(sbi->s_mount_opt, JOURNAL_ASYNC_COMMIT);
  1341. set_opt(sbi->s_mount_opt, JOURNAL_CHECKSUM);
  1342. break;
  1343. case Opt_noload:
  1344. set_opt(sbi->s_mount_opt, NOLOAD);
  1345. break;
  1346. case Opt_commit:
  1347. if (match_int(&args[0], &option))
  1348. return 0;
  1349. if (option < 0)
  1350. return 0;
  1351. if (option == 0)
  1352. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1353. sbi->s_commit_interval = HZ * option;
  1354. break;
  1355. case Opt_max_batch_time:
  1356. if (match_int(&args[0], &option))
  1357. return 0;
  1358. if (option < 0)
  1359. return 0;
  1360. if (option == 0)
  1361. option = EXT4_DEF_MAX_BATCH_TIME;
  1362. sbi->s_max_batch_time = option;
  1363. break;
  1364. case Opt_min_batch_time:
  1365. if (match_int(&args[0], &option))
  1366. return 0;
  1367. if (option < 0)
  1368. return 0;
  1369. sbi->s_min_batch_time = option;
  1370. break;
  1371. case Opt_data_journal:
  1372. data_opt = EXT4_MOUNT_JOURNAL_DATA;
  1373. goto datacheck;
  1374. case Opt_data_ordered:
  1375. data_opt = EXT4_MOUNT_ORDERED_DATA;
  1376. goto datacheck;
  1377. case Opt_data_writeback:
  1378. data_opt = EXT4_MOUNT_WRITEBACK_DATA;
  1379. datacheck:
  1380. if (is_remount) {
  1381. if (test_opt(sb, DATA_FLAGS) != data_opt) {
  1382. ext4_msg(sb, KERN_ERR,
  1383. "Cannot change data mode on remount");
  1384. return 0;
  1385. }
  1386. } else {
  1387. clear_opt(sbi->s_mount_opt, DATA_FLAGS);
  1388. sbi->s_mount_opt |= data_opt;
  1389. }
  1390. break;
  1391. case Opt_data_err_abort:
  1392. set_opt(sbi->s_mount_opt, DATA_ERR_ABORT);
  1393. break;
  1394. case Opt_data_err_ignore:
  1395. clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT);
  1396. break;
  1397. #ifdef CONFIG_QUOTA
  1398. case Opt_usrjquota:
  1399. if (!set_qf_name(sb, USRQUOTA, &args[0]))
  1400. return 0;
  1401. break;
  1402. case Opt_grpjquota:
  1403. if (!set_qf_name(sb, GRPQUOTA, &args[0]))
  1404. return 0;
  1405. break;
  1406. case Opt_offusrjquota:
  1407. if (!clear_qf_name(sb, USRQUOTA))
  1408. return 0;
  1409. break;
  1410. case Opt_offgrpjquota:
  1411. if (!clear_qf_name(sb, GRPQUOTA))
  1412. return 0;
  1413. break;
  1414. case Opt_jqfmt_vfsold:
  1415. qfmt = QFMT_VFS_OLD;
  1416. goto set_qf_format;
  1417. case Opt_jqfmt_vfsv0:
  1418. qfmt = QFMT_VFS_V0;
  1419. goto set_qf_format;
  1420. case Opt_jqfmt_vfsv1:
  1421. qfmt = QFMT_VFS_V1;
  1422. set_qf_format:
  1423. if (sb_any_quota_loaded(sb) &&
  1424. sbi->s_jquota_fmt != qfmt) {
  1425. ext4_msg(sb, KERN_ERR, "Cannot change "
  1426. "journaled quota options when "
  1427. "quota turned on");
  1428. return 0;
  1429. }
  1430. sbi->s_jquota_fmt = qfmt;
  1431. break;
  1432. case Opt_quota:
  1433. case Opt_usrquota:
  1434. set_opt(sbi->s_mount_opt, QUOTA);
  1435. set_opt(sbi->s_mount_opt, USRQUOTA);
  1436. break;
  1437. case Opt_grpquota:
  1438. set_opt(sbi->s_mount_opt, QUOTA);
  1439. set_opt(sbi->s_mount_opt, GRPQUOTA);
  1440. break;
  1441. case Opt_noquota:
  1442. if (sb_any_quota_loaded(sb)) {
  1443. ext4_msg(sb, KERN_ERR, "Cannot change quota "
  1444. "options when quota turned on");
  1445. return 0;
  1446. }
  1447. clear_opt(sbi->s_mount_opt, QUOTA);
  1448. clear_opt(sbi->s_mount_opt, USRQUOTA);
  1449. clear_opt(sbi->s_mount_opt, GRPQUOTA);
  1450. break;
  1451. #else
  1452. case Opt_quota:
  1453. case Opt_usrquota:
  1454. case Opt_grpquota:
  1455. ext4_msg(sb, KERN_ERR,
  1456. "quota options not supported");
  1457. break;
  1458. case Opt_usrjquota:
  1459. case Opt_grpjquota:
  1460. case Opt_offusrjquota:
  1461. case Opt_offgrpjquota:
  1462. case Opt_jqfmt_vfsold:
  1463. case Opt_jqfmt_vfsv0:
  1464. case Opt_jqfmt_vfsv1:
  1465. ext4_msg(sb, KERN_ERR,
  1466. "journaled quota options not supported");
  1467. break;
  1468. case Opt_noquota:
  1469. break;
  1470. #endif
  1471. case Opt_abort:
  1472. sbi->s_mount_flags |= EXT4_MF_FS_ABORTED;
  1473. break;
  1474. case Opt_nobarrier:
  1475. clear_opt(sbi->s_mount_opt, BARRIER);
  1476. break;
  1477. case Opt_barrier:
  1478. if (args[0].from) {
  1479. if (match_int(&args[0], &option))
  1480. return 0;
  1481. } else
  1482. option = 1; /* No argument, default to 1 */
  1483. if (option)
  1484. set_opt(sbi->s_mount_opt, BARRIER);
  1485. else
  1486. clear_opt(sbi->s_mount_opt, BARRIER);
  1487. break;
  1488. case Opt_ignore:
  1489. break;
  1490. case Opt_resize:
  1491. if (!is_remount) {
  1492. ext4_msg(sb, KERN_ERR,
  1493. "resize option only available "
  1494. "for remount");
  1495. return 0;
  1496. }
  1497. if (match_int(&args[0], &option) != 0)
  1498. return 0;
  1499. *n_blocks_count = option;
  1500. break;
  1501. case Opt_nobh:
  1502. ext4_msg(sb, KERN_WARNING,
  1503. "Ignoring deprecated nobh option");
  1504. break;
  1505. case Opt_bh:
  1506. ext4_msg(sb, KERN_WARNING,
  1507. "Ignoring deprecated bh option");
  1508. break;
  1509. case Opt_i_version:
  1510. set_opt(sbi->s_mount_opt, I_VERSION);
  1511. sb->s_flags |= MS_I_VERSION;
  1512. break;
  1513. case Opt_nodelalloc:
  1514. clear_opt(sbi->s_mount_opt, DELALLOC);
  1515. break;
  1516. case Opt_stripe:
  1517. if (match_int(&args[0], &option))
  1518. return 0;
  1519. if (option < 0)
  1520. return 0;
  1521. sbi->s_stripe = option;
  1522. break;
  1523. case Opt_delalloc:
  1524. set_opt(sbi->s_mount_opt, DELALLOC);
  1525. break;
  1526. case Opt_block_validity:
  1527. set_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
  1528. break;
  1529. case Opt_noblock_validity:
  1530. clear_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
  1531. break;
  1532. case Opt_inode_readahead_blks:
  1533. if (match_int(&args[0], &option))
  1534. return 0;
  1535. if (option < 0 || option > (1 << 30))
  1536. return 0;
  1537. if (!is_power_of_2(option)) {
  1538. ext4_msg(sb, KERN_ERR,
  1539. "EXT4-fs: inode_readahead_blks"
  1540. " must be a power of 2");
  1541. return 0;
  1542. }
  1543. sbi->s_inode_readahead_blks = option;
  1544. break;
  1545. case Opt_journal_ioprio:
  1546. if (match_int(&args[0], &option))
  1547. return 0;
  1548. if (option < 0 || option > 7)
  1549. break;
  1550. *journal_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE,
  1551. option);
  1552. break;
  1553. case Opt_noauto_da_alloc:
  1554. set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC);
  1555. break;
  1556. case Opt_auto_da_alloc:
  1557. if (args[0].from) {
  1558. if (match_int(&args[0], &option))
  1559. return 0;
  1560. } else
  1561. option = 1; /* No argument, default to 1 */
  1562. if (option)
  1563. clear_opt(sbi->s_mount_opt, NO_AUTO_DA_ALLOC);
  1564. else
  1565. set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC);
  1566. break;
  1567. case Opt_discard:
  1568. set_opt(sbi->s_mount_opt, DISCARD);
  1569. break;
  1570. case Opt_nodiscard:
  1571. clear_opt(sbi->s_mount_opt, DISCARD);
  1572. break;
  1573. case Opt_dioread_nolock:
  1574. set_opt(sbi->s_mount_opt, DIOREAD_NOLOCK);
  1575. break;
  1576. case Opt_dioread_lock:
  1577. clear_opt(sbi->s_mount_opt, DIOREAD_NOLOCK);
  1578. break;
  1579. default:
  1580. ext4_msg(sb, KERN_ERR,
  1581. "Unrecognized mount option \"%s\" "
  1582. "or missing value", p);
  1583. return 0;
  1584. }
  1585. }
  1586. #ifdef CONFIG_QUOTA
  1587. if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) {
  1588. if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA])
  1589. clear_opt(sbi->s_mount_opt, USRQUOTA);
  1590. if (test_opt(sb, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA])
  1591. clear_opt(sbi->s_mount_opt, GRPQUOTA);
  1592. if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) {
  1593. ext4_msg(sb, KERN_ERR, "old and new quota "
  1594. "format mixing");
  1595. return 0;
  1596. }
  1597. if (!sbi->s_jquota_fmt) {
  1598. ext4_msg(sb, KERN_ERR, "journaled quota format "
  1599. "not specified");
  1600. return 0;
  1601. }
  1602. } else {
  1603. if (sbi->s_jquota_fmt) {
  1604. ext4_msg(sb, KERN_ERR, "journaled quota format "
  1605. "specified with no journaling "
  1606. "enabled");
  1607. return 0;
  1608. }
  1609. }
  1610. #endif
  1611. return 1;
  1612. }
  1613. static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
  1614. int read_only)
  1615. {
  1616. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1617. int res = 0;
  1618. if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
  1619. ext4_msg(sb, KERN_ERR, "revision level too high, "
  1620. "forcing read-only mode");
  1621. res = MS_RDONLY;
  1622. }
  1623. if (read_only)
  1624. return res;
  1625. if (!(sbi->s_mount_state & EXT4_VALID_FS))
  1626. ext4_msg(sb, KERN_WARNING, "warning: mounting unchecked fs, "
  1627. "running e2fsck is recommended");
  1628. else if ((sbi->s_mount_state & EXT4_ERROR_FS))
  1629. ext4_msg(sb, KERN_WARNING,
  1630. "warning: mounting fs with errors, "
  1631. "running e2fsck is recommended");
  1632. else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
  1633. le16_to_cpu(es->s_mnt_count) >=
  1634. (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
  1635. ext4_msg(sb, KERN_WARNING,
  1636. "warning: maximal mount count reached, "
  1637. "running e2fsck is recommended");
  1638. else if (le32_to_cpu(es->s_checkinterval) &&
  1639. (le32_to_cpu(es->s_lastcheck) +
  1640. le32_to_cpu(es->s_checkinterval) <= get_seconds()))
  1641. ext4_msg(sb, KERN_WARNING,
  1642. "warning: checktime reached, "
  1643. "running e2fsck is recommended");
  1644. if (!sbi->s_journal)
  1645. es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
  1646. if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
  1647. es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
  1648. le16_add_cpu(&es->s_mnt_count, 1);
  1649. es->s_mtime = cpu_to_le32(get_seconds());
  1650. ext4_update_dynamic_rev(sb);
  1651. if (sbi->s_journal)
  1652. EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  1653. ext4_commit_super(sb, 1);
  1654. if (test_opt(sb, DEBUG))
  1655. printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
  1656. "bpg=%lu, ipg=%lu, mo=%04x]\n",
  1657. sb->s_blocksize,
  1658. sbi->s_groups_count,
  1659. EXT4_BLOCKS_PER_GROUP(sb),
  1660. EXT4_INODES_PER_GROUP(sb),
  1661. sbi->s_mount_opt);
  1662. return res;
  1663. }
  1664. static int ext4_fill_flex_info(struct super_block *sb)
  1665. {
  1666. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1667. struct ext4_group_desc *gdp = NULL;
  1668. ext4_group_t flex_group_count;
  1669. ext4_group_t flex_group;
  1670. int groups_per_flex = 0;
  1671. size_t size;
  1672. int i;
  1673. sbi->s_log_groups_per_flex = sbi->s_es->s_log_groups_per_flex;
  1674. groups_per_flex = 1 << sbi->s_log_groups_per_flex;
  1675. if (groups_per_flex < 2) {
  1676. sbi->s_log_groups_per_flex = 0;
  1677. return 1;
  1678. }
  1679. /* We allocate both existing and potentially added groups */
  1680. flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
  1681. ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
  1682. EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
  1683. size = flex_group_count * sizeof(struct flex_groups);
  1684. sbi->s_flex_groups = kzalloc(size, GFP_KERNEL);
  1685. if (sbi->s_flex_groups == NULL) {
  1686. sbi->s_flex_groups = vmalloc(size);
  1687. if (sbi->s_flex_groups)
  1688. memset(sbi->s_flex_groups, 0, size);
  1689. }
  1690. if (sbi->s_flex_groups == NULL) {
  1691. ext4_msg(sb, KERN_ERR, "not enough memory for "
  1692. "%u flex groups", flex_group_count);
  1693. goto failed;
  1694. }
  1695. for (i = 0; i < sbi->s_groups_count; i++) {
  1696. gdp = ext4_get_group_desc(sb, i, NULL);
  1697. flex_group = ext4_flex_group(sbi, i);
  1698. atomic_add(ext4_free_inodes_count(sb, gdp),
  1699. &sbi->s_flex_groups[flex_group].free_inodes);
  1700. atomic_add(ext4_free_blks_count(sb, gdp),
  1701. &sbi->s_flex_groups[flex_group].free_blocks);
  1702. atomic_add(ext4_used_dirs_count(sb, gdp),
  1703. &sbi->s_flex_groups[flex_group].used_dirs);
  1704. }
  1705. return 1;
  1706. failed:
  1707. return 0;
  1708. }
  1709. __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 block_group,
  1710. struct ext4_group_desc *gdp)
  1711. {
  1712. __u16 crc = 0;
  1713. if (sbi->s_es->s_feature_ro_compat &
  1714. cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
  1715. int offset = offsetof(struct ext4_group_desc, bg_checksum);
  1716. __le32 le_group = cpu_to_le32(block_group);
  1717. crc = crc16(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
  1718. crc = crc16(crc, (__u8 *)&le_group, sizeof(le_group));
  1719. crc = crc16(crc, (__u8 *)gdp, offset);
  1720. offset += sizeof(gdp->bg_checksum); /* skip checksum */
  1721. /* for checksum of struct ext4_group_desc do the rest...*/
  1722. if ((sbi->s_es->s_feature_incompat &
  1723. cpu_to_le32(EXT4_FEATURE_INCOMPAT_64BIT)) &&
  1724. offset < le16_to_cpu(sbi->s_es->s_desc_size))
  1725. crc = crc16(crc, (__u8 *)gdp + offset,
  1726. le16_to_cpu(sbi->s_es->s_desc_size) -
  1727. offset);
  1728. }
  1729. return cpu_to_le16(crc);
  1730. }
  1731. int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 block_group,
  1732. struct ext4_group_desc *gdp)
  1733. {
  1734. if ((sbi->s_es->s_feature_ro_compat &
  1735. cpu_to_le32(EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) &&
  1736. (gdp->bg_checksum != ext4_group_desc_csum(sbi, block_group, gdp)))
  1737. return 0;
  1738. return 1;
  1739. }
  1740. /* Called at mount-time, super-block is locked */
  1741. static int ext4_check_descriptors(struct super_block *sb)
  1742. {
  1743. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1744. ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
  1745. ext4_fsblk_t last_block;
  1746. ext4_fsblk_t block_bitmap;
  1747. ext4_fsblk_t inode_bitmap;
  1748. ext4_fsblk_t inode_table;
  1749. int flexbg_flag = 0;
  1750. ext4_group_t i;
  1751. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
  1752. flexbg_flag = 1;
  1753. ext4_debug("Checking group descriptors");
  1754. for (i = 0; i < sbi->s_groups_count; i++) {
  1755. struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
  1756. if (i == sbi->s_groups_count - 1 || flexbg_flag)
  1757. last_block = ext4_blocks_count(sbi->s_es) - 1;
  1758. else
  1759. last_block = first_block +
  1760. (EXT4_BLOCKS_PER_GROUP(sb) - 1);
  1761. block_bitmap = ext4_block_bitmap(sb, gdp);
  1762. if (block_bitmap < first_block || block_bitmap > last_block) {
  1763. ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
  1764. "Block bitmap for group %u not in group "
  1765. "(block %llu)!", i, block_bitmap);
  1766. return 0;
  1767. }
  1768. inode_bitmap = ext4_inode_bitmap(sb, gdp);
  1769. if (inode_bitmap < first_block || inode_bitmap > last_block) {
  1770. ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
  1771. "Inode bitmap for group %u not in group "
  1772. "(block %llu)!", i, inode_bitmap);
  1773. return 0;
  1774. }
  1775. inode_table = ext4_inode_table(sb, gdp);
  1776. if (inode_table < first_block ||
  1777. inode_table + sbi->s_itb_per_group - 1 > last_block) {
  1778. ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
  1779. "Inode table for group %u not in group "
  1780. "(block %llu)!", i, inode_table);
  1781. return 0;
  1782. }
  1783. ext4_lock_group(sb, i);
  1784. if (!ext4_group_desc_csum_verify(sbi, i, gdp)) {
  1785. ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
  1786. "Checksum for group %u failed (%u!=%u)",
  1787. i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
  1788. gdp)), le16_to_cpu(gdp->bg_checksum));
  1789. if (!(sb->s_flags & MS_RDONLY)) {
  1790. ext4_unlock_group(sb, i);
  1791. return 0;
  1792. }
  1793. }
  1794. ext4_unlock_group(sb, i);
  1795. if (!flexbg_flag)
  1796. first_block += EXT4_BLOCKS_PER_GROUP(sb);
  1797. }
  1798. ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
  1799. sbi->s_es->s_free_inodes_count =cpu_to_le32(ext4_count_free_inodes(sb));
  1800. return 1;
  1801. }
  1802. /* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at
  1803. * the superblock) which were deleted from all directories, but held open by
  1804. * a process at the time of a crash. We walk the list and try to delete these
  1805. * inodes at recovery time (only with a read-write filesystem).
  1806. *
  1807. * In order to keep the orphan inode chain consistent during traversal (in
  1808. * case of crash during recovery), we link each inode into the superblock
  1809. * orphan list_head and handle it the same way as an inode deletion during
  1810. * normal operation (which journals the operations for us).
  1811. *
  1812. * We only do an iget() and an iput() on each inode, which is very safe if we
  1813. * accidentally point at an in-use or already deleted inode. The worst that
  1814. * can happen in this case is that we get a "bit already cleared" message from
  1815. * ext4_free_inode(). The only reason we would point at a wrong inode is if
  1816. * e2fsck was run on this filesystem, and it must have already done the orphan
  1817. * inode cleanup for us, so we can safely abort without any further action.
  1818. */
  1819. static void ext4_orphan_cleanup(struct super_block *sb,
  1820. struct ext4_super_block *es)
  1821. {
  1822. unsigned int s_flags = sb->s_flags;
  1823. int nr_orphans = 0, nr_truncates = 0;
  1824. #ifdef CONFIG_QUOTA
  1825. int i;
  1826. #endif
  1827. if (!es->s_last_orphan) {
  1828. jbd_debug(4, "no orphan inodes to clean up\n");
  1829. return;
  1830. }
  1831. if (bdev_read_only(sb->s_bdev)) {
  1832. ext4_msg(sb, KERN_ERR, "write access "
  1833. "unavailable, skipping orphan cleanup");
  1834. return;
  1835. }
  1836. if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
  1837. if (es->s_last_orphan)
  1838. jbd_debug(1, "Errors on filesystem, "
  1839. "clearing orphan list.\n");
  1840. es->s_last_orphan = 0;
  1841. jbd_debug(1, "Skipping orphan recovery on fs with errors.\n");
  1842. return;
  1843. }
  1844. if (s_flags & MS_RDONLY) {
  1845. ext4_msg(sb, KERN_INFO, "orphan cleanup on readonly fs");
  1846. sb->s_flags &= ~MS_RDONLY;
  1847. }
  1848. #ifdef CONFIG_QUOTA
  1849. /* Needed for iput() to work correctly and not trash data */
  1850. sb->s_flags |= MS_ACTIVE;
  1851. /* Turn on quotas so that they are updated correctly */
  1852. for (i = 0; i < MAXQUOTAS; i++) {
  1853. if (EXT4_SB(sb)->s_qf_names[i]) {
  1854. int ret = ext4_quota_on_mount(sb, i);
  1855. if (ret < 0)
  1856. ext4_msg(sb, KERN_ERR,
  1857. "Cannot turn on journaled "
  1858. "quota: error %d", ret);
  1859. }
  1860. }
  1861. #endif
  1862. while (es->s_last_orphan) {
  1863. struct inode *inode;
  1864. inode = ext4_orphan_get(sb, le32_to_cpu(es->s_last_orphan));
  1865. if (IS_ERR(inode)) {
  1866. es->s_last_orphan = 0;
  1867. break;
  1868. }
  1869. list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
  1870. dquot_initialize(inode);
  1871. if (inode->i_nlink) {
  1872. ext4_msg(sb, KERN_DEBUG,
  1873. "%s: truncating inode %lu to %lld bytes",
  1874. __func__, inode->i_ino, inode->i_size);
  1875. jbd_debug(2, "truncating inode %lu to %lld bytes\n",
  1876. inode->i_ino, inode->i_size);
  1877. ext4_truncate(inode);
  1878. nr_truncates++;
  1879. } else {
  1880. ext4_msg(sb, KERN_DEBUG,
  1881. "%s: deleting unreferenced inode %lu",
  1882. __func__, inode->i_ino);
  1883. jbd_debug(2, "deleting unreferenced inode %lu\n",
  1884. inode->i_ino);
  1885. nr_orphans++;
  1886. }
  1887. iput(inode); /* The delete magic happens here! */
  1888. }
  1889. #define PLURAL(x) (x), ((x) == 1) ? "" : "s"
  1890. if (nr_orphans)
  1891. ext4_msg(sb, KERN_INFO, "%d orphan inode%s deleted",
  1892. PLURAL(nr_orphans));
  1893. if (nr_truncates)
  1894. ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
  1895. PLURAL(nr_truncates));
  1896. #ifdef CONFIG_QUOTA
  1897. /* Turn quotas off */
  1898. for (i = 0; i < MAXQUOTAS; i++) {
  1899. if (sb_dqopt(sb)->files[i])
  1900. dquot_quota_off(sb, i);
  1901. }
  1902. #endif
  1903. sb->s_flags = s_flags; /* Restore MS_RDONLY status */
  1904. }
  1905. /*
  1906. * Maximal extent format file size.
  1907. * Resulting logical blkno at s_maxbytes must fit in our on-disk
  1908. * extent format containers, within a sector_t, and within i_blocks
  1909. * in the vfs. ext4 inode has 48 bits of i_block in fsblock units,
  1910. * so that won't be a limiting factor.
  1911. *
  1912. * Note, this does *not* consider any metadata overhead for vfs i_blocks.
  1913. */
  1914. static loff_t ext4_max_size(int blkbits, int has_huge_files)
  1915. {
  1916. loff_t res;
  1917. loff_t upper_limit = MAX_LFS_FILESIZE;
  1918. /* small i_blocks in vfs inode? */
  1919. if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
  1920. /*
  1921. * CONFIG_LBDAF is not enabled implies the inode
  1922. * i_block represent total blocks in 512 bytes
  1923. * 32 == size of vfs inode i_blocks * 8
  1924. */
  1925. upper_limit = (1LL << 32) - 1;
  1926. /* total blocks in file system block size */
  1927. upper_limit >>= (blkbits - 9);
  1928. upper_limit <<= blkbits;
  1929. }
  1930. /* 32-bit extent-start container, ee_block */
  1931. res = 1LL << 32;
  1932. res <<= blkbits;
  1933. res -= 1;
  1934. /* Sanity check against vm- & vfs- imposed limits */
  1935. if (res > upper_limit)
  1936. res = upper_limit;
  1937. return res;
  1938. }
  1939. /*
  1940. * Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect
  1941. * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks.
  1942. * We need to be 1 filesystem block less than the 2^48 sector limit.
  1943. */
  1944. static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
  1945. {
  1946. loff_t res = EXT4_NDIR_BLOCKS;
  1947. int meta_blocks;
  1948. loff_t upper_limit;
  1949. /* This is calculated to be the largest file size for a dense, block
  1950. * mapped file such that the file's total number of 512-byte sectors,
  1951. * including data and all indirect blocks, does not exceed (2^48 - 1).
  1952. *
  1953. * __u32 i_blocks_lo and _u16 i_blocks_high represent the total
  1954. * number of 512-byte sectors of the file.
  1955. */
  1956. if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
  1957. /*
  1958. * !has_huge_files or CONFIG_LBDAF not enabled implies that
  1959. * the inode i_block field represents total file blocks in
  1960. * 2^32 512-byte sectors == size of vfs inode i_blocks * 8
  1961. */
  1962. upper_limit = (1LL << 32) - 1;
  1963. /* total blocks in file system block size */
  1964. upper_limit >>= (bits - 9);
  1965. } else {
  1966. /*
  1967. * We use 48 bit ext4_inode i_blocks
  1968. * With EXT4_HUGE_FILE_FL set the i_blocks
  1969. * represent total number of blocks in
  1970. * file system block size
  1971. */
  1972. upper_limit = (1LL << 48) - 1;
  1973. }
  1974. /* indirect blocks */
  1975. meta_blocks = 1;
  1976. /* double indirect blocks */
  1977. meta_blocks += 1 + (1LL << (bits-2));
  1978. /* tripple indirect blocks */
  1979. meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2)));
  1980. upper_limit -= meta_blocks;
  1981. upper_limit <<= bits;
  1982. res += 1LL << (bits-2);
  1983. res += 1LL << (2*(bits-2));
  1984. res += 1LL << (3*(bits-2));
  1985. res <<= bits;
  1986. if (res > upper_limit)
  1987. res = upper_limit;
  1988. if (res > MAX_LFS_FILESIZE)
  1989. res = MAX_LFS_FILESIZE;
  1990. return res;
  1991. }
  1992. static ext4_fsblk_t descriptor_loc(struct super_block *sb,
  1993. ext4_fsblk_t logical_sb_block, int nr)
  1994. {
  1995. struct ext4_sb_info *sbi = EXT4_SB(sb);
  1996. ext4_group_t bg, first_meta_bg;
  1997. int has_super = 0;
  1998. first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg);
  1999. if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_META_BG) ||
  2000. nr < first_meta_bg)
  2001. return logical_sb_block + nr + 1;
  2002. bg = sbi->s_desc_per_block * nr;
  2003. if (ext4_bg_has_super(sb, bg))
  2004. has_super = 1;
  2005. return (has_super + ext4_group_first_block_no(sb, bg));
  2006. }
  2007. /**
  2008. * ext4_get_stripe_size: Get the stripe size.
  2009. * @sbi: In memory super block info
  2010. *
  2011. * If we have specified it via mount option, then
  2012. * use the mount option value. If the value specified at mount time is
  2013. * greater than the blocks per group use the super block value.
  2014. * If the super block value is greater than blocks per group return 0.
  2015. * Allocator needs it be less than blocks per group.
  2016. *
  2017. */
  2018. static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi)
  2019. {
  2020. unsigned long stride = le16_to_cpu(sbi->s_es->s_raid_stride);
  2021. unsigned long stripe_width =
  2022. le32_to_cpu(sbi->s_es->s_raid_stripe_width);
  2023. if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group)
  2024. return sbi->s_stripe;
  2025. if (stripe_width <= sbi->s_blocks_per_group)
  2026. return stripe_width;
  2027. if (stride <= sbi->s_blocks_per_group)
  2028. return stride;
  2029. return 0;
  2030. }
  2031. /* sysfs supprt */
  2032. struct ext4_attr {
  2033. struct attribute attr;
  2034. ssize_t (*show)(struct ext4_attr *, struct ext4_sb_info *, char *);
  2035. ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
  2036. const char *, size_t);
  2037. int offset;
  2038. };
  2039. static int parse_strtoul(const char *buf,
  2040. unsigned long max, unsigned long *value)
  2041. {
  2042. char *endp;
  2043. *value = simple_strtoul(skip_spaces(buf), &endp, 0);
  2044. endp = skip_spaces(endp);
  2045. if (*endp || *value > max)
  2046. return -EINVAL;
  2047. return 0;
  2048. }
  2049. static ssize_t delayed_allocation_blocks_show(struct ext4_attr *a,
  2050. struct ext4_sb_info *sbi,
  2051. char *buf)
  2052. {
  2053. return snprintf(buf, PAGE_SIZE, "%llu\n",
  2054. (s64) percpu_counter_sum(&sbi->s_dirtyblocks_counter));
  2055. }
  2056. static ssize_t session_write_kbytes_show(struct ext4_attr *a,
  2057. struct ext4_sb_info *sbi, char *buf)
  2058. {
  2059. struct super_block *sb = sbi->s_buddy_cache->i_sb;
  2060. return snprintf(buf, PAGE_SIZE, "%lu\n",
  2061. (part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
  2062. sbi->s_sectors_written_start) >> 1);
  2063. }
  2064. static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
  2065. struct ext4_sb_info *sbi, char *buf)
  2066. {
  2067. struct super_block *sb = sbi->s_buddy_cache->i_sb;
  2068. return snprintf(buf, PAGE_SIZE, "%llu\n",
  2069. (unsigned long long)(sbi->s_kbytes_written +
  2070. ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
  2071. EXT4_SB(sb)->s_sectors_written_start) >> 1)));
  2072. }
  2073. static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
  2074. struct ext4_sb_info *sbi,
  2075. const char *buf, size_t count)
  2076. {
  2077. unsigned long t;
  2078. if (parse_strtoul(buf, 0x40000000, &t))
  2079. return -EINVAL;
  2080. if (!is_power_of_2(t))
  2081. return -EINVAL;
  2082. sbi->s_inode_readahead_blks = t;
  2083. return count;
  2084. }
  2085. static ssize_t sbi_ui_show(struct ext4_attr *a,
  2086. struct ext4_sb_info *sbi, char *buf)
  2087. {
  2088. unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
  2089. return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
  2090. }
  2091. static ssize_t sbi_ui_store(struct ext4_attr *a,
  2092. struct ext4_sb_info *sbi,
  2093. const char *buf, size_t count)
  2094. {
  2095. unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
  2096. unsigned long t;
  2097. if (parse_strtoul(buf, 0xffffffff, &t))
  2098. return -EINVAL;
  2099. *ui = t;
  2100. return count;
  2101. }
  2102. #define EXT4_ATTR_OFFSET(_name,_mode,_show,_store,_elname) \
  2103. static struct ext4_attr ext4_attr_##_name = { \
  2104. .attr = {.name = __stringify(_name), .mode = _mode }, \
  2105. .show = _show, \
  2106. .store = _store, \
  2107. .offset = offsetof(struct ext4_sb_info, _elname), \
  2108. }
  2109. #define EXT4_ATTR(name, mode, show, store) \
  2110. static struct ext4_attr ext4_attr_##name = __ATTR(name, mode, show, store)
  2111. #define EXT4_RO_ATTR(name) EXT4_ATTR(name, 0444, name##_show, NULL)
  2112. #define EXT4_RW_ATTR(name) EXT4_ATTR(name, 0644, name##_show, name##_store)
  2113. #define EXT4_RW_ATTR_SBI_UI(name, elname) \
  2114. EXT4_ATTR_OFFSET(name, 0644, sbi_ui_show, sbi_ui_store, elname)
  2115. #define ATTR_LIST(name) &ext4_attr_##name.attr
  2116. EXT4_RO_ATTR(delayed_allocation_blocks);
  2117. EXT4_RO_ATTR(session_write_kbytes);
  2118. EXT4_RO_ATTR(lifetime_write_kbytes);
  2119. EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, sbi_ui_show,
  2120. inode_readahead_blks_store, s_inode_readahead_blks);
  2121. EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
  2122. EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
  2123. EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
  2124. EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
  2125. EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
  2126. EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
  2127. EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
  2128. EXT4_RW_ATTR_SBI_UI(max_writeback_mb_bump, s_max_writeback_mb_bump);
  2129. static struct attribute *ext4_attrs[] = {
  2130. ATTR_LIST(delayed_allocation_blocks),
  2131. ATTR_LIST(session_write_kbytes),
  2132. ATTR_LIST(lifetime_write_kbytes),
  2133. ATTR_LIST(inode_readahead_blks),
  2134. ATTR_LIST(inode_goal),
  2135. ATTR_LIST(mb_stats),
  2136. ATTR_LIST(mb_max_to_scan),
  2137. ATTR_LIST(mb_min_to_scan),
  2138. ATTR_LIST(mb_order2_req),
  2139. ATTR_LIST(mb_stream_req),
  2140. ATTR_LIST(mb_group_prealloc),
  2141. ATTR_LIST(max_writeback_mb_bump),
  2142. NULL,
  2143. };
  2144. static ssize_t ext4_attr_show(struct kobject *kobj,
  2145. struct attribute *attr, char *buf)
  2146. {
  2147. struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
  2148. s_kobj);
  2149. struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
  2150. return a->show ? a->show(a, sbi, buf) : 0;
  2151. }
  2152. static ssize_t ext4_attr_store(struct kobject *kobj,
  2153. struct attribute *attr,
  2154. const char *buf, size_t len)
  2155. {
  2156. struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
  2157. s_kobj);
  2158. struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
  2159. return a->store ? a->store(a, sbi, buf, len) : 0;
  2160. }
  2161. static void ext4_sb_release(struct kobject *kobj)
  2162. {
  2163. struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
  2164. s_kobj);
  2165. complete(&sbi->s_kobj_unregister);
  2166. }
  2167. static const struct sysfs_ops ext4_attr_ops = {
  2168. .show = ext4_attr_show,
  2169. .store = ext4_attr_store,
  2170. };
  2171. static struct kobj_type ext4_ktype = {
  2172. .default_attrs = ext4_attrs,
  2173. .sysfs_ops = &ext4_attr_ops,
  2174. .release = ext4_sb_release,
  2175. };
  2176. /*
  2177. * Check whether this filesystem can be mounted based on
  2178. * the features present and the RDONLY/RDWR mount requested.
  2179. * Returns 1 if this filesystem can be mounted as requested,
  2180. * 0 if it cannot be.
  2181. */
  2182. static int ext4_feature_set_ok(struct super_block *sb, int readonly)
  2183. {
  2184. if (EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP)) {
  2185. ext4_msg(sb, KERN_ERR,
  2186. "Couldn't mount because of "
  2187. "unsupported optional features (%x)",
  2188. (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
  2189. ~EXT4_FEATURE_INCOMPAT_SUPP));
  2190. return 0;
  2191. }
  2192. if (readonly)
  2193. return 1;
  2194. /* Check that feature set is OK for a read-write mount */
  2195. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP)) {
  2196. ext4_msg(sb, KERN_ERR, "couldn't mount RDWR because of "
  2197. "unsupported optional features (%x)",
  2198. (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
  2199. ~EXT4_FEATURE_RO_COMPAT_SUPP));
  2200. return 0;
  2201. }
  2202. /*
  2203. * Large file size enabled file system can only be mounted
  2204. * read-write on 32-bit systems if kernel is built with CONFIG_LBDAF
  2205. */
  2206. if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
  2207. if (sizeof(blkcnt_t) < sizeof(u64)) {
  2208. ext4_msg(sb, KERN_ERR, "Filesystem with huge files "
  2209. "cannot be mounted RDWR without "
  2210. "CONFIG_LBDAF");
  2211. return 0;
  2212. }
  2213. }
  2214. return 1;
  2215. }
  2216. static int ext4_fill_super(struct super_block *sb, void *data, int silent)
  2217. __releases(kernel_lock)
  2218. __acquires(kernel_lock)
  2219. {
  2220. char *orig_data = kstrdup(data, GFP_KERNEL);
  2221. struct buffer_head *bh;
  2222. struct ext4_super_block *es = NULL;
  2223. struct ext4_sb_info *sbi;
  2224. ext4_fsblk_t block;
  2225. ext4_fsblk_t sb_block = get_sb_block(&data);
  2226. ext4_fsblk_t logical_sb_block;
  2227. unsigned long offset = 0;
  2228. unsigned long journal_devnum = 0;
  2229. unsigned long def_mount_opts;
  2230. struct inode *root;
  2231. char *cp;
  2232. const char *descr;
  2233. int ret = -EINVAL;
  2234. int blocksize;
  2235. unsigned int db_count;
  2236. unsigned int i;
  2237. int needs_recovery, has_huge_files;
  2238. __u64 blocks_count;
  2239. int err;
  2240. unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
  2241. sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
  2242. if (!sbi)
  2243. return -ENOMEM;
  2244. sbi->s_blockgroup_lock =
  2245. kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
  2246. if (!sbi->s_blockgroup_lock) {
  2247. kfree(sbi);
  2248. return -ENOMEM;
  2249. }
  2250. sb->s_fs_info = sbi;
  2251. sbi->s_mount_opt = 0;
  2252. sbi->s_resuid = EXT4_DEF_RESUID;
  2253. sbi->s_resgid = EXT4_DEF_RESGID;
  2254. sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
  2255. sbi->s_sb_block = sb_block;
  2256. sbi->s_sectors_written_start = part_stat_read(sb->s_bdev->bd_part,
  2257. sectors[1]);
  2258. unlock_kernel();
  2259. /* Cleanup superblock name */
  2260. for (cp = sb->s_id; (cp = strchr(cp, '/'));)
  2261. *cp = '!';
  2262. blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
  2263. if (!blocksize) {
  2264. ext4_msg(sb, KERN_ERR, "unable to set blocksize");
  2265. goto out_fail;
  2266. }
  2267. /*
  2268. * The ext4 superblock will not be buffer aligned for other than 1kB
  2269. * block sizes. We need to calculate the offset from buffer start.
  2270. */
  2271. if (blocksize != EXT4_MIN_BLOCK_SIZE) {
  2272. logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
  2273. offset = do_div(logical_sb_block, blocksize);
  2274. } else {
  2275. logical_sb_block = sb_block;
  2276. }
  2277. if (!(bh = sb_bread(sb, logical_sb_block))) {
  2278. ext4_msg(sb, KERN_ERR, "unable to read superblock");
  2279. goto out_fail;
  2280. }
  2281. /*
  2282. * Note: s_es must be initialized as soon as possible because
  2283. * some ext4 macro-instructions depend on its value
  2284. */
  2285. es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
  2286. sbi->s_es = es;
  2287. sb->s_magic = le16_to_cpu(es->s_magic);
  2288. if (sb->s_magic != EXT4_SUPER_MAGIC)
  2289. goto cantfind_ext4;
  2290. sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);
  2291. /* Set defaults before we parse the mount options */
  2292. def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
  2293. if (def_mount_opts & EXT4_DEFM_DEBUG)
  2294. set_opt(sbi->s_mount_opt, DEBUG);
  2295. if (def_mount_opts & EXT4_DEFM_BSDGROUPS) {
  2296. ext4_msg(sb, KERN_WARNING, deprecated_msg, "bsdgroups",
  2297. "2.6.38");
  2298. set_opt(sbi->s_mount_opt, GRPID);
  2299. }
  2300. if (def_mount_opts & EXT4_DEFM_UID16)
  2301. set_opt(sbi->s_mount_opt, NO_UID32);
  2302. #ifdef CONFIG_EXT4_FS_XATTR
  2303. if (def_mount_opts & EXT4_DEFM_XATTR_USER)
  2304. set_opt(sbi->s_mount_opt, XATTR_USER);
  2305. #endif
  2306. #ifdef CONFIG_EXT4_FS_POSIX_ACL
  2307. if (def_mount_opts & EXT4_DEFM_ACL)
  2308. set_opt(sbi->s_mount_opt, POSIX_ACL);
  2309. #endif
  2310. if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_DATA)
  2311. set_opt(sbi->s_mount_opt, JOURNAL_DATA);
  2312. else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_ORDERED)
  2313. set_opt(sbi->s_mount_opt, ORDERED_DATA);
  2314. else if ((def_mount_opts & EXT4_DEFM_JMODE) == EXT4_DEFM_JMODE_WBACK)
  2315. set_opt(sbi->s_mount_opt, WRITEBACK_DATA);
  2316. if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_PANIC)
  2317. set_opt(sbi->s_mount_opt, ERRORS_PANIC);
  2318. else if (le16_to_cpu(sbi->s_es->s_errors) == EXT4_ERRORS_CONTINUE)
  2319. set_opt(sbi->s_mount_opt, ERRORS_CONT);
  2320. else
  2321. set_opt(sbi->s_mount_opt, ERRORS_RO);
  2322. sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
  2323. sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
  2324. sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
  2325. sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
  2326. sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
  2327. set_opt(sbi->s_mount_opt, BARRIER);
  2328. /*
  2329. * enable delayed allocation by default
  2330. * Use -o nodelalloc to turn it off
  2331. */
  2332. if (!IS_EXT3_SB(sb))
  2333. set_opt(sbi->s_mount_opt, DELALLOC);
  2334. if (!parse_options((char *) data, sb, &journal_devnum,
  2335. &journal_ioprio, NULL, 0))
  2336. goto failed_mount;
  2337. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  2338. (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
  2339. if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV &&
  2340. (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
  2341. EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
  2342. EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
  2343. ext4_msg(sb, KERN_WARNING,
  2344. "feature flags set on rev 0 fs, "
  2345. "running e2fsck is recommended");
  2346. /*
  2347. * Check feature flags regardless of the revision level, since we
  2348. * previously didn't change the revision level when setting the flags,
  2349. * so there is a chance incompat flags are set on a rev 0 filesystem.
  2350. */
  2351. if (!ext4_feature_set_ok(sb, (sb->s_flags & MS_RDONLY)))
  2352. goto failed_mount;
  2353. blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
  2354. if (blocksize < EXT4_MIN_BLOCK_SIZE ||
  2355. blocksize > EXT4_MAX_BLOCK_SIZE) {
  2356. ext4_msg(sb, KERN_ERR,
  2357. "Unsupported filesystem blocksize %d", blocksize);
  2358. goto failed_mount;
  2359. }
  2360. if (sb->s_blocksize != blocksize) {
  2361. /* Validate the filesystem blocksize */
  2362. if (!sb_set_blocksize(sb, blocksize)) {
  2363. ext4_msg(sb, KERN_ERR, "bad block size %d",
  2364. blocksize);
  2365. goto failed_mount;
  2366. }
  2367. brelse(bh);
  2368. logical_sb_block = sb_block * EXT4_MIN_BLOCK_SIZE;
  2369. offset = do_div(logical_sb_block, blocksize);
  2370. bh = sb_bread(sb, logical_sb_block);
  2371. if (!bh) {
  2372. ext4_msg(sb, KERN_ERR,
  2373. "Can't read superblock on 2nd try");
  2374. goto failed_mount;
  2375. }
  2376. es = (struct ext4_super_block *)(((char *)bh->b_data) + offset);
  2377. sbi->s_es = es;
  2378. if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
  2379. ext4_msg(sb, KERN_ERR,
  2380. "Magic mismatch, very weird!");
  2381. goto failed_mount;
  2382. }
  2383. }
  2384. has_huge_files = EXT4_HAS_RO_COMPAT_FEATURE(sb,
  2385. EXT4_FEATURE_RO_COMPAT_HUGE_FILE);
  2386. sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits,
  2387. has_huge_files);
  2388. sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files);
  2389. if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV) {
  2390. sbi->s_inode_size = EXT4_GOOD_OLD_INODE_SIZE;
  2391. sbi->s_first_ino = EXT4_GOOD_OLD_FIRST_INO;
  2392. } else {
  2393. sbi->s_inode_size = le16_to_cpu(es->s_inode_size);
  2394. sbi->s_first_ino = le32_to_cpu(es->s_first_ino);
  2395. if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
  2396. (!is_power_of_2(sbi->s_inode_size)) ||
  2397. (sbi->s_inode_size > blocksize)) {
  2398. ext4_msg(sb, KERN_ERR,
  2399. "unsupported inode size: %d",
  2400. sbi->s_inode_size);
  2401. goto failed_mount;
  2402. }
  2403. if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
  2404. sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
  2405. }
  2406. sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
  2407. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) {
  2408. if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
  2409. sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
  2410. !is_power_of_2(sbi->s_desc_size)) {
  2411. ext4_msg(sb, KERN_ERR,
  2412. "unsupported descriptor size %lu",
  2413. sbi->s_desc_size);
  2414. goto failed_mount;
  2415. }
  2416. } else
  2417. sbi->s_desc_size = EXT4_MIN_DESC_SIZE;
  2418. sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
  2419. sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
  2420. if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
  2421. goto cantfind_ext4;
  2422. sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
  2423. if (sbi->s_inodes_per_block == 0)
  2424. goto cantfind_ext4;
  2425. sbi->s_itb_per_group = sbi->s_inodes_per_group /
  2426. sbi->s_inodes_per_block;
  2427. sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
  2428. sbi->s_sbh = bh;
  2429. sbi->s_mount_state = le16_to_cpu(es->s_state);
  2430. sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
  2431. sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
  2432. for (i = 0; i < 4; i++)
  2433. sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
  2434. sbi->s_def_hash_version = es->s_def_hash_version;
  2435. i = le32_to_cpu(es->s_flags);
  2436. if (i & EXT2_FLAGS_UNSIGNED_HASH)
  2437. sbi->s_hash_unsigned = 3;
  2438. else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) {
  2439. #ifdef __CHAR_UNSIGNED__
  2440. es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH);
  2441. sbi->s_hash_unsigned = 3;
  2442. #else
  2443. es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
  2444. #endif
  2445. sb->s_dirt = 1;
  2446. }
  2447. if (sbi->s_blocks_per_group > blocksize * 8) {
  2448. ext4_msg(sb, KERN_ERR,
  2449. "#blocks per group too big: %lu",
  2450. sbi->s_blocks_per_group);
  2451. goto failed_mount;
  2452. }
  2453. if (sbi->s_inodes_per_group > blocksize * 8) {
  2454. ext4_msg(sb, KERN_ERR,
  2455. "#inodes per group too big: %lu",
  2456. sbi->s_inodes_per_group);
  2457. goto failed_mount;
  2458. }
  2459. /*
  2460. * Test whether we have more sectors than will fit in sector_t,
  2461. * and whether the max offset is addressable by the page cache.
  2462. */
  2463. if ((ext4_blocks_count(es) >
  2464. (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) ||
  2465. (ext4_blocks_count(es) >
  2466. (pgoff_t)(~0ULL) >> (PAGE_CACHE_SHIFT - sb->s_blocksize_bits))) {
  2467. ext4_msg(sb, KERN_ERR, "filesystem"
  2468. " too large to mount safely on this system");
  2469. if (sizeof(sector_t) < 8)
  2470. ext4_msg(sb, KERN_WARNING, "CONFIG_LBDAF not enabled");
  2471. ret = -EFBIG;
  2472. goto failed_mount;
  2473. }
  2474. if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
  2475. goto cantfind_ext4;
  2476. /* check blocks count against device size */
  2477. blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
  2478. if (blocks_count && ext4_blocks_count(es) > blocks_count) {
  2479. ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
  2480. "exceeds size of device (%llu blocks)",
  2481. ext4_blocks_count(es), blocks_count);
  2482. goto failed_mount;
  2483. }
  2484. /*
  2485. * It makes no sense for the first data block to be beyond the end
  2486. * of the filesystem.
  2487. */
  2488. if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) {
  2489. ext4_msg(sb, KERN_WARNING, "bad geometry: first data"
  2490. "block %u is beyond end of filesystem (%llu)",
  2491. le32_to_cpu(es->s_first_data_block),
  2492. ext4_blocks_count(es));
  2493. goto failed_mount;
  2494. }
  2495. blocks_count = (ext4_blocks_count(es) -
  2496. le32_to_cpu(es->s_first_data_block) +
  2497. EXT4_BLOCKS_PER_GROUP(sb) - 1);
  2498. do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
  2499. if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {
  2500. ext4_msg(sb, KERN_WARNING, "groups count too large: %u "
  2501. "(block count %llu, first data block %u, "
  2502. "blocks per group %lu)", sbi->s_groups_count,
  2503. ext4_blocks_count(es),
  2504. le32_to_cpu(es->s_first_data_block),
  2505. EXT4_BLOCKS_PER_GROUP(sb));
  2506. goto failed_mount;
  2507. }
  2508. sbi->s_groups_count = blocks_count;
  2509. sbi->s_blockfile_groups = min_t(ext4_group_t, sbi->s_groups_count,
  2510. (EXT4_MAX_BLOCK_FILE_PHYS / EXT4_BLOCKS_PER_GROUP(sb)));
  2511. db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
  2512. EXT4_DESC_PER_BLOCK(sb);
  2513. sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *),
  2514. GFP_KERNEL);
  2515. if (sbi->s_group_desc == NULL) {
  2516. ext4_msg(sb, KERN_ERR, "not enough memory");
  2517. goto failed_mount;
  2518. }
  2519. #ifdef CONFIG_PROC_FS
  2520. if (ext4_proc_root)
  2521. sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
  2522. #endif
  2523. bgl_lock_init(sbi->s_blockgroup_lock);
  2524. for (i = 0; i < db_count; i++) {
  2525. block = descriptor_loc(sb, logical_sb_block, i);
  2526. sbi->s_group_desc[i] = sb_bread(sb, block);
  2527. if (!sbi->s_group_desc[i]) {
  2528. ext4_msg(sb, KERN_ERR,
  2529. "can't read group descriptor %d", i);
  2530. db_count = i;
  2531. goto failed_mount2;
  2532. }
  2533. }
  2534. if (!ext4_check_descriptors(sb)) {
  2535. ext4_msg(sb, KERN_ERR, "group descriptors corrupted!");
  2536. goto failed_mount2;
  2537. }
  2538. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
  2539. if (!ext4_fill_flex_info(sb)) {
  2540. ext4_msg(sb, KERN_ERR,
  2541. "unable to initialize "
  2542. "flex_bg meta info!");
  2543. goto failed_mount2;
  2544. }
  2545. sbi->s_gdb_count = db_count;
  2546. get_random_bytes(&sbi->s_next_generation, sizeof(u32));
  2547. spin_lock_init(&sbi->s_next_gen_lock);
  2548. sbi->s_stripe = ext4_get_stripe_size(sbi);
  2549. sbi->s_max_writeback_mb_bump = 128;
  2550. /*
  2551. * set up enough so that it can read an inode
  2552. */
  2553. if (!test_opt(sb, NOLOAD) &&
  2554. EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL))
  2555. sb->s_op = &ext4_sops;
  2556. else
  2557. sb->s_op = &ext4_nojournal_sops;
  2558. sb->s_export_op = &ext4_export_ops;
  2559. sb->s_xattr = ext4_xattr_handlers;
  2560. #ifdef CONFIG_QUOTA
  2561. sb->s_qcop = &ext4_qctl_operations;
  2562. sb->dq_op = &ext4_quota_operations;
  2563. #endif
  2564. INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
  2565. mutex_init(&sbi->s_orphan_lock);
  2566. mutex_init(&sbi->s_resize_lock);
  2567. sb->s_root = NULL;
  2568. needs_recovery = (es->s_last_orphan != 0 ||
  2569. EXT4_HAS_INCOMPAT_FEATURE(sb,
  2570. EXT4_FEATURE_INCOMPAT_RECOVER));
  2571. /*
  2572. * The first inode we look at is the journal inode. Don't try
  2573. * root first: it may be modified in the journal!
  2574. */
  2575. if (!test_opt(sb, NOLOAD) &&
  2576. EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
  2577. if (ext4_load_journal(sb, es, journal_devnum))
  2578. goto failed_mount3;
  2579. } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&
  2580. EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
  2581. ext4_msg(sb, KERN_ERR, "required journal recovery "
  2582. "suppressed and not mounted read-only");
  2583. goto failed_mount_wq;
  2584. } else {
  2585. clear_opt(sbi->s_mount_opt, DATA_FLAGS);
  2586. set_opt(sbi->s_mount_opt, WRITEBACK_DATA);
  2587. sbi->s_journal = NULL;
  2588. needs_recovery = 0;
  2589. goto no_journal;
  2590. }
  2591. if (ext4_blocks_count(es) > 0xffffffffULL &&
  2592. !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
  2593. JBD2_FEATURE_INCOMPAT_64BIT)) {
  2594. ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature");
  2595. goto failed_mount_wq;
  2596. }
  2597. if (test_opt(sb, JOURNAL_ASYNC_COMMIT)) {
  2598. jbd2_journal_set_features(sbi->s_journal,
  2599. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2600. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2601. } else if (test_opt(sb, JOURNAL_CHECKSUM)) {
  2602. jbd2_journal_set_features(sbi->s_journal,
  2603. JBD2_FEATURE_COMPAT_CHECKSUM, 0, 0);
  2604. jbd2_journal_clear_features(sbi->s_journal, 0, 0,
  2605. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2606. } else {
  2607. jbd2_journal_clear_features(sbi->s_journal,
  2608. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2609. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2610. }
  2611. /* We have now updated the journal if required, so we can
  2612. * validate the data journaling mode. */
  2613. switch (test_opt(sb, DATA_FLAGS)) {
  2614. case 0:
  2615. /* No mode set, assume a default based on the journal
  2616. * capabilities: ORDERED_DATA if the journal can
  2617. * cope, else JOURNAL_DATA
  2618. */
  2619. if (jbd2_journal_check_available_features
  2620. (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE))
  2621. set_opt(sbi->s_mount_opt, ORDERED_DATA);
  2622. else
  2623. set_opt(sbi->s_mount_opt, JOURNAL_DATA);
  2624. break;
  2625. case EXT4_MOUNT_ORDERED_DATA:
  2626. case EXT4_MOUNT_WRITEBACK_DATA:
  2627. if (!jbd2_journal_check_available_features
  2628. (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
  2629. ext4_msg(sb, KERN_ERR, "Journal does not support "
  2630. "requested data journaling mode");
  2631. goto failed_mount_wq;
  2632. }
  2633. default:
  2634. break;
  2635. }
  2636. set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
  2637. no_journal:
  2638. err = percpu_counter_init(&sbi->s_freeblocks_counter,
  2639. ext4_count_free_blocks(sb));
  2640. if (!err)
  2641. err = percpu_counter_init(&sbi->s_freeinodes_counter,
  2642. ext4_count_free_inodes(sb));
  2643. if (!err)
  2644. err = percpu_counter_init(&sbi->s_dirs_counter,
  2645. ext4_count_dirs(sb));
  2646. if (!err)
  2647. err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
  2648. if (err) {
  2649. ext4_msg(sb, KERN_ERR, "insufficient memory");
  2650. goto failed_mount_wq;
  2651. }
  2652. EXT4_SB(sb)->dio_unwritten_wq = create_workqueue("ext4-dio-unwritten");
  2653. if (!EXT4_SB(sb)->dio_unwritten_wq) {
  2654. printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n");
  2655. goto failed_mount_wq;
  2656. }
  2657. /*
  2658. * The jbd2_journal_load will have done any necessary log recovery,
  2659. * so we can safely mount the rest of the filesystem now.
  2660. */
  2661. root = ext4_iget(sb, EXT4_ROOT_INO);
  2662. if (IS_ERR(root)) {
  2663. ext4_msg(sb, KERN_ERR, "get root inode failed");
  2664. ret = PTR_ERR(root);
  2665. goto failed_mount4;
  2666. }
  2667. if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
  2668. iput(root);
  2669. ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck");
  2670. goto failed_mount4;
  2671. }
  2672. sb->s_root = d_alloc_root(root);
  2673. if (!sb->s_root) {
  2674. ext4_msg(sb, KERN_ERR, "get root dentry failed");
  2675. iput(root);
  2676. ret = -ENOMEM;
  2677. goto failed_mount4;
  2678. }
  2679. ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY);
  2680. /* determine the minimum size of new large inodes, if present */
  2681. if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) {
  2682. sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
  2683. EXT4_GOOD_OLD_INODE_SIZE;
  2684. if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
  2685. EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) {
  2686. if (sbi->s_want_extra_isize <
  2687. le16_to_cpu(es->s_want_extra_isize))
  2688. sbi->s_want_extra_isize =
  2689. le16_to_cpu(es->s_want_extra_isize);
  2690. if (sbi->s_want_extra_isize <
  2691. le16_to_cpu(es->s_min_extra_isize))
  2692. sbi->s_want_extra_isize =
  2693. le16_to_cpu(es->s_min_extra_isize);
  2694. }
  2695. }
  2696. /* Check if enough inode space is available */
  2697. if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize >
  2698. sbi->s_inode_size) {
  2699. sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
  2700. EXT4_GOOD_OLD_INODE_SIZE;
  2701. ext4_msg(sb, KERN_INFO, "required extra inode space not"
  2702. "available");
  2703. }
  2704. if (test_opt(sb, DELALLOC) &&
  2705. (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)) {
  2706. ext4_msg(sb, KERN_WARNING, "Ignoring delalloc option - "
  2707. "requested data journaling mode");
  2708. clear_opt(sbi->s_mount_opt, DELALLOC);
  2709. }
  2710. if (test_opt(sb, DIOREAD_NOLOCK)) {
  2711. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
  2712. ext4_msg(sb, KERN_WARNING, "Ignoring dioread_nolock "
  2713. "option - requested data journaling mode");
  2714. clear_opt(sbi->s_mount_opt, DIOREAD_NOLOCK);
  2715. }
  2716. if (sb->s_blocksize < PAGE_SIZE) {
  2717. ext4_msg(sb, KERN_WARNING, "Ignoring dioread_nolock "
  2718. "option - block size is too small");
  2719. clear_opt(sbi->s_mount_opt, DIOREAD_NOLOCK);
  2720. }
  2721. }
  2722. err = ext4_setup_system_zone(sb);
  2723. if (err) {
  2724. ext4_msg(sb, KERN_ERR, "failed to initialize system "
  2725. "zone (%d)", err);
  2726. goto failed_mount4;
  2727. }
  2728. ext4_ext_init(sb);
  2729. err = ext4_mb_init(sb, needs_recovery);
  2730. if (err) {
  2731. ext4_msg(sb, KERN_ERR, "failed to initalize mballoc (%d)",
  2732. err);
  2733. goto failed_mount4;
  2734. }
  2735. sbi->s_kobj.kset = ext4_kset;
  2736. init_completion(&sbi->s_kobj_unregister);
  2737. err = kobject_init_and_add(&sbi->s_kobj, &ext4_ktype, NULL,
  2738. "%s", sb->s_id);
  2739. if (err) {
  2740. ext4_mb_release(sb);
  2741. ext4_ext_release(sb);
  2742. goto failed_mount4;
  2743. };
  2744. EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
  2745. ext4_orphan_cleanup(sb, es);
  2746. EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
  2747. if (needs_recovery) {
  2748. ext4_msg(sb, KERN_INFO, "recovery complete");
  2749. ext4_mark_recovery_complete(sb, es);
  2750. }
  2751. if (EXT4_SB(sb)->s_journal) {
  2752. if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
  2753. descr = " journalled data mode";
  2754. else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
  2755. descr = " ordered data mode";
  2756. else
  2757. descr = " writeback data mode";
  2758. } else
  2759. descr = "out journal";
  2760. ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. "
  2761. "Opts: %s", descr, orig_data);
  2762. lock_kernel();
  2763. kfree(orig_data);
  2764. return 0;
  2765. cantfind_ext4:
  2766. if (!silent)
  2767. ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
  2768. goto failed_mount;
  2769. failed_mount4:
  2770. ext4_msg(sb, KERN_ERR, "mount failed");
  2771. destroy_workqueue(EXT4_SB(sb)->dio_unwritten_wq);
  2772. failed_mount_wq:
  2773. ext4_release_system_zone(sb);
  2774. if (sbi->s_journal) {
  2775. jbd2_journal_destroy(sbi->s_journal);
  2776. sbi->s_journal = NULL;
  2777. }
  2778. percpu_counter_destroy(&sbi->s_freeblocks_counter);
  2779. percpu_counter_destroy(&sbi->s_freeinodes_counter);
  2780. percpu_counter_destroy(&sbi->s_dirs_counter);
  2781. percpu_counter_destroy(&sbi->s_dirtyblocks_counter);
  2782. failed_mount3:
  2783. if (sbi->s_flex_groups) {
  2784. if (is_vmalloc_addr(sbi->s_flex_groups))
  2785. vfree(sbi->s_flex_groups);
  2786. else
  2787. kfree(sbi->s_flex_groups);
  2788. }
  2789. failed_mount2:
  2790. for (i = 0; i < db_count; i++)
  2791. brelse(sbi->s_group_desc[i]);
  2792. kfree(sbi->s_group_desc);
  2793. failed_mount:
  2794. if (sbi->s_proc) {
  2795. remove_proc_entry(sb->s_id, ext4_proc_root);
  2796. }
  2797. #ifdef CONFIG_QUOTA
  2798. for (i = 0; i < MAXQUOTAS; i++)
  2799. kfree(sbi->s_qf_names[i]);
  2800. #endif
  2801. ext4_blkdev_remove(sbi);
  2802. brelse(bh);
  2803. out_fail:
  2804. sb->s_fs_info = NULL;
  2805. kfree(sbi->s_blockgroup_lock);
  2806. kfree(sbi);
  2807. lock_kernel();
  2808. kfree(orig_data);
  2809. return ret;
  2810. }
  2811. /*
  2812. * Setup any per-fs journal parameters now. We'll do this both on
  2813. * initial mount, once the journal has been initialised but before we've
  2814. * done any recovery; and again on any subsequent remount.
  2815. */
  2816. static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
  2817. {
  2818. struct ext4_sb_info *sbi = EXT4_SB(sb);
  2819. journal->j_commit_interval = sbi->s_commit_interval;
  2820. journal->j_min_batch_time = sbi->s_min_batch_time;
  2821. journal->j_max_batch_time = sbi->s_max_batch_time;
  2822. spin_lock(&journal->j_state_lock);
  2823. if (test_opt(sb, BARRIER))
  2824. journal->j_flags |= JBD2_BARRIER;
  2825. else
  2826. journal->j_flags &= ~JBD2_BARRIER;
  2827. if (test_opt(sb, DATA_ERR_ABORT))
  2828. journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
  2829. else
  2830. journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
  2831. spin_unlock(&journal->j_state_lock);
  2832. }
  2833. static journal_t *ext4_get_journal(struct super_block *sb,
  2834. unsigned int journal_inum)
  2835. {
  2836. struct inode *journal_inode;
  2837. journal_t *journal;
  2838. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  2839. /* First, test for the existence of a valid inode on disk. Bad
  2840. * things happen if we iget() an unused inode, as the subsequent
  2841. * iput() will try to delete it. */
  2842. journal_inode = ext4_iget(sb, journal_inum);
  2843. if (IS_ERR(journal_inode)) {
  2844. ext4_msg(sb, KERN_ERR, "no journal found");
  2845. return NULL;
  2846. }
  2847. if (!journal_inode->i_nlink) {
  2848. make_bad_inode(journal_inode);
  2849. iput(journal_inode);
  2850. ext4_msg(sb, KERN_ERR, "journal inode is deleted");
  2851. return NULL;
  2852. }
  2853. jbd_debug(2, "Journal inode found at %p: %lld bytes\n",
  2854. journal_inode, journal_inode->i_size);
  2855. if (!S_ISREG(journal_inode->i_mode)) {
  2856. ext4_msg(sb, KERN_ERR, "invalid journal inode");
  2857. iput(journal_inode);
  2858. return NULL;
  2859. }
  2860. journal = jbd2_journal_init_inode(journal_inode);
  2861. if (!journal) {
  2862. ext4_msg(sb, KERN_ERR, "Could not load journal inode");
  2863. iput(journal_inode);
  2864. return NULL;
  2865. }
  2866. journal->j_private = sb;
  2867. ext4_init_journal_params(sb, journal);
  2868. return journal;
  2869. }
  2870. static journal_t *ext4_get_dev_journal(struct super_block *sb,
  2871. dev_t j_dev)
  2872. {
  2873. struct buffer_head *bh;
  2874. journal_t *journal;
  2875. ext4_fsblk_t start;
  2876. ext4_fsblk_t len;
  2877. int hblock, blocksize;
  2878. ext4_fsblk_t sb_block;
  2879. unsigned long offset;
  2880. struct ext4_super_block *es;
  2881. struct block_device *bdev;
  2882. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  2883. bdev = ext4_blkdev_get(j_dev, sb);
  2884. if (bdev == NULL)
  2885. return NULL;
  2886. if (bd_claim(bdev, sb)) {
  2887. ext4_msg(sb, KERN_ERR,
  2888. "failed to claim external journal device");
  2889. blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
  2890. return NULL;
  2891. }
  2892. blocksize = sb->s_blocksize;
  2893. hblock = bdev_logical_block_size(bdev);
  2894. if (blocksize < hblock) {
  2895. ext4_msg(sb, KERN_ERR,
  2896. "blocksize too small for journal device");
  2897. goto out_bdev;
  2898. }
  2899. sb_block = EXT4_MIN_BLOCK_SIZE / blocksize;
  2900. offset = EXT4_MIN_BLOCK_SIZE % blocksize;
  2901. set_blocksize(bdev, blocksize);
  2902. if (!(bh = __bread(bdev, sb_block, blocksize))) {
  2903. ext4_msg(sb, KERN_ERR, "couldn't read superblock of "
  2904. "external journal");
  2905. goto out_bdev;
  2906. }
  2907. es = (struct ext4_super_block *) (((char *)bh->b_data) + offset);
  2908. if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
  2909. !(le32_to_cpu(es->s_feature_incompat) &
  2910. EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
  2911. ext4_msg(sb, KERN_ERR, "external journal has "
  2912. "bad superblock");
  2913. brelse(bh);
  2914. goto out_bdev;
  2915. }
  2916. if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
  2917. ext4_msg(sb, KERN_ERR, "journal UUID does not match");
  2918. brelse(bh);
  2919. goto out_bdev;
  2920. }
  2921. len = ext4_blocks_count(es);
  2922. start = sb_block + 1;
  2923. brelse(bh); /* we're done with the superblock */
  2924. journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
  2925. start, len, blocksize);
  2926. if (!journal) {
  2927. ext4_msg(sb, KERN_ERR, "failed to create device journal");
  2928. goto out_bdev;
  2929. }
  2930. journal->j_private = sb;
  2931. ll_rw_block(READ, 1, &journal->j_sb_buffer);
  2932. wait_on_buffer(journal->j_sb_buffer);
  2933. if (!buffer_uptodate(journal->j_sb_buffer)) {
  2934. ext4_msg(sb, KERN_ERR, "I/O error on journal device");
  2935. goto out_journal;
  2936. }
  2937. if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
  2938. ext4_msg(sb, KERN_ERR, "External journal has more than one "
  2939. "user (unsupported) - %d",
  2940. be32_to_cpu(journal->j_superblock->s_nr_users));
  2941. goto out_journal;
  2942. }
  2943. EXT4_SB(sb)->journal_bdev = bdev;
  2944. ext4_init_journal_params(sb, journal);
  2945. return journal;
  2946. out_journal:
  2947. jbd2_journal_destroy(journal);
  2948. out_bdev:
  2949. ext4_blkdev_put(bdev);
  2950. return NULL;
  2951. }
  2952. static int ext4_load_journal(struct super_block *sb,
  2953. struct ext4_super_block *es,
  2954. unsigned long journal_devnum)
  2955. {
  2956. journal_t *journal;
  2957. unsigned int journal_inum = le32_to_cpu(es->s_journal_inum);
  2958. dev_t journal_dev;
  2959. int err = 0;
  2960. int really_read_only;
  2961. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  2962. if (journal_devnum &&
  2963. journal_devnum != le32_to_cpu(es->s_journal_dev)) {
  2964. ext4_msg(sb, KERN_INFO, "external journal device major/minor "
  2965. "numbers have changed");
  2966. journal_dev = new_decode_dev(journal_devnum);
  2967. } else
  2968. journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
  2969. really_read_only = bdev_read_only(sb->s_bdev);
  2970. /*
  2971. * Are we loading a blank journal or performing recovery after a
  2972. * crash? For recovery, we need to check in advance whether we
  2973. * can get read-write access to the device.
  2974. */
  2975. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
  2976. if (sb->s_flags & MS_RDONLY) {
  2977. ext4_msg(sb, KERN_INFO, "INFO: recovery "
  2978. "required on readonly filesystem");
  2979. if (really_read_only) {
  2980. ext4_msg(sb, KERN_ERR, "write access "
  2981. "unavailable, cannot proceed");
  2982. return -EROFS;
  2983. }
  2984. ext4_msg(sb, KERN_INFO, "write access will "
  2985. "be enabled during recovery");
  2986. }
  2987. }
  2988. if (journal_inum && journal_dev) {
  2989. ext4_msg(sb, KERN_ERR, "filesystem has both journal "
  2990. "and inode journals!");
  2991. return -EINVAL;
  2992. }
  2993. if (journal_inum) {
  2994. if (!(journal = ext4_get_journal(sb, journal_inum)))
  2995. return -EINVAL;
  2996. } else {
  2997. if (!(journal = ext4_get_dev_journal(sb, journal_dev)))
  2998. return -EINVAL;
  2999. }
  3000. if (!(journal->j_flags & JBD2_BARRIER))
  3001. ext4_msg(sb, KERN_INFO, "barriers disabled");
  3002. if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) {
  3003. err = jbd2_journal_update_format(journal);
  3004. if (err) {
  3005. ext4_msg(sb, KERN_ERR, "error updating journal");
  3006. jbd2_journal_destroy(journal);
  3007. return err;
  3008. }
  3009. }
  3010. if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
  3011. err = jbd2_journal_wipe(journal, !really_read_only);
  3012. if (!err) {
  3013. char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
  3014. if (save)
  3015. memcpy(save, ((char *) es) +
  3016. EXT4_S_ERR_START, EXT4_S_ERR_LEN);
  3017. err = jbd2_journal_load(journal);
  3018. if (save)
  3019. memcpy(((char *) es) + EXT4_S_ERR_START,
  3020. save, EXT4_S_ERR_LEN);
  3021. kfree(save);
  3022. }
  3023. if (err) {
  3024. ext4_msg(sb, KERN_ERR, "error loading journal");
  3025. jbd2_journal_destroy(journal);
  3026. return err;
  3027. }
  3028. EXT4_SB(sb)->s_journal = journal;
  3029. ext4_clear_journal_err(sb, es);
  3030. if (journal_devnum &&
  3031. journal_devnum != le32_to_cpu(es->s_journal_dev)) {
  3032. es->s_journal_dev = cpu_to_le32(journal_devnum);
  3033. /* Make sure we flush the recovery flag to disk. */
  3034. ext4_commit_super(sb, 1);
  3035. }
  3036. return 0;
  3037. }
  3038. static int ext4_commit_super(struct super_block *sb, int sync)
  3039. {
  3040. struct ext4_super_block *es = EXT4_SB(sb)->s_es;
  3041. struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
  3042. int error = 0;
  3043. if (!sbh)
  3044. return error;
  3045. if (buffer_write_io_error(sbh)) {
  3046. /*
  3047. * Oh, dear. A previous attempt to write the
  3048. * superblock failed. This could happen because the
  3049. * USB device was yanked out. Or it could happen to
  3050. * be a transient write error and maybe the block will
  3051. * be remapped. Nothing we can do but to retry the
  3052. * write and hope for the best.
  3053. */
  3054. ext4_msg(sb, KERN_ERR, "previous I/O error to "
  3055. "superblock detected");
  3056. clear_buffer_write_io_error(sbh);
  3057. set_buffer_uptodate(sbh);
  3058. }
  3059. /*
  3060. * If the file system is mounted read-only, don't update the
  3061. * superblock write time. This avoids updating the superblock
  3062. * write time when we are mounting the root file system
  3063. * read/only but we need to replay the journal; at that point,
  3064. * for people who are east of GMT and who make their clock
  3065. * tick in localtime for Windows bug-for-bug compatibility,
  3066. * the clock is set in the future, and this will cause e2fsck
  3067. * to complain and force a full file system check.
  3068. */
  3069. if (!(sb->s_flags & MS_RDONLY))
  3070. es->s_wtime = cpu_to_le32(get_seconds());
  3071. es->s_kbytes_written =
  3072. cpu_to_le64(EXT4_SB(sb)->s_kbytes_written +
  3073. ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
  3074. EXT4_SB(sb)->s_sectors_written_start) >> 1));
  3075. ext4_free_blocks_count_set(es, percpu_counter_sum_positive(
  3076. &EXT4_SB(sb)->s_freeblocks_counter));
  3077. es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive(
  3078. &EXT4_SB(sb)->s_freeinodes_counter));
  3079. sb->s_dirt = 0;
  3080. BUFFER_TRACE(sbh, "marking dirty");
  3081. mark_buffer_dirty(sbh);
  3082. if (sync) {
  3083. error = sync_dirty_buffer(sbh);
  3084. if (error)
  3085. return error;
  3086. error = buffer_write_io_error(sbh);
  3087. if (error) {
  3088. ext4_msg(sb, KERN_ERR, "I/O error while writing "
  3089. "superblock");
  3090. clear_buffer_write_io_error(sbh);
  3091. set_buffer_uptodate(sbh);
  3092. }
  3093. }
  3094. return error;
  3095. }
  3096. /*
  3097. * Have we just finished recovery? If so, and if we are mounting (or
  3098. * remounting) the filesystem readonly, then we will end up with a
  3099. * consistent fs on disk. Record that fact.
  3100. */
  3101. static void ext4_mark_recovery_complete(struct super_block *sb,
  3102. struct ext4_super_block *es)
  3103. {
  3104. journal_t *journal = EXT4_SB(sb)->s_journal;
  3105. if (!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) {
  3106. BUG_ON(journal != NULL);
  3107. return;
  3108. }
  3109. jbd2_journal_lock_updates(journal);
  3110. if (jbd2_journal_flush(journal) < 0)
  3111. goto out;
  3112. if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
  3113. sb->s_flags & MS_RDONLY) {
  3114. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  3115. ext4_commit_super(sb, 1);
  3116. }
  3117. out:
  3118. jbd2_journal_unlock_updates(journal);
  3119. }
  3120. /*
  3121. * If we are mounting (or read-write remounting) a filesystem whose journal
  3122. * has recorded an error from a previous lifetime, move that error to the
  3123. * main filesystem now.
  3124. */
  3125. static void ext4_clear_journal_err(struct super_block *sb,
  3126. struct ext4_super_block *es)
  3127. {
  3128. journal_t *journal;
  3129. int j_errno;
  3130. const char *errstr;
  3131. BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
  3132. journal = EXT4_SB(sb)->s_journal;
  3133. /*
  3134. * Now check for any error status which may have been recorded in the
  3135. * journal by a prior ext4_error() or ext4_abort()
  3136. */
  3137. j_errno = jbd2_journal_errno(journal);
  3138. if (j_errno) {
  3139. char nbuf[16];
  3140. errstr = ext4_decode_error(sb, j_errno, nbuf);
  3141. ext4_warning(sb, "Filesystem error recorded "
  3142. "from previous mount: %s", errstr);
  3143. ext4_warning(sb, "Marking fs in need of filesystem check.");
  3144. EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
  3145. es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
  3146. ext4_commit_super(sb, 1);
  3147. jbd2_journal_clear_err(journal);
  3148. }
  3149. }
  3150. /*
  3151. * Force the running and committing transactions to commit,
  3152. * and wait on the commit.
  3153. */
  3154. int ext4_force_commit(struct super_block *sb)
  3155. {
  3156. journal_t *journal;
  3157. int ret = 0;
  3158. if (sb->s_flags & MS_RDONLY)
  3159. return 0;
  3160. journal = EXT4_SB(sb)->s_journal;
  3161. if (journal) {
  3162. vfs_check_frozen(sb, SB_FREEZE_WRITE);
  3163. ret = ext4_journal_force_commit(journal);
  3164. }
  3165. return ret;
  3166. }
  3167. static void ext4_write_super(struct super_block *sb)
  3168. {
  3169. lock_super(sb);
  3170. ext4_commit_super(sb, 1);
  3171. unlock_super(sb);
  3172. }
  3173. static int ext4_sync_fs(struct super_block *sb, int wait)
  3174. {
  3175. int ret = 0;
  3176. tid_t target;
  3177. struct ext4_sb_info *sbi = EXT4_SB(sb);
  3178. trace_ext4_sync_fs(sb, wait);
  3179. flush_workqueue(sbi->dio_unwritten_wq);
  3180. if (jbd2_journal_start_commit(sbi->s_journal, &target)) {
  3181. if (wait)
  3182. jbd2_log_wait_commit(sbi->s_journal, target);
  3183. }
  3184. return ret;
  3185. }
  3186. /*
  3187. * LVM calls this function before a (read-only) snapshot is created. This
  3188. * gives us a chance to flush the journal completely and mark the fs clean.
  3189. */
  3190. static int ext4_freeze(struct super_block *sb)
  3191. {
  3192. int error = 0;
  3193. journal_t *journal;
  3194. if (sb->s_flags & MS_RDONLY)
  3195. return 0;
  3196. journal = EXT4_SB(sb)->s_journal;
  3197. /* Now we set up the journal barrier. */
  3198. jbd2_journal_lock_updates(journal);
  3199. /*
  3200. * Don't clear the needs_recovery flag if we failed to flush
  3201. * the journal.
  3202. */
  3203. error = jbd2_journal_flush(journal);
  3204. if (error < 0)
  3205. goto out;
  3206. /* Journal blocked and flushed, clear needs_recovery flag. */
  3207. EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  3208. error = ext4_commit_super(sb, 1);
  3209. out:
  3210. /* we rely on s_frozen to stop further updates */
  3211. jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
  3212. return error;
  3213. }
  3214. /*
  3215. * Called by LVM after the snapshot is done. We need to reset the RECOVER
  3216. * flag here, even though the filesystem is not technically dirty yet.
  3217. */
  3218. static int ext4_unfreeze(struct super_block *sb)
  3219. {
  3220. if (sb->s_flags & MS_RDONLY)
  3221. return 0;
  3222. lock_super(sb);
  3223. /* Reset the needs_recovery flag before the fs is unlocked. */
  3224. EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
  3225. ext4_commit_super(sb, 1);
  3226. unlock_super(sb);
  3227. return 0;
  3228. }
  3229. static int ext4_remount(struct super_block *sb, int *flags, char *data)
  3230. {
  3231. struct ext4_super_block *es;
  3232. struct ext4_sb_info *sbi = EXT4_SB(sb);
  3233. ext4_fsblk_t n_blocks_count = 0;
  3234. unsigned long old_sb_flags;
  3235. struct ext4_mount_options old_opts;
  3236. int enable_quota = 0;
  3237. ext4_group_t g;
  3238. unsigned int journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
  3239. int err;
  3240. #ifdef CONFIG_QUOTA
  3241. int i;
  3242. #endif
  3243. char *orig_data = kstrdup(data, GFP_KERNEL);
  3244. lock_kernel();
  3245. /* Store the original options */
  3246. lock_super(sb);
  3247. old_sb_flags = sb->s_flags;
  3248. old_opts.s_mount_opt = sbi->s_mount_opt;
  3249. old_opts.s_resuid = sbi->s_resuid;
  3250. old_opts.s_resgid = sbi->s_resgid;
  3251. old_opts.s_commit_interval = sbi->s_commit_interval;
  3252. old_opts.s_min_batch_time = sbi->s_min_batch_time;
  3253. old_opts.s_max_batch_time = sbi->s_max_batch_time;
  3254. #ifdef CONFIG_QUOTA
  3255. old_opts.s_jquota_fmt = sbi->s_jquota_fmt;
  3256. for (i = 0; i < MAXQUOTAS; i++)
  3257. old_opts.s_qf_names[i] = sbi->s_qf_names[i];
  3258. #endif
  3259. if (sbi->s_journal && sbi->s_journal->j_task->io_context)
  3260. journal_ioprio = sbi->s_journal->j_task->io_context->ioprio;
  3261. /*
  3262. * Allow the "check" option to be passed as a remount option.
  3263. */
  3264. if (!parse_options(data, sb, NULL, &journal_ioprio,
  3265. &n_blocks_count, 1)) {
  3266. err = -EINVAL;
  3267. goto restore_opts;
  3268. }
  3269. if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
  3270. ext4_abort(sb, "Abort forced by user");
  3271. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  3272. (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
  3273. es = sbi->s_es;
  3274. if (sbi->s_journal) {
  3275. ext4_init_journal_params(sb, sbi->s_journal);
  3276. set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
  3277. }
  3278. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) ||
  3279. n_blocks_count > ext4_blocks_count(es)) {
  3280. if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) {
  3281. err = -EROFS;
  3282. goto restore_opts;
  3283. }
  3284. if (*flags & MS_RDONLY) {
  3285. err = dquot_suspend(sb, -1);
  3286. if (err < 0)
  3287. goto restore_opts;
  3288. /*
  3289. * First of all, the unconditional stuff we have to do
  3290. * to disable replay of the journal when we next remount
  3291. */
  3292. sb->s_flags |= MS_RDONLY;
  3293. /*
  3294. * OK, test if we are remounting a valid rw partition
  3295. * readonly, and if so set the rdonly flag and then
  3296. * mark the partition as valid again.
  3297. */
  3298. if (!(es->s_state & cpu_to_le16(EXT4_VALID_FS)) &&
  3299. (sbi->s_mount_state & EXT4_VALID_FS))
  3300. es->s_state = cpu_to_le16(sbi->s_mount_state);
  3301. if (sbi->s_journal)
  3302. ext4_mark_recovery_complete(sb, es);
  3303. } else {
  3304. /* Make sure we can mount this feature set readwrite */
  3305. if (!ext4_feature_set_ok(sb, 0)) {
  3306. err = -EROFS;
  3307. goto restore_opts;
  3308. }
  3309. /*
  3310. * Make sure the group descriptor checksums
  3311. * are sane. If they aren't, refuse to remount r/w.
  3312. */
  3313. for (g = 0; g < sbi->s_groups_count; g++) {
  3314. struct ext4_group_desc *gdp =
  3315. ext4_get_group_desc(sb, g, NULL);
  3316. if (!ext4_group_desc_csum_verify(sbi, g, gdp)) {
  3317. ext4_msg(sb, KERN_ERR,
  3318. "ext4_remount: Checksum for group %u failed (%u!=%u)",
  3319. g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
  3320. le16_to_cpu(gdp->bg_checksum));
  3321. err = -EINVAL;
  3322. goto restore_opts;
  3323. }
  3324. }
  3325. /*
  3326. * If we have an unprocessed orphan list hanging
  3327. * around from a previously readonly bdev mount,
  3328. * require a full umount/remount for now.
  3329. */
  3330. if (es->s_last_orphan) {
  3331. ext4_msg(sb, KERN_WARNING, "Couldn't "
  3332. "remount RDWR because of unprocessed "
  3333. "orphan inode list. Please "
  3334. "umount/remount instead");
  3335. err = -EINVAL;
  3336. goto restore_opts;
  3337. }
  3338. /*
  3339. * Mounting a RDONLY partition read-write, so reread
  3340. * and store the current valid flag. (It may have
  3341. * been changed by e2fsck since we originally mounted
  3342. * the partition.)
  3343. */
  3344. if (sbi->s_journal)
  3345. ext4_clear_journal_err(sb, es);
  3346. sbi->s_mount_state = le16_to_cpu(es->s_state);
  3347. if ((err = ext4_group_extend(sb, es, n_blocks_count)))
  3348. goto restore_opts;
  3349. if (!ext4_setup_super(sb, es, 0))
  3350. sb->s_flags &= ~MS_RDONLY;
  3351. enable_quota = 1;
  3352. }
  3353. }
  3354. ext4_setup_system_zone(sb);
  3355. if (sbi->s_journal == NULL)
  3356. ext4_commit_super(sb, 1);
  3357. #ifdef CONFIG_QUOTA
  3358. /* Release old quota file names */
  3359. for (i = 0; i < MAXQUOTAS; i++)
  3360. if (old_opts.s_qf_names[i] &&
  3361. old_opts.s_qf_names[i] != sbi->s_qf_names[i])
  3362. kfree(old_opts.s_qf_names[i]);
  3363. #endif
  3364. unlock_super(sb);
  3365. unlock_kernel();
  3366. if (enable_quota)
  3367. dquot_resume(sb, -1);
  3368. ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data);
  3369. kfree(orig_data);
  3370. return 0;
  3371. restore_opts:
  3372. sb->s_flags = old_sb_flags;
  3373. sbi->s_mount_opt = old_opts.s_mount_opt;
  3374. sbi->s_resuid = old_opts.s_resuid;
  3375. sbi->s_resgid = old_opts.s_resgid;
  3376. sbi->s_commit_interval = old_opts.s_commit_interval;
  3377. sbi->s_min_batch_time = old_opts.s_min_batch_time;
  3378. sbi->s_max_batch_time = old_opts.s_max_batch_time;
  3379. #ifdef CONFIG_QUOTA
  3380. sbi->s_jquota_fmt = old_opts.s_jquota_fmt;
  3381. for (i = 0; i < MAXQUOTAS; i++) {
  3382. if (sbi->s_qf_names[i] &&
  3383. old_opts.s_qf_names[i] != sbi->s_qf_names[i])
  3384. kfree(sbi->s_qf_names[i]);
  3385. sbi->s_qf_names[i] = old_opts.s_qf_names[i];
  3386. }
  3387. #endif
  3388. unlock_super(sb);
  3389. unlock_kernel();
  3390. kfree(orig_data);
  3391. return err;
  3392. }
  3393. static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
  3394. {
  3395. struct super_block *sb = dentry->d_sb;
  3396. struct ext4_sb_info *sbi = EXT4_SB(sb);
  3397. struct ext4_super_block *es = sbi->s_es;
  3398. u64 fsid;
  3399. if (test_opt(sb, MINIX_DF)) {
  3400. sbi->s_overhead_last = 0;
  3401. } else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
  3402. ext4_group_t i, ngroups = ext4_get_groups_count(sb);
  3403. ext4_fsblk_t overhead = 0;
  3404. /*
  3405. * Compute the overhead (FS structures). This is constant
  3406. * for a given filesystem unless the number of block groups
  3407. * changes so we cache the previous value until it does.
  3408. */
  3409. /*
  3410. * All of the blocks before first_data_block are
  3411. * overhead
  3412. */
  3413. overhead = le32_to_cpu(es->s_first_data_block);
  3414. /*
  3415. * Add the overhead attributed to the superblock and
  3416. * block group descriptors. If the sparse superblocks
  3417. * feature is turned on, then not all groups have this.
  3418. */
  3419. for (i = 0; i < ngroups; i++) {
  3420. overhead += ext4_bg_has_super(sb, i) +
  3421. ext4_bg_num_gdb(sb, i);
  3422. cond_resched();
  3423. }
  3424. /*
  3425. * Every block group has an inode bitmap, a block
  3426. * bitmap, and an inode table.
  3427. */
  3428. overhead += ngroups * (2 + sbi->s_itb_per_group);
  3429. sbi->s_overhead_last = overhead;
  3430. smp_wmb();
  3431. sbi->s_blocks_last = ext4_blocks_count(es);
  3432. }
  3433. buf->f_type = EXT4_SUPER_MAGIC;
  3434. buf->f_bsize = sb->s_blocksize;
  3435. buf->f_blocks = ext4_blocks_count(es) - sbi->s_overhead_last;
  3436. buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter) -
  3437. percpu_counter_sum_positive(&sbi->s_dirtyblocks_counter);
  3438. buf->f_bavail = buf->f_bfree - ext4_r_blocks_count(es);
  3439. if (buf->f_bfree < ext4_r_blocks_count(es))
  3440. buf->f_bavail = 0;
  3441. buf->f_files = le32_to_cpu(es->s_inodes_count);
  3442. buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
  3443. buf->f_namelen = EXT4_NAME_LEN;
  3444. fsid = le64_to_cpup((void *)es->s_uuid) ^
  3445. le64_to_cpup((void *)es->s_uuid + sizeof(u64));
  3446. buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
  3447. buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
  3448. return 0;
  3449. }
  3450. /* Helper function for writing quotas on sync - we need to start transaction
  3451. * before quota file is locked for write. Otherwise the are possible deadlocks:
  3452. * Process 1 Process 2
  3453. * ext4_create() quota_sync()
  3454. * jbd2_journal_start() write_dquot()
  3455. * dquot_initialize() down(dqio_mutex)
  3456. * down(dqio_mutex) jbd2_journal_start()
  3457. *
  3458. */
  3459. #ifdef CONFIG_QUOTA
  3460. static inline struct inode *dquot_to_inode(struct dquot *dquot)
  3461. {
  3462. return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
  3463. }
  3464. static int ext4_write_dquot(struct dquot *dquot)
  3465. {
  3466. int ret, err;
  3467. handle_t *handle;
  3468. struct inode *inode;
  3469. inode = dquot_to_inode(dquot);
  3470. handle = ext4_journal_start(inode,
  3471. EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
  3472. if (IS_ERR(handle))
  3473. return PTR_ERR(handle);
  3474. ret = dquot_commit(dquot);
  3475. err = ext4_journal_stop(handle);
  3476. if (!ret)
  3477. ret = err;
  3478. return ret;
  3479. }
  3480. static int ext4_acquire_dquot(struct dquot *dquot)
  3481. {
  3482. int ret, err;
  3483. handle_t *handle;
  3484. handle = ext4_journal_start(dquot_to_inode(dquot),
  3485. EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
  3486. if (IS_ERR(handle))
  3487. return PTR_ERR(handle);
  3488. ret = dquot_acquire(dquot);
  3489. err = ext4_journal_stop(handle);
  3490. if (!ret)
  3491. ret = err;
  3492. return ret;
  3493. }
  3494. static int ext4_release_dquot(struct dquot *dquot)
  3495. {
  3496. int ret, err;
  3497. handle_t *handle;
  3498. handle = ext4_journal_start(dquot_to_inode(dquot),
  3499. EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
  3500. if (IS_ERR(handle)) {
  3501. /* Release dquot anyway to avoid endless cycle in dqput() */
  3502. dquot_release(dquot);
  3503. return PTR_ERR(handle);
  3504. }
  3505. ret = dquot_release(dquot);
  3506. err = ext4_journal_stop(handle);
  3507. if (!ret)
  3508. ret = err;
  3509. return ret;
  3510. }
  3511. static int ext4_mark_dquot_dirty(struct dquot *dquot)
  3512. {
  3513. /* Are we journaling quotas? */
  3514. if (EXT4_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
  3515. EXT4_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
  3516. dquot_mark_dquot_dirty(dquot);
  3517. return ext4_write_dquot(dquot);
  3518. } else {
  3519. return dquot_mark_dquot_dirty(dquot);
  3520. }
  3521. }
  3522. static int ext4_write_info(struct super_block *sb, int type)
  3523. {
  3524. int ret, err;
  3525. handle_t *handle;
  3526. /* Data block + inode block */
  3527. handle = ext4_journal_start(sb->s_root->d_inode, 2);
  3528. if (IS_ERR(handle))
  3529. return PTR_ERR(handle);
  3530. ret = dquot_commit_info(sb, type);
  3531. err = ext4_journal_stop(handle);
  3532. if (!ret)
  3533. ret = err;
  3534. return ret;
  3535. }
  3536. /*
  3537. * Turn on quotas during mount time - we need to find
  3538. * the quota file and such...
  3539. */
  3540. static int ext4_quota_on_mount(struct super_block *sb, int type)
  3541. {
  3542. return dquot_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
  3543. EXT4_SB(sb)->s_jquota_fmt, type);
  3544. }
  3545. /*
  3546. * Standard function to be called on quota_on
  3547. */
  3548. static int ext4_quota_on(struct super_block *sb, int type, int format_id,
  3549. char *name)
  3550. {
  3551. int err;
  3552. struct path path;
  3553. if (!test_opt(sb, QUOTA))
  3554. return -EINVAL;
  3555. err = kern_path(name, LOOKUP_FOLLOW, &path);
  3556. if (err)
  3557. return err;
  3558. /* Quotafile not on the same filesystem? */
  3559. if (path.mnt->mnt_sb != sb) {
  3560. path_put(&path);
  3561. return -EXDEV;
  3562. }
  3563. /* Journaling quota? */
  3564. if (EXT4_SB(sb)->s_qf_names[type]) {
  3565. /* Quotafile not in fs root? */
  3566. if (path.dentry->d_parent != sb->s_root)
  3567. ext4_msg(sb, KERN_WARNING,
  3568. "Quota file not on filesystem root. "
  3569. "Journaled quota will not work");
  3570. }
  3571. /*
  3572. * When we journal data on quota file, we have to flush journal to see
  3573. * all updates to the file when we bypass pagecache...
  3574. */
  3575. if (EXT4_SB(sb)->s_journal &&
  3576. ext4_should_journal_data(path.dentry->d_inode)) {
  3577. /*
  3578. * We don't need to lock updates but journal_flush() could
  3579. * otherwise be livelocked...
  3580. */
  3581. jbd2_journal_lock_updates(EXT4_SB(sb)->s_journal);
  3582. err = jbd2_journal_flush(EXT4_SB(sb)->s_journal);
  3583. jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
  3584. if (err) {
  3585. path_put(&path);
  3586. return err;
  3587. }
  3588. }
  3589. err = dquot_quota_on_path(sb, type, format_id, &path);
  3590. path_put(&path);
  3591. return err;
  3592. }
  3593. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  3594. * acquiring the locks... As quota files are never truncated and quota code
  3595. * itself serializes the operations (and noone else should touch the files)
  3596. * we don't have to be afraid of races */
  3597. static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
  3598. size_t len, loff_t off)
  3599. {
  3600. struct inode *inode = sb_dqopt(sb)->files[type];
  3601. ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
  3602. int err = 0;
  3603. int offset = off & (sb->s_blocksize - 1);
  3604. int tocopy;
  3605. size_t toread;
  3606. struct buffer_head *bh;
  3607. loff_t i_size = i_size_read(inode);
  3608. if (off > i_size)
  3609. return 0;
  3610. if (off+len > i_size)
  3611. len = i_size-off;
  3612. toread = len;
  3613. while (toread > 0) {
  3614. tocopy = sb->s_blocksize - offset < toread ?
  3615. sb->s_blocksize - offset : toread;
  3616. bh = ext4_bread(NULL, inode, blk, 0, &err);
  3617. if (err)
  3618. return err;
  3619. if (!bh) /* A hole? */
  3620. memset(data, 0, tocopy);
  3621. else
  3622. memcpy(data, bh->b_data+offset, tocopy);
  3623. brelse(bh);
  3624. offset = 0;
  3625. toread -= tocopy;
  3626. data += tocopy;
  3627. blk++;
  3628. }
  3629. return len;
  3630. }
  3631. /* Write to quotafile (we know the transaction is already started and has
  3632. * enough credits) */
  3633. static ssize_t ext4_quota_write(struct super_block *sb, int type,
  3634. const char *data, size_t len, loff_t off)
  3635. {
  3636. struct inode *inode = sb_dqopt(sb)->files[type];
  3637. ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
  3638. int err = 0;
  3639. int offset = off & (sb->s_blocksize - 1);
  3640. int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL;
  3641. struct buffer_head *bh;
  3642. handle_t *handle = journal_current_handle();
  3643. if (EXT4_SB(sb)->s_journal && !handle) {
  3644. ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
  3645. " cancelled because transaction is not started",
  3646. (unsigned long long)off, (unsigned long long)len);
  3647. return -EIO;
  3648. }
  3649. /*
  3650. * Since we account only one data block in transaction credits,
  3651. * then it is impossible to cross a block boundary.
  3652. */
  3653. if (sb->s_blocksize - offset < len) {
  3654. ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
  3655. " cancelled because not block aligned",
  3656. (unsigned long long)off, (unsigned long long)len);
  3657. return -EIO;
  3658. }
  3659. mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
  3660. bh = ext4_bread(handle, inode, blk, 1, &err);
  3661. if (!bh)
  3662. goto out;
  3663. if (journal_quota) {
  3664. err = ext4_journal_get_write_access(handle, bh);
  3665. if (err) {
  3666. brelse(bh);
  3667. goto out;
  3668. }
  3669. }
  3670. lock_buffer(bh);
  3671. memcpy(bh->b_data+offset, data, len);
  3672. flush_dcache_page(bh->b_page);
  3673. unlock_buffer(bh);
  3674. if (journal_quota)
  3675. err = ext4_handle_dirty_metadata(handle, NULL, bh);
  3676. else {
  3677. /* Always do at least ordered writes for quotas */
  3678. err = ext4_jbd2_file_inode(handle, inode);
  3679. mark_buffer_dirty(bh);
  3680. }
  3681. brelse(bh);
  3682. out:
  3683. if (err) {
  3684. mutex_unlock(&inode->i_mutex);
  3685. return err;
  3686. }
  3687. if (inode->i_size < off + len) {
  3688. i_size_write(inode, off + len);
  3689. EXT4_I(inode)->i_disksize = inode->i_size;
  3690. }
  3691. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  3692. ext4_mark_inode_dirty(handle, inode);
  3693. mutex_unlock(&inode->i_mutex);
  3694. return len;
  3695. }
  3696. #endif
  3697. static int ext4_get_sb(struct file_system_type *fs_type, int flags,
  3698. const char *dev_name, void *data, struct vfsmount *mnt)
  3699. {
  3700. return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super,mnt);
  3701. }
  3702. #if !defined(CONFIG_EXT2_FS) && !defined(CONFIG_EXT2_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
  3703. static struct file_system_type ext2_fs_type = {
  3704. .owner = THIS_MODULE,
  3705. .name = "ext2",
  3706. .get_sb = ext4_get_sb,
  3707. .kill_sb = kill_block_super,
  3708. .fs_flags = FS_REQUIRES_DEV,
  3709. };
  3710. static inline void register_as_ext2(void)
  3711. {
  3712. int err = register_filesystem(&ext2_fs_type);
  3713. if (err)
  3714. printk(KERN_WARNING
  3715. "EXT4-fs: Unable to register as ext2 (%d)\n", err);
  3716. }
  3717. static inline void unregister_as_ext2(void)
  3718. {
  3719. unregister_filesystem(&ext2_fs_type);
  3720. }
  3721. MODULE_ALIAS("ext2");
  3722. #else
  3723. static inline void register_as_ext2(void) { }
  3724. static inline void unregister_as_ext2(void) { }
  3725. #endif
  3726. #if !defined(CONFIG_EXT3_FS) && !defined(CONFIG_EXT3_FS_MODULE) && defined(CONFIG_EXT4_USE_FOR_EXT23)
  3727. static inline void register_as_ext3(void)
  3728. {
  3729. int err = register_filesystem(&ext3_fs_type);
  3730. if (err)
  3731. printk(KERN_WARNING
  3732. "EXT4-fs: Unable to register as ext3 (%d)\n", err);
  3733. }
  3734. static inline void unregister_as_ext3(void)
  3735. {
  3736. unregister_filesystem(&ext3_fs_type);
  3737. }
  3738. MODULE_ALIAS("ext3");
  3739. #else
  3740. static inline void register_as_ext3(void) { }
  3741. static inline void unregister_as_ext3(void) { }
  3742. #endif
  3743. static struct file_system_type ext4_fs_type = {
  3744. .owner = THIS_MODULE,
  3745. .name = "ext4",
  3746. .get_sb = ext4_get_sb,
  3747. .kill_sb = kill_block_super,
  3748. .fs_flags = FS_REQUIRES_DEV,
  3749. };
  3750. static int __init init_ext4_fs(void)
  3751. {
  3752. int err;
  3753. ext4_check_flag_values();
  3754. err = init_ext4_system_zone();
  3755. if (err)
  3756. return err;
  3757. ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj);
  3758. if (!ext4_kset)
  3759. goto out4;
  3760. ext4_proc_root = proc_mkdir("fs/ext4", NULL);
  3761. err = init_ext4_mballoc();
  3762. if (err)
  3763. goto out3;
  3764. err = init_ext4_xattr();
  3765. if (err)
  3766. goto out2;
  3767. err = init_inodecache();
  3768. if (err)
  3769. goto out1;
  3770. register_as_ext2();
  3771. register_as_ext3();
  3772. err = register_filesystem(&ext4_fs_type);
  3773. if (err)
  3774. goto out;
  3775. return 0;
  3776. out:
  3777. unregister_as_ext2();
  3778. unregister_as_ext3();
  3779. destroy_inodecache();
  3780. out1:
  3781. exit_ext4_xattr();
  3782. out2:
  3783. exit_ext4_mballoc();
  3784. out3:
  3785. remove_proc_entry("fs/ext4", NULL);
  3786. kset_unregister(ext4_kset);
  3787. out4:
  3788. exit_ext4_system_zone();
  3789. return err;
  3790. }
  3791. static void __exit exit_ext4_fs(void)
  3792. {
  3793. unregister_as_ext2();
  3794. unregister_as_ext3();
  3795. unregister_filesystem(&ext4_fs_type);
  3796. destroy_inodecache();
  3797. exit_ext4_xattr();
  3798. exit_ext4_mballoc();
  3799. remove_proc_entry("fs/ext4", NULL);
  3800. kset_unregister(ext4_kset);
  3801. exit_ext4_system_zone();
  3802. }
  3803. MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
  3804. MODULE_DESCRIPTION("Fourth Extended Filesystem");
  3805. MODULE_LICENSE("GPL");
  3806. module_init(init_ext4_fs)
  3807. module_exit(exit_ext4_fs)