123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868 |
- #include "xfs.h"
- #include "xfs_fs.h"
- #include "xfs_shared.h"
- #include "xfs_format.h"
- #include "xfs_log_format.h"
- #include "xfs_trans_resv.h"
- #include "xfs_bit.h"
- #include "xfs_sb.h"
- #include "xfs_mount.h"
- #include "xfs_da_format.h"
- #include "xfs_da_btree.h"
- #include "xfs_inode.h"
- #include "xfs_trans.h"
- #include "xfs_log.h"
- #include "xfs_log_priv.h"
- #include "xfs_log_recover.h"
- #include "xfs_inode_item.h"
- #include "xfs_extfree_item.h"
- #include "xfs_trans_priv.h"
- #include "xfs_alloc.h"
- #include "xfs_ialloc.h"
- #include "xfs_quota.h"
- #include "xfs_cksum.h"
- #include "xfs_trace.h"
- #include "xfs_icache.h"
- #include "xfs_bmap_btree.h"
- #include "xfs_error.h"
- #include "xfs_dir2.h"
- #include "xfs_rmap_item.h"
- #include "xfs_buf_item.h"
- #include "xfs_refcount_item.h"
- #include "xfs_bmap_item.h"
- #define BLK_AVG(blk1, blk2) ((blk1+blk2) >> 1)
- STATIC int
- xlog_find_zeroed(
- struct xlog *,
- xfs_daddr_t *);
- STATIC int
- xlog_clear_stale_blocks(
- struct xlog *,
- xfs_lsn_t);
- #if defined(DEBUG)
- STATIC void
- xlog_recover_check_summary(
- struct xlog *);
- #else
- #define xlog_recover_check_summary(log)
- #endif
- STATIC int
- xlog_do_recovery_pass(
- struct xlog *, xfs_daddr_t, xfs_daddr_t, int, xfs_daddr_t *);
- struct xfs_buf_cancel {
- xfs_daddr_t bc_blkno;
- uint bc_len;
- int bc_refcount;
- struct list_head bc_list;
- };
- static inline int
- xlog_buf_bbcount_valid(
- struct xlog *log,
- int bbcount)
- {
- return bbcount > 0 && bbcount <= log->l_logBBsize;
- }
- STATIC xfs_buf_t *
- xlog_get_bp(
- struct xlog *log,
- int nbblks)
- {
- struct xfs_buf *bp;
- if (!xlog_buf_bbcount_valid(log, nbblks)) {
- xfs_warn(log->l_mp, "Invalid block length (0x%x) for buffer",
- nbblks);
- XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_HIGH, log->l_mp);
- return NULL;
- }
-
- if (nbblks > 1 && log->l_sectBBsize > 1)
- nbblks += log->l_sectBBsize;
- nbblks = round_up(nbblks, log->l_sectBBsize);
- bp = xfs_buf_get_uncached(log->l_mp->m_logdev_targp, nbblks, 0);
- if (bp)
- xfs_buf_unlock(bp);
- return bp;
- }
- STATIC void
- xlog_put_bp(
- xfs_buf_t *bp)
- {
- xfs_buf_free(bp);
- }
- STATIC char *
- xlog_align(
- struct xlog *log,
- xfs_daddr_t blk_no,
- int nbblks,
- struct xfs_buf *bp)
- {
- xfs_daddr_t offset = blk_no & ((xfs_daddr_t)log->l_sectBBsize - 1);
- ASSERT(offset + nbblks <= bp->b_length);
- return bp->b_addr + BBTOB(offset);
- }
- STATIC int
- xlog_bread_noalign(
- struct xlog *log,
- xfs_daddr_t blk_no,
- int nbblks,
- struct xfs_buf *bp)
- {
- int error;
- if (!xlog_buf_bbcount_valid(log, nbblks)) {
- xfs_warn(log->l_mp, "Invalid block length (0x%x) for buffer",
- nbblks);
- XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_HIGH, log->l_mp);
- return -EFSCORRUPTED;
- }
- blk_no = round_down(blk_no, log->l_sectBBsize);
- nbblks = round_up(nbblks, log->l_sectBBsize);
- ASSERT(nbblks > 0);
- ASSERT(nbblks <= bp->b_length);
- XFS_BUF_SET_ADDR(bp, log->l_logBBstart + blk_no);
- bp->b_flags |= XBF_READ;
- bp->b_io_length = nbblks;
- bp->b_error = 0;
- error = xfs_buf_submit_wait(bp);
- if (error && !XFS_FORCED_SHUTDOWN(log->l_mp))
- xfs_buf_ioerror_alert(bp, __func__);
- return error;
- }
- STATIC int
- xlog_bread(
- struct xlog *log,
- xfs_daddr_t blk_no,
- int nbblks,
- struct xfs_buf *bp,
- char **offset)
- {
- int error;
- error = xlog_bread_noalign(log, blk_no, nbblks, bp);
- if (error)
- return error;
- *offset = xlog_align(log, blk_no, nbblks, bp);
- return 0;
- }
- STATIC int
- xlog_bread_offset(
- struct xlog *log,
- xfs_daddr_t blk_no,
- int nbblks,
- struct xfs_buf *bp,
- char *offset)
- {
- char *orig_offset = bp->b_addr;
- int orig_len = BBTOB(bp->b_length);
- int error, error2;
- error = xfs_buf_associate_memory(bp, offset, BBTOB(nbblks));
- if (error)
- return error;
- error = xlog_bread_noalign(log, blk_no, nbblks, bp);
-
- error2 = xfs_buf_associate_memory(bp, orig_offset, orig_len);
- if (error)
- return error;
- return error2;
- }
- STATIC int
- xlog_bwrite(
- struct xlog *log,
- xfs_daddr_t blk_no,
- int nbblks,
- struct xfs_buf *bp)
- {
- int error;
- if (!xlog_buf_bbcount_valid(log, nbblks)) {
- xfs_warn(log->l_mp, "Invalid block length (0x%x) for buffer",
- nbblks);
- XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_HIGH, log->l_mp);
- return -EFSCORRUPTED;
- }
- blk_no = round_down(blk_no, log->l_sectBBsize);
- nbblks = round_up(nbblks, log->l_sectBBsize);
- ASSERT(nbblks > 0);
- ASSERT(nbblks <= bp->b_length);
- XFS_BUF_SET_ADDR(bp, log->l_logBBstart + blk_no);
- xfs_buf_hold(bp);
- xfs_buf_lock(bp);
- bp->b_io_length = nbblks;
- bp->b_error = 0;
- error = xfs_bwrite(bp);
- if (error)
- xfs_buf_ioerror_alert(bp, __func__);
- xfs_buf_relse(bp);
- return error;
- }
- #ifdef DEBUG
- STATIC void
- xlog_header_check_dump(
- xfs_mount_t *mp,
- xlog_rec_header_t *head)
- {
- xfs_debug(mp, "%s: SB : uuid = %pU, fmt = %d",
- __func__, &mp->m_sb.sb_uuid, XLOG_FMT);
- xfs_debug(mp, " log : uuid = %pU, fmt = %d",
- &head->h_fs_uuid, be32_to_cpu(head->h_fmt));
- }
- #else
- #define xlog_header_check_dump(mp, head)
- #endif
- STATIC int
- xlog_header_check_recover(
- xfs_mount_t *mp,
- xlog_rec_header_t *head)
- {
- ASSERT(head->h_magicno == cpu_to_be32(XLOG_HEADER_MAGIC_NUM));
-
- if (unlikely(head->h_fmt != cpu_to_be32(XLOG_FMT))) {
- xfs_warn(mp,
- "dirty log written in incompatible format - can't recover");
- xlog_header_check_dump(mp, head);
- XFS_ERROR_REPORT("xlog_header_check_recover(1)",
- XFS_ERRLEVEL_HIGH, mp);
- return -EFSCORRUPTED;
- } else if (unlikely(!uuid_equal(&mp->m_sb.sb_uuid, &head->h_fs_uuid))) {
- xfs_warn(mp,
- "dirty log entry has mismatched uuid - can't recover");
- xlog_header_check_dump(mp, head);
- XFS_ERROR_REPORT("xlog_header_check_recover(2)",
- XFS_ERRLEVEL_HIGH, mp);
- return -EFSCORRUPTED;
- }
- return 0;
- }
- STATIC int
- xlog_header_check_mount(
- xfs_mount_t *mp,
- xlog_rec_header_t *head)
- {
- ASSERT(head->h_magicno == cpu_to_be32(XLOG_HEADER_MAGIC_NUM));
- if (uuid_is_nil(&head->h_fs_uuid)) {
-
- xfs_warn(mp, "nil uuid in log - IRIX style log");
- } else if (unlikely(!uuid_equal(&mp->m_sb.sb_uuid, &head->h_fs_uuid))) {
- xfs_warn(mp, "log has mismatched uuid - can't recover");
- xlog_header_check_dump(mp, head);
- XFS_ERROR_REPORT("xlog_header_check_mount",
- XFS_ERRLEVEL_HIGH, mp);
- return -EFSCORRUPTED;
- }
- return 0;
- }
- STATIC void
- xlog_recover_iodone(
- struct xfs_buf *bp)
- {
- if (bp->b_error) {
-
- if (!XFS_FORCED_SHUTDOWN(bp->b_target->bt_mount)) {
- xfs_buf_ioerror_alert(bp, __func__);
- xfs_force_shutdown(bp->b_target->bt_mount,
- SHUTDOWN_META_IO_ERROR);
- }
- }
-
- if (bp->b_fspriv)
- xfs_buf_item_relse(bp);
- ASSERT(bp->b_fspriv == NULL);
- bp->b_iodone = NULL;
- xfs_buf_ioend(bp);
- }
- STATIC int
- xlog_find_cycle_start(
- struct xlog *log,
- struct xfs_buf *bp,
- xfs_daddr_t first_blk,
- xfs_daddr_t *last_blk,
- uint cycle)
- {
- char *offset;
- xfs_daddr_t mid_blk;
- xfs_daddr_t end_blk;
- uint mid_cycle;
- int error;
- end_blk = *last_blk;
- mid_blk = BLK_AVG(first_blk, end_blk);
- while (mid_blk != first_blk && mid_blk != end_blk) {
- error = xlog_bread(log, mid_blk, 1, bp, &offset);
- if (error)
- return error;
- mid_cycle = xlog_get_cycle(offset);
- if (mid_cycle == cycle)
- end_blk = mid_blk;
- else
- first_blk = mid_blk;
- mid_blk = BLK_AVG(first_blk, end_blk);
- }
- ASSERT((mid_blk == first_blk && mid_blk+1 == end_blk) ||
- (mid_blk == end_blk && mid_blk-1 == first_blk));
- *last_blk = end_blk;
- return 0;
- }
- STATIC int
- xlog_find_verify_cycle(
- struct xlog *log,
- xfs_daddr_t start_blk,
- int nbblks,
- uint stop_on_cycle_no,
- xfs_daddr_t *new_blk)
- {
- xfs_daddr_t i, j;
- uint cycle;
- xfs_buf_t *bp;
- xfs_daddr_t bufblks;
- char *buf = NULL;
- int error = 0;
-
- bufblks = 1 << ffs(nbblks);
- while (bufblks > log->l_logBBsize)
- bufblks >>= 1;
- while (!(bp = xlog_get_bp(log, bufblks))) {
- bufblks >>= 1;
- if (bufblks < log->l_sectBBsize)
- return -ENOMEM;
- }
- for (i = start_blk; i < start_blk + nbblks; i += bufblks) {
- int bcount;
- bcount = min(bufblks, (start_blk + nbblks - i));
- error = xlog_bread(log, i, bcount, bp, &buf);
- if (error)
- goto out;
- for (j = 0; j < bcount; j++) {
- cycle = xlog_get_cycle(buf);
- if (cycle == stop_on_cycle_no) {
- *new_blk = i+j;
- goto out;
- }
- buf += BBSIZE;
- }
- }
- *new_blk = -1;
- out:
- xlog_put_bp(bp);
- return error;
- }
- STATIC int
- xlog_find_verify_log_record(
- struct xlog *log,
- xfs_daddr_t start_blk,
- xfs_daddr_t *last_blk,
- int extra_bblks)
- {
- xfs_daddr_t i;
- xfs_buf_t *bp;
- char *offset = NULL;
- xlog_rec_header_t *head = NULL;
- int error = 0;
- int smallmem = 0;
- int num_blks = *last_blk - start_blk;
- int xhdrs;
- ASSERT(start_blk != 0 || *last_blk != start_blk);
- if (!(bp = xlog_get_bp(log, num_blks))) {
- if (!(bp = xlog_get_bp(log, 1)))
- return -ENOMEM;
- smallmem = 1;
- } else {
- error = xlog_bread(log, start_blk, num_blks, bp, &offset);
- if (error)
- goto out;
- offset += ((num_blks - 1) << BBSHIFT);
- }
- for (i = (*last_blk) - 1; i >= 0; i--) {
- if (i < start_blk) {
-
- xfs_warn(log->l_mp,
- "Log inconsistent (didn't find previous header)");
- ASSERT(0);
- error = -EIO;
- goto out;
- }
- if (smallmem) {
- error = xlog_bread(log, i, 1, bp, &offset);
- if (error)
- goto out;
- }
- head = (xlog_rec_header_t *)offset;
- if (head->h_magicno == cpu_to_be32(XLOG_HEADER_MAGIC_NUM))
- break;
- if (!smallmem)
- offset -= BBSIZE;
- }
-
- if (i == -1) {
- error = 1;
- goto out;
- }
-
- if ((error = xlog_header_check_mount(log->l_mp, head)))
- goto out;
-
- if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
- uint h_size = be32_to_cpu(head->h_size);
- xhdrs = h_size / XLOG_HEADER_CYCLE_SIZE;
- if (h_size % XLOG_HEADER_CYCLE_SIZE)
- xhdrs++;
- } else {
- xhdrs = 1;
- }
- if (*last_blk - i + extra_bblks !=
- BTOBB(be32_to_cpu(head->h_len)) + xhdrs)
- *last_blk = i;
- out:
- xlog_put_bp(bp);
- return error;
- }
- STATIC int
- xlog_find_head(
- struct xlog *log,
- xfs_daddr_t *return_head_blk)
- {
- xfs_buf_t *bp;
- char *offset;
- xfs_daddr_t new_blk, first_blk, start_blk, last_blk, head_blk;
- int num_scan_bblks;
- uint first_half_cycle, last_half_cycle;
- uint stop_on_cycle;
- int error, log_bbnum = log->l_logBBsize;
-
- error = xlog_find_zeroed(log, &first_blk);
- if (error < 0) {
- xfs_warn(log->l_mp, "empty log check failed");
- return error;
- }
- if (error == 1) {
- *return_head_blk = first_blk;
-
- if (!first_blk) {
-
- xfs_warn(log->l_mp, "totally zeroed log");
- }
- return 0;
- }
- first_blk = 0;
- bp = xlog_get_bp(log, 1);
- if (!bp)
- return -ENOMEM;
- error = xlog_bread(log, 0, 1, bp, &offset);
- if (error)
- goto bp_err;
- first_half_cycle = xlog_get_cycle(offset);
- last_blk = head_blk = log_bbnum - 1;
- error = xlog_bread(log, last_blk, 1, bp, &offset);
- if (error)
- goto bp_err;
- last_half_cycle = xlog_get_cycle(offset);
- ASSERT(last_half_cycle != 0);
-
- if (first_half_cycle == last_half_cycle) {
-
- head_blk = log_bbnum;
- stop_on_cycle = last_half_cycle - 1;
- } else {
-
- stop_on_cycle = last_half_cycle;
- if ((error = xlog_find_cycle_start(log, bp, first_blk,
- &head_blk, last_half_cycle)))
- goto bp_err;
- }
-
- num_scan_bblks = XLOG_TOTAL_REC_SHIFT(log);
- if (head_blk >= num_scan_bblks) {
-
- start_blk = head_blk - num_scan_bblks;
- if ((error = xlog_find_verify_cycle(log,
- start_blk, num_scan_bblks,
- stop_on_cycle, &new_blk)))
- goto bp_err;
- if (new_blk != -1)
- head_blk = new_blk;
- } else {
-
- ASSERT(head_blk <= INT_MAX &&
- (xfs_daddr_t) num_scan_bblks >= head_blk);
- start_blk = log_bbnum - (num_scan_bblks - head_blk);
- if ((error = xlog_find_verify_cycle(log, start_blk,
- num_scan_bblks - (int)head_blk,
- (stop_on_cycle - 1), &new_blk)))
- goto bp_err;
- if (new_blk != -1) {
- head_blk = new_blk;
- goto validate_head;
- }
-
- start_blk = 0;
- ASSERT(head_blk <= INT_MAX);
- if ((error = xlog_find_verify_cycle(log,
- start_blk, (int)head_blk,
- stop_on_cycle, &new_blk)))
- goto bp_err;
- if (new_blk != -1)
- head_blk = new_blk;
- }
- validate_head:
-
- num_scan_bblks = XLOG_REC_SHIFT(log);
- if (head_blk >= num_scan_bblks) {
- start_blk = head_blk - num_scan_bblks;
-
- error = xlog_find_verify_log_record(log, start_blk, &head_blk, 0);
- if (error == 1)
- error = -EIO;
- if (error)
- goto bp_err;
- } else {
- start_blk = 0;
- ASSERT(head_blk <= INT_MAX);
- error = xlog_find_verify_log_record(log, start_blk, &head_blk, 0);
- if (error < 0)
- goto bp_err;
- if (error == 1) {
-
- start_blk = log_bbnum - (num_scan_bblks - head_blk);
- new_blk = log_bbnum;
- ASSERT(start_blk <= INT_MAX &&
- (xfs_daddr_t) log_bbnum-start_blk >= 0);
- ASSERT(head_blk <= INT_MAX);
- error = xlog_find_verify_log_record(log, start_blk,
- &new_blk, (int)head_blk);
- if (error == 1)
- error = -EIO;
- if (error)
- goto bp_err;
- if (new_blk != log_bbnum)
- head_blk = new_blk;
- } else if (error)
- goto bp_err;
- }
- xlog_put_bp(bp);
- if (head_blk == log_bbnum)
- *return_head_blk = 0;
- else
- *return_head_blk = head_blk;
-
- return 0;
- bp_err:
- xlog_put_bp(bp);
- if (error)
- xfs_warn(log->l_mp, "failed to find log head");
- return error;
- }
- STATIC int
- xlog_rseek_logrec_hdr(
- struct xlog *log,
- xfs_daddr_t head_blk,
- xfs_daddr_t tail_blk,
- int count,
- struct xfs_buf *bp,
- xfs_daddr_t *rblk,
- struct xlog_rec_header **rhead,
- bool *wrapped)
- {
- int i;
- int error;
- int found = 0;
- char *offset = NULL;
- xfs_daddr_t end_blk;
- *wrapped = false;
-
- end_blk = head_blk > tail_blk ? tail_blk : 0;
- for (i = (int) head_blk - 1; i >= end_blk; i--) {
- error = xlog_bread(log, i, 1, bp, &offset);
- if (error)
- goto out_error;
- if (*(__be32 *) offset == cpu_to_be32(XLOG_HEADER_MAGIC_NUM)) {
- *rblk = i;
- *rhead = (struct xlog_rec_header *) offset;
- if (++found == count)
- break;
- }
- }
-
- if (tail_blk >= head_blk && found != count) {
- for (i = log->l_logBBsize - 1; i >= (int) tail_blk; i--) {
- error = xlog_bread(log, i, 1, bp, &offset);
- if (error)
- goto out_error;
- if (*(__be32 *)offset ==
- cpu_to_be32(XLOG_HEADER_MAGIC_NUM)) {
- *wrapped = true;
- *rblk = i;
- *rhead = (struct xlog_rec_header *) offset;
- if (++found == count)
- break;
- }
- }
- }
- return found;
- out_error:
- return error;
- }
- STATIC int
- xlog_seek_logrec_hdr(
- struct xlog *log,
- xfs_daddr_t head_blk,
- xfs_daddr_t tail_blk,
- int count,
- struct xfs_buf *bp,
- xfs_daddr_t *rblk,
- struct xlog_rec_header **rhead,
- bool *wrapped)
- {
- int i;
- int error;
- int found = 0;
- char *offset = NULL;
- xfs_daddr_t end_blk;
- *wrapped = false;
-
- end_blk = head_blk > tail_blk ? head_blk : log->l_logBBsize - 1;
- for (i = (int) tail_blk; i <= end_blk; i++) {
- error = xlog_bread(log, i, 1, bp, &offset);
- if (error)
- goto out_error;
- if (*(__be32 *) offset == cpu_to_be32(XLOG_HEADER_MAGIC_NUM)) {
- *rblk = i;
- *rhead = (struct xlog_rec_header *) offset;
- if (++found == count)
- break;
- }
- }
-
- if (tail_blk > head_blk && found != count) {
- for (i = 0; i < (int) head_blk; i++) {
- error = xlog_bread(log, i, 1, bp, &offset);
- if (error)
- goto out_error;
- if (*(__be32 *)offset ==
- cpu_to_be32(XLOG_HEADER_MAGIC_NUM)) {
- *wrapped = true;
- *rblk = i;
- *rhead = (struct xlog_rec_header *) offset;
- if (++found == count)
- break;
- }
- }
- }
- return found;
- out_error:
- return error;
- }
- static inline int
- xlog_tail_distance(
- struct xlog *log,
- xfs_daddr_t head_blk,
- xfs_daddr_t tail_blk)
- {
- if (head_blk < tail_blk)
- return tail_blk - head_blk;
- return tail_blk + (log->l_logBBsize - head_blk);
- }
- STATIC int
- xlog_verify_tail(
- struct xlog *log,
- xfs_daddr_t head_blk,
- xfs_daddr_t *tail_blk,
- int hsize)
- {
- struct xlog_rec_header *thead;
- struct xfs_buf *bp;
- xfs_daddr_t first_bad;
- int error = 0;
- bool wrapped;
- xfs_daddr_t tmp_tail;
- xfs_daddr_t orig_tail = *tail_blk;
- bp = xlog_get_bp(log, 1);
- if (!bp)
- return -ENOMEM;
-
- error = xlog_seek_logrec_hdr(log, head_blk, *tail_blk, 1, bp,
- &tmp_tail, &thead, &wrapped);
- if (error < 0)
- goto out;
- if (*tail_blk != tmp_tail)
- *tail_blk = tmp_tail;
-
- first_bad = 0;
- error = xlog_do_recovery_pass(log, head_blk, *tail_blk,
- XLOG_RECOVER_CRCPASS, &first_bad);
- while ((error == -EFSBADCRC || error == -EFSCORRUPTED) && first_bad) {
- int tail_distance;
-
- tail_distance = xlog_tail_distance(log, head_blk, first_bad);
- if (tail_distance > BTOBB(XLOG_MAX_ICLOGS * hsize))
- break;
-
- error = xlog_seek_logrec_hdr(log, head_blk, first_bad, 2, bp,
- &tmp_tail, &thead, &wrapped);
- if (error < 0)
- goto out;
- *tail_blk = tmp_tail;
- first_bad = 0;
- error = xlog_do_recovery_pass(log, head_blk, *tail_blk,
- XLOG_RECOVER_CRCPASS, &first_bad);
- }
- if (!error && *tail_blk != orig_tail)
- xfs_warn(log->l_mp,
- "Tail block (0x%llx) overwrite detected. Updated to 0x%llx",
- orig_tail, *tail_blk);
- out:
- xlog_put_bp(bp);
- return error;
- }
- STATIC int
- xlog_verify_head(
- struct xlog *log,
- xfs_daddr_t *head_blk,
- xfs_daddr_t *tail_blk,
- struct xfs_buf *bp,
- xfs_daddr_t *rhead_blk,
- struct xlog_rec_header **rhead,
- bool *wrapped)
- {
- struct xlog_rec_header *tmp_rhead;
- struct xfs_buf *tmp_bp;
- xfs_daddr_t first_bad;
- xfs_daddr_t tmp_rhead_blk;
- int found;
- int error;
- bool tmp_wrapped;
-
- tmp_bp = xlog_get_bp(log, 1);
- if (!tmp_bp)
- return -ENOMEM;
- error = xlog_rseek_logrec_hdr(log, *head_blk, *tail_blk,
- XLOG_MAX_ICLOGS, tmp_bp, &tmp_rhead_blk,
- &tmp_rhead, &tmp_wrapped);
- xlog_put_bp(tmp_bp);
- if (error < 0)
- return error;
-
- error = xlog_do_recovery_pass(log, *head_blk, tmp_rhead_blk,
- XLOG_RECOVER_CRCPASS, &first_bad);
- if ((error == -EFSBADCRC || error == -EFSCORRUPTED) && first_bad) {
-
- error = 0;
- xfs_warn(log->l_mp,
- "Torn write (CRC failure) detected at log block 0x%llx. Truncating head block from 0x%llx.",
- first_bad, *head_blk);
-
- found = xlog_rseek_logrec_hdr(log, first_bad, *tail_blk, 1, bp,
- rhead_blk, rhead, wrapped);
- if (found < 0)
- return found;
- if (found == 0)
- return -EIO;
-
- *head_blk = first_bad;
- *tail_blk = BLOCK_LSN(be64_to_cpu((*rhead)->h_tail_lsn));
- if (*head_blk == *tail_blk) {
- ASSERT(0);
- return 0;
- }
- }
- if (error)
- return error;
- return xlog_verify_tail(log, *head_blk, tail_blk,
- be32_to_cpu((*rhead)->h_size));
- }
- static int
- xlog_check_unmount_rec(
- struct xlog *log,
- xfs_daddr_t *head_blk,
- xfs_daddr_t *tail_blk,
- struct xlog_rec_header *rhead,
- xfs_daddr_t rhead_blk,
- struct xfs_buf *bp,
- bool *clean)
- {
- struct xlog_op_header *op_head;
- xfs_daddr_t umount_data_blk;
- xfs_daddr_t after_umount_blk;
- int hblks;
- int error;
- char *offset;
- *clean = false;
-
- if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
- int h_size = be32_to_cpu(rhead->h_size);
- int h_version = be32_to_cpu(rhead->h_version);
- if ((h_version & XLOG_VERSION_2) &&
- (h_size > XLOG_HEADER_CYCLE_SIZE)) {
- hblks = h_size / XLOG_HEADER_CYCLE_SIZE;
- if (h_size % XLOG_HEADER_CYCLE_SIZE)
- hblks++;
- } else {
- hblks = 1;
- }
- } else {
- hblks = 1;
- }
- after_umount_blk = rhead_blk + hblks + BTOBB(be32_to_cpu(rhead->h_len));
- after_umount_blk = do_mod(after_umount_blk, log->l_logBBsize);
- if (*head_blk == after_umount_blk &&
- be32_to_cpu(rhead->h_num_logops) == 1) {
- umount_data_blk = rhead_blk + hblks;
- umount_data_blk = do_mod(umount_data_blk, log->l_logBBsize);
- error = xlog_bread(log, umount_data_blk, 1, bp, &offset);
- if (error)
- return error;
- op_head = (struct xlog_op_header *)offset;
- if (op_head->oh_flags & XLOG_UNMOUNT_TRANS) {
-
- xlog_assign_atomic_lsn(&log->l_tail_lsn,
- log->l_curr_cycle, after_umount_blk);
- xlog_assign_atomic_lsn(&log->l_last_sync_lsn,
- log->l_curr_cycle, after_umount_blk);
- *tail_blk = after_umount_blk;
- *clean = true;
- }
- }
- return 0;
- }
- static void
- xlog_set_state(
- struct xlog *log,
- xfs_daddr_t head_blk,
- struct xlog_rec_header *rhead,
- xfs_daddr_t rhead_blk,
- bool bump_cycle)
- {
-
- log->l_prev_block = rhead_blk;
- log->l_curr_block = (int)head_blk;
- log->l_curr_cycle = be32_to_cpu(rhead->h_cycle);
- if (bump_cycle)
- log->l_curr_cycle++;
- atomic64_set(&log->l_tail_lsn, be64_to_cpu(rhead->h_tail_lsn));
- atomic64_set(&log->l_last_sync_lsn, be64_to_cpu(rhead->h_lsn));
- xlog_assign_grant_head(&log->l_reserve_head.grant, log->l_curr_cycle,
- BBTOB(log->l_curr_block));
- xlog_assign_grant_head(&log->l_write_head.grant, log->l_curr_cycle,
- BBTOB(log->l_curr_block));
- }
- STATIC int
- xlog_find_tail(
- struct xlog *log,
- xfs_daddr_t *head_blk,
- xfs_daddr_t *tail_blk)
- {
- xlog_rec_header_t *rhead;
- char *offset = NULL;
- xfs_buf_t *bp;
- int error;
- xfs_daddr_t rhead_blk;
- xfs_lsn_t tail_lsn;
- bool wrapped = false;
- bool clean = false;
-
- if ((error = xlog_find_head(log, head_blk)))
- return error;
- ASSERT(*head_blk < INT_MAX);
- bp = xlog_get_bp(log, 1);
- if (!bp)
- return -ENOMEM;
- if (*head_blk == 0) {
- error = xlog_bread(log, 0, 1, bp, &offset);
- if (error)
- goto done;
- if (xlog_get_cycle(offset) == 0) {
- *tail_blk = 0;
-
- goto done;
- }
- }
-
- error = xlog_rseek_logrec_hdr(log, *head_blk, *head_blk, 1, bp,
- &rhead_blk, &rhead, &wrapped);
- if (error < 0)
- return error;
- if (!error) {
- xfs_warn(log->l_mp, "%s: couldn't find sync record", __func__);
- return -EIO;
- }
- *tail_blk = BLOCK_LSN(be64_to_cpu(rhead->h_tail_lsn));
-
- xlog_set_state(log, *head_blk, rhead, rhead_blk, wrapped);
- tail_lsn = atomic64_read(&log->l_tail_lsn);
-
- error = xlog_check_unmount_rec(log, head_blk, tail_blk, rhead,
- rhead_blk, bp, &clean);
- if (error)
- goto done;
-
- if (!clean) {
- xfs_daddr_t orig_head = *head_blk;
- error = xlog_verify_head(log, head_blk, tail_blk, bp,
- &rhead_blk, &rhead, &wrapped);
- if (error)
- goto done;
-
- if (*head_blk != orig_head) {
- xlog_set_state(log, *head_blk, rhead, rhead_blk,
- wrapped);
- tail_lsn = atomic64_read(&log->l_tail_lsn);
- error = xlog_check_unmount_rec(log, head_blk, tail_blk,
- rhead, rhead_blk, bp,
- &clean);
- if (error)
- goto done;
- }
- }
-
- if (clean)
- log->l_mp->m_flags |= XFS_MOUNT_WAS_CLEAN;
-
- if (!xfs_readonly_buftarg(log->l_mp->m_logdev_targp))
- error = xlog_clear_stale_blocks(log, tail_lsn);
- done:
- xlog_put_bp(bp);
- if (error)
- xfs_warn(log->l_mp, "failed to locate log tail");
- return error;
- }
- STATIC int
- xlog_find_zeroed(
- struct xlog *log,
- xfs_daddr_t *blk_no)
- {
- xfs_buf_t *bp;
- char *offset;
- uint first_cycle, last_cycle;
- xfs_daddr_t new_blk, last_blk, start_blk;
- xfs_daddr_t num_scan_bblks;
- int error, log_bbnum = log->l_logBBsize;
- *blk_no = 0;
-
- bp = xlog_get_bp(log, 1);
- if (!bp)
- return -ENOMEM;
- error = xlog_bread(log, 0, 1, bp, &offset);
- if (error)
- goto bp_err;
- first_cycle = xlog_get_cycle(offset);
- if (first_cycle == 0) {
- *blk_no = 0;
- xlog_put_bp(bp);
- return 1;
- }
-
- error = xlog_bread(log, log_bbnum-1, 1, bp, &offset);
- if (error)
- goto bp_err;
- last_cycle = xlog_get_cycle(offset);
- if (last_cycle != 0) {
- xlog_put_bp(bp);
- return 0;
- } else if (first_cycle != 1) {
-
- xfs_warn(log->l_mp,
- "Log inconsistent or not a log (last==0, first!=1)");
- error = -EINVAL;
- goto bp_err;
- }
-
- last_blk = log_bbnum-1;
- if ((error = xlog_find_cycle_start(log, bp, 0, &last_blk, 0)))
- goto bp_err;
-
- num_scan_bblks = XLOG_TOTAL_REC_SHIFT(log);
- ASSERT(num_scan_bblks <= INT_MAX);
- if (last_blk < num_scan_bblks)
- num_scan_bblks = last_blk;
- start_blk = last_blk - num_scan_bblks;
-
- if ((error = xlog_find_verify_cycle(log, start_blk,
- (int)num_scan_bblks, 0, &new_blk)))
- goto bp_err;
- if (new_blk != -1)
- last_blk = new_blk;
-
- error = xlog_find_verify_log_record(log, start_blk, &last_blk, 0);
- if (error == 1)
- error = -EIO;
- if (error)
- goto bp_err;
- *blk_no = last_blk;
- bp_err:
- xlog_put_bp(bp);
- if (error)
- return error;
- return 1;
- }
- STATIC void
- xlog_add_record(
- struct xlog *log,
- char *buf,
- int cycle,
- int block,
- int tail_cycle,
- int tail_block)
- {
- xlog_rec_header_t *recp = (xlog_rec_header_t *)buf;
- memset(buf, 0, BBSIZE);
- recp->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
- recp->h_cycle = cpu_to_be32(cycle);
- recp->h_version = cpu_to_be32(
- xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? 2 : 1);
- recp->h_lsn = cpu_to_be64(xlog_assign_lsn(cycle, block));
- recp->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(tail_cycle, tail_block));
- recp->h_fmt = cpu_to_be32(XLOG_FMT);
- memcpy(&recp->h_fs_uuid, &log->l_mp->m_sb.sb_uuid, sizeof(uuid_t));
- }
- STATIC int
- xlog_write_log_records(
- struct xlog *log,
- int cycle,
- int start_block,
- int blocks,
- int tail_cycle,
- int tail_block)
- {
- char *offset;
- xfs_buf_t *bp;
- int balign, ealign;
- int sectbb = log->l_sectBBsize;
- int end_block = start_block + blocks;
- int bufblks;
- int error = 0;
- int i, j = 0;
-
- bufblks = 1 << ffs(blocks);
- while (bufblks > log->l_logBBsize)
- bufblks >>= 1;
- while (!(bp = xlog_get_bp(log, bufblks))) {
- bufblks >>= 1;
- if (bufblks < sectbb)
- return -ENOMEM;
- }
-
- balign = round_down(start_block, sectbb);
- if (balign != start_block) {
- error = xlog_bread_noalign(log, start_block, 1, bp);
- if (error)
- goto out_put_bp;
- j = start_block - balign;
- }
- for (i = start_block; i < end_block; i += bufblks) {
- int bcount, endcount;
- bcount = min(bufblks, end_block - start_block);
- endcount = bcount - j;
-
- ealign = round_down(end_block, sectbb);
- if (j == 0 && (start_block + endcount > ealign)) {
- offset = bp->b_addr + BBTOB(ealign - start_block);
- error = xlog_bread_offset(log, ealign, sectbb,
- bp, offset);
- if (error)
- break;
- }
- offset = xlog_align(log, start_block, endcount, bp);
- for (; j < endcount; j++) {
- xlog_add_record(log, offset, cycle, i+j,
- tail_cycle, tail_block);
- offset += BBSIZE;
- }
- error = xlog_bwrite(log, start_block, endcount, bp);
- if (error)
- break;
- start_block += endcount;
- j = 0;
- }
- out_put_bp:
- xlog_put_bp(bp);
- return error;
- }
- STATIC int
- xlog_clear_stale_blocks(
- struct xlog *log,
- xfs_lsn_t tail_lsn)
- {
- int tail_cycle, head_cycle;
- int tail_block, head_block;
- int tail_distance, max_distance;
- int distance;
- int error;
- tail_cycle = CYCLE_LSN(tail_lsn);
- tail_block = BLOCK_LSN(tail_lsn);
- head_cycle = log->l_curr_cycle;
- head_block = log->l_curr_block;
-
- if (head_cycle == tail_cycle) {
-
- if (unlikely(head_block < tail_block || head_block >= log->l_logBBsize)) {
- XFS_ERROR_REPORT("xlog_clear_stale_blocks(1)",
- XFS_ERRLEVEL_LOW, log->l_mp);
- return -EFSCORRUPTED;
- }
- tail_distance = tail_block + (log->l_logBBsize - head_block);
- } else {
-
- if (unlikely(head_block >= tail_block || head_cycle != (tail_cycle + 1))){
- XFS_ERROR_REPORT("xlog_clear_stale_blocks(2)",
- XFS_ERRLEVEL_LOW, log->l_mp);
- return -EFSCORRUPTED;
- }
- tail_distance = tail_block - head_block;
- }
-
- if (tail_distance <= 0) {
- ASSERT(tail_distance == 0);
- return 0;
- }
- max_distance = XLOG_TOTAL_REC_SHIFT(log);
-
- max_distance = MIN(max_distance, tail_distance);
- if ((head_block + max_distance) <= log->l_logBBsize) {
-
- error = xlog_write_log_records(log, (head_cycle - 1),
- head_block, max_distance, tail_cycle,
- tail_block);
- if (error)
- return error;
- } else {
-
- distance = log->l_logBBsize - head_block;
- error = xlog_write_log_records(log, (head_cycle - 1),
- head_block, distance, tail_cycle,
- tail_block);
- if (error)
- return error;
-
- distance = max_distance - (log->l_logBBsize - head_block);
- error = xlog_write_log_records(log, head_cycle, 0, distance,
- tail_cycle, tail_block);
- if (error)
- return error;
- }
- return 0;
- }
- STATIC int
- xlog_recover_reorder_trans(
- struct xlog *log,
- struct xlog_recover *trans,
- int pass)
- {
- xlog_recover_item_t *item, *n;
- int error = 0;
- LIST_HEAD(sort_list);
- LIST_HEAD(cancel_list);
- LIST_HEAD(buffer_list);
- LIST_HEAD(inode_buffer_list);
- LIST_HEAD(inode_list);
- list_splice_init(&trans->r_itemq, &sort_list);
- list_for_each_entry_safe(item, n, &sort_list, ri_list) {
- xfs_buf_log_format_t *buf_f = item->ri_buf[0].i_addr;
- switch (ITEM_TYPE(item)) {
- case XFS_LI_ICREATE:
- list_move_tail(&item->ri_list, &buffer_list);
- break;
- case XFS_LI_BUF:
- if (buf_f->blf_flags & XFS_BLF_CANCEL) {
- trace_xfs_log_recover_item_reorder_head(log,
- trans, item, pass);
- list_move(&item->ri_list, &cancel_list);
- break;
- }
- if (buf_f->blf_flags & XFS_BLF_INODE_BUF) {
- list_move(&item->ri_list, &inode_buffer_list);
- break;
- }
- list_move_tail(&item->ri_list, &buffer_list);
- break;
- case XFS_LI_INODE:
- case XFS_LI_DQUOT:
- case XFS_LI_QUOTAOFF:
- case XFS_LI_EFD:
- case XFS_LI_EFI:
- case XFS_LI_RUI:
- case XFS_LI_RUD:
- case XFS_LI_CUI:
- case XFS_LI_CUD:
- case XFS_LI_BUI:
- case XFS_LI_BUD:
- trace_xfs_log_recover_item_reorder_tail(log,
- trans, item, pass);
- list_move_tail(&item->ri_list, &inode_list);
- break;
- default:
- xfs_warn(log->l_mp,
- "%s: unrecognized type of log operation",
- __func__);
- ASSERT(0);
-
- if (!list_empty(&sort_list))
- list_splice_init(&sort_list, &trans->r_itemq);
- error = -EIO;
- goto out;
- }
- }
- out:
- ASSERT(list_empty(&sort_list));
- if (!list_empty(&buffer_list))
- list_splice(&buffer_list, &trans->r_itemq);
- if (!list_empty(&inode_list))
- list_splice_tail(&inode_list, &trans->r_itemq);
- if (!list_empty(&inode_buffer_list))
- list_splice_tail(&inode_buffer_list, &trans->r_itemq);
- if (!list_empty(&cancel_list))
- list_splice_tail(&cancel_list, &trans->r_itemq);
- return error;
- }
- STATIC int
- xlog_recover_buffer_pass1(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- xfs_buf_log_format_t *buf_f = item->ri_buf[0].i_addr;
- struct list_head *bucket;
- struct xfs_buf_cancel *bcp;
-
- if (!(buf_f->blf_flags & XFS_BLF_CANCEL)) {
- trace_xfs_log_recover_buf_not_cancel(log, buf_f);
- return 0;
- }
-
- bucket = XLOG_BUF_CANCEL_BUCKET(log, buf_f->blf_blkno);
- list_for_each_entry(bcp, bucket, bc_list) {
- if (bcp->bc_blkno == buf_f->blf_blkno &&
- bcp->bc_len == buf_f->blf_len) {
- bcp->bc_refcount++;
- trace_xfs_log_recover_buf_cancel_ref_inc(log, buf_f);
- return 0;
- }
- }
- bcp = kmem_alloc(sizeof(struct xfs_buf_cancel), KM_SLEEP);
- bcp->bc_blkno = buf_f->blf_blkno;
- bcp->bc_len = buf_f->blf_len;
- bcp->bc_refcount = 1;
- list_add_tail(&bcp->bc_list, bucket);
- trace_xfs_log_recover_buf_cancel_add(log, buf_f);
- return 0;
- }
- STATIC struct xfs_buf_cancel *
- xlog_peek_buffer_cancelled(
- struct xlog *log,
- xfs_daddr_t blkno,
- uint len,
- ushort flags)
- {
- struct list_head *bucket;
- struct xfs_buf_cancel *bcp;
- if (!log->l_buf_cancel_table) {
-
- ASSERT(!(flags & XFS_BLF_CANCEL));
- return NULL;
- }
- bucket = XLOG_BUF_CANCEL_BUCKET(log, blkno);
- list_for_each_entry(bcp, bucket, bc_list) {
- if (bcp->bc_blkno == blkno && bcp->bc_len == len)
- return bcp;
- }
-
- ASSERT(!(flags & XFS_BLF_CANCEL));
- return NULL;
- }
- STATIC int
- xlog_check_buffer_cancelled(
- struct xlog *log,
- xfs_daddr_t blkno,
- uint len,
- ushort flags)
- {
- struct xfs_buf_cancel *bcp;
- bcp = xlog_peek_buffer_cancelled(log, blkno, len, flags);
- if (!bcp)
- return 0;
-
- if (flags & XFS_BLF_CANCEL) {
- if (--bcp->bc_refcount == 0) {
- list_del(&bcp->bc_list);
- kmem_free(bcp);
- }
- }
- return 1;
- }
- STATIC int
- xlog_recover_do_inode_buffer(
- struct xfs_mount *mp,
- xlog_recover_item_t *item,
- struct xfs_buf *bp,
- xfs_buf_log_format_t *buf_f)
- {
- int i;
- int item_index = 0;
- int bit = 0;
- int nbits = 0;
- int reg_buf_offset = 0;
- int reg_buf_bytes = 0;
- int next_unlinked_offset;
- int inodes_per_buf;
- xfs_agino_t *logged_nextp;
- xfs_agino_t *buffer_nextp;
- trace_xfs_log_recover_buf_inode_buf(mp->m_log, buf_f);
-
- if (xfs_sb_version_hascrc(&mp->m_sb))
- bp->b_ops = &xfs_inode_buf_ops;
- inodes_per_buf = BBTOB(bp->b_io_length) >> mp->m_sb.sb_inodelog;
- for (i = 0; i < inodes_per_buf; i++) {
- next_unlinked_offset = (i * mp->m_sb.sb_inodesize) +
- offsetof(xfs_dinode_t, di_next_unlinked);
- while (next_unlinked_offset >=
- (reg_buf_offset + reg_buf_bytes)) {
-
- bit += nbits;
- bit = xfs_next_bit(buf_f->blf_data_map,
- buf_f->blf_map_size, bit);
-
- if (bit == -1)
- return 0;
- nbits = xfs_contig_bits(buf_f->blf_data_map,
- buf_f->blf_map_size, bit);
- ASSERT(nbits > 0);
- reg_buf_offset = bit << XFS_BLF_SHIFT;
- reg_buf_bytes = nbits << XFS_BLF_SHIFT;
- item_index++;
- }
-
- if (next_unlinked_offset < reg_buf_offset)
- continue;
- ASSERT(item->ri_buf[item_index].i_addr != NULL);
- ASSERT((item->ri_buf[item_index].i_len % XFS_BLF_CHUNK) == 0);
- ASSERT((reg_buf_offset + reg_buf_bytes) <=
- BBTOB(bp->b_io_length));
-
- logged_nextp = item->ri_buf[item_index].i_addr +
- next_unlinked_offset - reg_buf_offset;
- if (unlikely(*logged_nextp == 0)) {
- xfs_alert(mp,
- "Bad inode buffer log record (ptr = 0x%p, bp = 0x%p). "
- "Trying to replay bad (0) inode di_next_unlinked field.",
- item, bp);
- XFS_ERROR_REPORT("xlog_recover_do_inode_buf",
- XFS_ERRLEVEL_LOW, mp);
- return -EFSCORRUPTED;
- }
- buffer_nextp = xfs_buf_offset(bp, next_unlinked_offset);
- *buffer_nextp = *logged_nextp;
-
- xfs_dinode_calc_crc(mp,
- xfs_buf_offset(bp, i * mp->m_sb.sb_inodesize));
- }
- return 0;
- }
- static xfs_lsn_t
- xlog_recover_get_buf_lsn(
- struct xfs_mount *mp,
- struct xfs_buf *bp)
- {
- __uint32_t magic32;
- __uint16_t magic16;
- __uint16_t magicda;
- void *blk = bp->b_addr;
- uuid_t *uuid;
- xfs_lsn_t lsn = -1;
-
- if (!xfs_sb_version_hascrc(&mp->m_sb))
- goto recover_immediately;
- magic32 = be32_to_cpu(*(__be32 *)blk);
- switch (magic32) {
- case XFS_ABTB_CRC_MAGIC:
- case XFS_ABTC_CRC_MAGIC:
- case XFS_ABTB_MAGIC:
- case XFS_ABTC_MAGIC:
- case XFS_RMAP_CRC_MAGIC:
- case XFS_REFC_CRC_MAGIC:
- case XFS_IBT_CRC_MAGIC:
- case XFS_IBT_MAGIC: {
- struct xfs_btree_block *btb = blk;
- lsn = be64_to_cpu(btb->bb_u.s.bb_lsn);
- uuid = &btb->bb_u.s.bb_uuid;
- break;
- }
- case XFS_BMAP_CRC_MAGIC:
- case XFS_BMAP_MAGIC: {
- struct xfs_btree_block *btb = blk;
- lsn = be64_to_cpu(btb->bb_u.l.bb_lsn);
- uuid = &btb->bb_u.l.bb_uuid;
- break;
- }
- case XFS_AGF_MAGIC:
- lsn = be64_to_cpu(((struct xfs_agf *)blk)->agf_lsn);
- uuid = &((struct xfs_agf *)blk)->agf_uuid;
- break;
- case XFS_AGFL_MAGIC:
- lsn = be64_to_cpu(((struct xfs_agfl *)blk)->agfl_lsn);
- uuid = &((struct xfs_agfl *)blk)->agfl_uuid;
- break;
- case XFS_AGI_MAGIC:
- lsn = be64_to_cpu(((struct xfs_agi *)blk)->agi_lsn);
- uuid = &((struct xfs_agi *)blk)->agi_uuid;
- break;
- case XFS_SYMLINK_MAGIC:
- lsn = be64_to_cpu(((struct xfs_dsymlink_hdr *)blk)->sl_lsn);
- uuid = &((struct xfs_dsymlink_hdr *)blk)->sl_uuid;
- break;
- case XFS_DIR3_BLOCK_MAGIC:
- case XFS_DIR3_DATA_MAGIC:
- case XFS_DIR3_FREE_MAGIC:
- lsn = be64_to_cpu(((struct xfs_dir3_blk_hdr *)blk)->lsn);
- uuid = &((struct xfs_dir3_blk_hdr *)blk)->uuid;
- break;
- case XFS_ATTR3_RMT_MAGIC:
-
- goto recover_immediately;
- case XFS_SB_MAGIC:
-
- lsn = be64_to_cpu(((struct xfs_dsb *)blk)->sb_lsn);
- if (xfs_sb_version_hasmetauuid(&mp->m_sb))
- uuid = &((struct xfs_dsb *)blk)->sb_meta_uuid;
- else
- uuid = &((struct xfs_dsb *)blk)->sb_uuid;
- break;
- default:
- break;
- }
- if (lsn != (xfs_lsn_t)-1) {
- if (!uuid_equal(&mp->m_sb.sb_meta_uuid, uuid))
- goto recover_immediately;
- return lsn;
- }
- magicda = be16_to_cpu(((struct xfs_da_blkinfo *)blk)->magic);
- switch (magicda) {
- case XFS_DIR3_LEAF1_MAGIC:
- case XFS_DIR3_LEAFN_MAGIC:
- case XFS_DA3_NODE_MAGIC:
- lsn = be64_to_cpu(((struct xfs_da3_blkinfo *)blk)->lsn);
- uuid = &((struct xfs_da3_blkinfo *)blk)->uuid;
- break;
- default:
- break;
- }
- if (lsn != (xfs_lsn_t)-1) {
- if (!uuid_equal(&mp->m_sb.sb_uuid, uuid))
- goto recover_immediately;
- return lsn;
- }
-
- magic16 = be16_to_cpu(*(__be16 *)blk);
- switch (magic16) {
- case XFS_DQUOT_MAGIC:
- case XFS_DINODE_MAGIC:
- goto recover_immediately;
- default:
- break;
- }
-
- recover_immediately:
- return (xfs_lsn_t)-1;
- }
- static void
- xlog_recover_validate_buf_type(
- struct xfs_mount *mp,
- struct xfs_buf *bp,
- xfs_buf_log_format_t *buf_f,
- xfs_lsn_t current_lsn)
- {
- struct xfs_da_blkinfo *info = bp->b_addr;
- __uint32_t magic32;
- __uint16_t magic16;
- __uint16_t magicda;
- char *warnmsg = NULL;
-
- if (!xfs_sb_version_hascrc(&mp->m_sb))
- return;
- magic32 = be32_to_cpu(*(__be32 *)bp->b_addr);
- magic16 = be16_to_cpu(*(__be16*)bp->b_addr);
- magicda = be16_to_cpu(info->magic);
- switch (xfs_blft_from_flags(buf_f)) {
- case XFS_BLFT_BTREE_BUF:
- switch (magic32) {
- case XFS_ABTB_CRC_MAGIC:
- case XFS_ABTC_CRC_MAGIC:
- case XFS_ABTB_MAGIC:
- case XFS_ABTC_MAGIC:
- bp->b_ops = &xfs_allocbt_buf_ops;
- break;
- case XFS_IBT_CRC_MAGIC:
- case XFS_FIBT_CRC_MAGIC:
- case XFS_IBT_MAGIC:
- case XFS_FIBT_MAGIC:
- bp->b_ops = &xfs_inobt_buf_ops;
- break;
- case XFS_BMAP_CRC_MAGIC:
- case XFS_BMAP_MAGIC:
- bp->b_ops = &xfs_bmbt_buf_ops;
- break;
- case XFS_RMAP_CRC_MAGIC:
- bp->b_ops = &xfs_rmapbt_buf_ops;
- break;
- case XFS_REFC_CRC_MAGIC:
- bp->b_ops = &xfs_refcountbt_buf_ops;
- break;
- default:
- warnmsg = "Bad btree block magic!";
- break;
- }
- break;
- case XFS_BLFT_AGF_BUF:
- if (magic32 != XFS_AGF_MAGIC) {
- warnmsg = "Bad AGF block magic!";
- break;
- }
- bp->b_ops = &xfs_agf_buf_ops;
- break;
- case XFS_BLFT_AGFL_BUF:
- if (magic32 != XFS_AGFL_MAGIC) {
- warnmsg = "Bad AGFL block magic!";
- break;
- }
- bp->b_ops = &xfs_agfl_buf_ops;
- break;
- case XFS_BLFT_AGI_BUF:
- if (magic32 != XFS_AGI_MAGIC) {
- warnmsg = "Bad AGI block magic!";
- break;
- }
- bp->b_ops = &xfs_agi_buf_ops;
- break;
- case XFS_BLFT_UDQUOT_BUF:
- case XFS_BLFT_PDQUOT_BUF:
- case XFS_BLFT_GDQUOT_BUF:
- #ifdef CONFIG_XFS_QUOTA
- if (magic16 != XFS_DQUOT_MAGIC) {
- warnmsg = "Bad DQUOT block magic!";
- break;
- }
- bp->b_ops = &xfs_dquot_buf_ops;
- #else
- xfs_alert(mp,
- "Trying to recover dquots without QUOTA support built in!");
- ASSERT(0);
- #endif
- break;
- case XFS_BLFT_DINO_BUF:
- if (magic16 != XFS_DINODE_MAGIC) {
- warnmsg = "Bad INODE block magic!";
- break;
- }
- bp->b_ops = &xfs_inode_buf_ops;
- break;
- case XFS_BLFT_SYMLINK_BUF:
- if (magic32 != XFS_SYMLINK_MAGIC) {
- warnmsg = "Bad symlink block magic!";
- break;
- }
- bp->b_ops = &xfs_symlink_buf_ops;
- break;
- case XFS_BLFT_DIR_BLOCK_BUF:
- if (magic32 != XFS_DIR2_BLOCK_MAGIC &&
- magic32 != XFS_DIR3_BLOCK_MAGIC) {
- warnmsg = "Bad dir block magic!";
- break;
- }
- bp->b_ops = &xfs_dir3_block_buf_ops;
- break;
- case XFS_BLFT_DIR_DATA_BUF:
- if (magic32 != XFS_DIR2_DATA_MAGIC &&
- magic32 != XFS_DIR3_DATA_MAGIC) {
- warnmsg = "Bad dir data magic!";
- break;
- }
- bp->b_ops = &xfs_dir3_data_buf_ops;
- break;
- case XFS_BLFT_DIR_FREE_BUF:
- if (magic32 != XFS_DIR2_FREE_MAGIC &&
- magic32 != XFS_DIR3_FREE_MAGIC) {
- warnmsg = "Bad dir3 free magic!";
- break;
- }
- bp->b_ops = &xfs_dir3_free_buf_ops;
- break;
- case XFS_BLFT_DIR_LEAF1_BUF:
- if (magicda != XFS_DIR2_LEAF1_MAGIC &&
- magicda != XFS_DIR3_LEAF1_MAGIC) {
- warnmsg = "Bad dir leaf1 magic!";
- break;
- }
- bp->b_ops = &xfs_dir3_leaf1_buf_ops;
- break;
- case XFS_BLFT_DIR_LEAFN_BUF:
- if (magicda != XFS_DIR2_LEAFN_MAGIC &&
- magicda != XFS_DIR3_LEAFN_MAGIC) {
- warnmsg = "Bad dir leafn magic!";
- break;
- }
- bp->b_ops = &xfs_dir3_leafn_buf_ops;
- break;
- case XFS_BLFT_DA_NODE_BUF:
- if (magicda != XFS_DA_NODE_MAGIC &&
- magicda != XFS_DA3_NODE_MAGIC) {
- warnmsg = "Bad da node magic!";
- break;
- }
- bp->b_ops = &xfs_da3_node_buf_ops;
- break;
- case XFS_BLFT_ATTR_LEAF_BUF:
- if (magicda != XFS_ATTR_LEAF_MAGIC &&
- magicda != XFS_ATTR3_LEAF_MAGIC) {
- warnmsg = "Bad attr leaf magic!";
- break;
- }
- bp->b_ops = &xfs_attr3_leaf_buf_ops;
- break;
- case XFS_BLFT_ATTR_RMT_BUF:
- if (magic32 != XFS_ATTR3_RMT_MAGIC) {
- warnmsg = "Bad attr remote magic!";
- break;
- }
- bp->b_ops = &xfs_attr3_rmt_buf_ops;
- break;
- case XFS_BLFT_SB_BUF:
- if (magic32 != XFS_SB_MAGIC) {
- warnmsg = "Bad SB block magic!";
- break;
- }
- bp->b_ops = &xfs_sb_buf_ops;
- break;
- #ifdef CONFIG_XFS_RT
- case XFS_BLFT_RTBITMAP_BUF:
- case XFS_BLFT_RTSUMMARY_BUF:
-
- bp->b_ops = &xfs_rtbuf_ops;
- break;
- #endif
- default:
- xfs_warn(mp, "Unknown buffer type %d!",
- xfs_blft_from_flags(buf_f));
- break;
- }
-
- if (current_lsn == NULLCOMMITLSN)
- return;
- if (warnmsg) {
- xfs_warn(mp, warnmsg);
- ASSERT(0);
- }
-
- if (bp->b_ops) {
- struct xfs_buf_log_item *bip;
- ASSERT(!bp->b_iodone || bp->b_iodone == xlog_recover_iodone);
- bp->b_iodone = xlog_recover_iodone;
- xfs_buf_item_init(bp, mp);
- bip = bp->b_fspriv;
- bip->bli_item.li_lsn = current_lsn;
- }
- }
- STATIC void
- xlog_recover_do_reg_buffer(
- struct xfs_mount *mp,
- xlog_recover_item_t *item,
- struct xfs_buf *bp,
- xfs_buf_log_format_t *buf_f,
- xfs_lsn_t current_lsn)
- {
- int i;
- int bit;
- int nbits;
- int error;
- trace_xfs_log_recover_buf_reg_buf(mp->m_log, buf_f);
- bit = 0;
- i = 1;
- while (1) {
- bit = xfs_next_bit(buf_f->blf_data_map,
- buf_f->blf_map_size, bit);
- if (bit == -1)
- break;
- nbits = xfs_contig_bits(buf_f->blf_data_map,
- buf_f->blf_map_size, bit);
- ASSERT(nbits > 0);
- ASSERT(item->ri_buf[i].i_addr != NULL);
- ASSERT(item->ri_buf[i].i_len % XFS_BLF_CHUNK == 0);
- ASSERT(BBTOB(bp->b_io_length) >=
- ((uint)bit << XFS_BLF_SHIFT) + (nbits << XFS_BLF_SHIFT));
-
- if (item->ri_buf[i].i_len < (nbits << XFS_BLF_SHIFT))
- nbits = item->ri_buf[i].i_len >> XFS_BLF_SHIFT;
-
- error = 0;
- if (buf_f->blf_flags &
- (XFS_BLF_UDQUOT_BUF|XFS_BLF_PDQUOT_BUF|XFS_BLF_GDQUOT_BUF)) {
- if (item->ri_buf[i].i_addr == NULL) {
- xfs_alert(mp,
- "XFS: NULL dquot in %s.", __func__);
- goto next;
- }
- if (item->ri_buf[i].i_len < sizeof(xfs_disk_dquot_t)) {
- xfs_alert(mp,
- "XFS: dquot too small (%d) in %s.",
- item->ri_buf[i].i_len, __func__);
- goto next;
- }
- error = xfs_dqcheck(mp, item->ri_buf[i].i_addr,
- -1, 0, XFS_QMOPT_DOWARN,
- "dquot_buf_recover");
- if (error)
- goto next;
- }
- memcpy(xfs_buf_offset(bp,
- (uint)bit << XFS_BLF_SHIFT),
- item->ri_buf[i].i_addr,
- nbits<<XFS_BLF_SHIFT);
- next:
- i++;
- bit += nbits;
- }
-
- ASSERT(i == item->ri_total);
- xlog_recover_validate_buf_type(mp, bp, buf_f, current_lsn);
- }
- STATIC bool
- xlog_recover_do_dquot_buffer(
- struct xfs_mount *mp,
- struct xlog *log,
- struct xlog_recover_item *item,
- struct xfs_buf *bp,
- struct xfs_buf_log_format *buf_f)
- {
- uint type;
- trace_xfs_log_recover_buf_dquot_buf(log, buf_f);
-
- if (!mp->m_qflags)
- return false;
- type = 0;
- if (buf_f->blf_flags & XFS_BLF_UDQUOT_BUF)
- type |= XFS_DQ_USER;
- if (buf_f->blf_flags & XFS_BLF_PDQUOT_BUF)
- type |= XFS_DQ_PROJ;
- if (buf_f->blf_flags & XFS_BLF_GDQUOT_BUF)
- type |= XFS_DQ_GROUP;
-
- if (log->l_quotaoffs_flag & type)
- return false;
- xlog_recover_do_reg_buffer(mp, item, bp, buf_f, NULLCOMMITLSN);
- return true;
- }
- STATIC int
- xlog_recover_buffer_pass2(
- struct xlog *log,
- struct list_head *buffer_list,
- struct xlog_recover_item *item,
- xfs_lsn_t current_lsn)
- {
- xfs_buf_log_format_t *buf_f = item->ri_buf[0].i_addr;
- xfs_mount_t *mp = log->l_mp;
- xfs_buf_t *bp;
- int error;
- uint buf_flags;
- xfs_lsn_t lsn;
-
- if (xlog_check_buffer_cancelled(log, buf_f->blf_blkno,
- buf_f->blf_len, buf_f->blf_flags)) {
- trace_xfs_log_recover_buf_cancel(log, buf_f);
- return 0;
- }
- trace_xfs_log_recover_buf_recover(log, buf_f);
- buf_flags = 0;
- if (buf_f->blf_flags & XFS_BLF_INODE_BUF)
- buf_flags |= XBF_UNMAPPED;
- bp = xfs_buf_read(mp->m_ddev_targp, buf_f->blf_blkno, buf_f->blf_len,
- buf_flags, NULL);
- if (!bp)
- return -ENOMEM;
- error = bp->b_error;
- if (error) {
- xfs_buf_ioerror_alert(bp, "xlog_recover_do..(read#1)");
- goto out_release;
- }
-
- lsn = xlog_recover_get_buf_lsn(mp, bp);
- if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) {
- trace_xfs_log_recover_buf_skip(log, buf_f);
- xlog_recover_validate_buf_type(mp, bp, buf_f, NULLCOMMITLSN);
- goto out_release;
- }
- if (buf_f->blf_flags & XFS_BLF_INODE_BUF) {
- error = xlog_recover_do_inode_buffer(mp, item, bp, buf_f);
- if (error)
- goto out_release;
- } else if (buf_f->blf_flags &
- (XFS_BLF_UDQUOT_BUF|XFS_BLF_PDQUOT_BUF|XFS_BLF_GDQUOT_BUF)) {
- bool dirty;
- dirty = xlog_recover_do_dquot_buffer(mp, log, item, bp, buf_f);
- if (!dirty)
- goto out_release;
- } else {
- xlog_recover_do_reg_buffer(mp, item, bp, buf_f, current_lsn);
- }
-
- if (XFS_DINODE_MAGIC ==
- be16_to_cpu(*((__be16 *)xfs_buf_offset(bp, 0))) &&
- (BBTOB(bp->b_io_length) != MAX(log->l_mp->m_sb.sb_blocksize,
- (__uint32_t)log->l_mp->m_inode_cluster_size))) {
- xfs_buf_stale(bp);
- error = xfs_bwrite(bp);
- } else {
- ASSERT(bp->b_target->bt_mount == mp);
- bp->b_iodone = xlog_recover_iodone;
- xfs_buf_delwri_queue(bp, buffer_list);
- }
- out_release:
- xfs_buf_relse(bp);
- return error;
- }
- STATIC int
- xfs_recover_inode_owner_change(
- struct xfs_mount *mp,
- struct xfs_dinode *dip,
- struct xfs_inode_log_format *in_f,
- struct list_head *buffer_list)
- {
- struct xfs_inode *ip;
- int error;
- ASSERT(in_f->ilf_fields & (XFS_ILOG_DOWNER|XFS_ILOG_AOWNER));
- ip = xfs_inode_alloc(mp, in_f->ilf_ino);
- if (!ip)
- return -ENOMEM;
-
- xfs_inode_from_disk(ip, dip);
- ASSERT(ip->i_d.di_version >= 3);
- error = xfs_iformat_fork(ip, dip);
- if (error)
- goto out_free_ip;
- if (in_f->ilf_fields & XFS_ILOG_DOWNER) {
- ASSERT(in_f->ilf_fields & XFS_ILOG_DBROOT);
- error = xfs_bmbt_change_owner(NULL, ip, XFS_DATA_FORK,
- ip->i_ino, buffer_list);
- if (error)
- goto out_free_ip;
- }
- if (in_f->ilf_fields & XFS_ILOG_AOWNER) {
- ASSERT(in_f->ilf_fields & XFS_ILOG_ABROOT);
- error = xfs_bmbt_change_owner(NULL, ip, XFS_ATTR_FORK,
- ip->i_ino, buffer_list);
- if (error)
- goto out_free_ip;
- }
- out_free_ip:
- xfs_inode_free(ip);
- return error;
- }
- STATIC int
- xlog_recover_inode_pass2(
- struct xlog *log,
- struct list_head *buffer_list,
- struct xlog_recover_item *item,
- xfs_lsn_t current_lsn)
- {
- xfs_inode_log_format_t *in_f;
- xfs_mount_t *mp = log->l_mp;
- xfs_buf_t *bp;
- xfs_dinode_t *dip;
- int len;
- char *src;
- char *dest;
- int error;
- int attr_index;
- uint fields;
- struct xfs_log_dinode *ldip;
- uint isize;
- int need_free = 0;
- if (item->ri_buf[0].i_len == sizeof(xfs_inode_log_format_t)) {
- in_f = item->ri_buf[0].i_addr;
- } else {
- in_f = kmem_alloc(sizeof(xfs_inode_log_format_t), KM_SLEEP);
- need_free = 1;
- error = xfs_inode_item_format_convert(&item->ri_buf[0], in_f);
- if (error)
- goto error;
- }
-
- if (xlog_check_buffer_cancelled(log, in_f->ilf_blkno,
- in_f->ilf_len, 0)) {
- error = 0;
- trace_xfs_log_recover_inode_cancel(log, in_f);
- goto error;
- }
- trace_xfs_log_recover_inode_recover(log, in_f);
- bp = xfs_buf_read(mp->m_ddev_targp, in_f->ilf_blkno, in_f->ilf_len, 0,
- &xfs_inode_buf_ops);
- if (!bp) {
- error = -ENOMEM;
- goto error;
- }
- error = bp->b_error;
- if (error) {
- xfs_buf_ioerror_alert(bp, "xlog_recover_do..(read#2)");
- goto out_release;
- }
- ASSERT(in_f->ilf_fields & XFS_ILOG_CORE);
- dip = xfs_buf_offset(bp, in_f->ilf_boffset);
-
- if (unlikely(dip->di_magic != cpu_to_be16(XFS_DINODE_MAGIC))) {
- xfs_alert(mp,
- "%s: Bad inode magic number, dip = 0x%p, dino bp = 0x%p, ino = %Ld",
- __func__, dip, bp, in_f->ilf_ino);
- XFS_ERROR_REPORT("xlog_recover_inode_pass2(1)",
- XFS_ERRLEVEL_LOW, mp);
- error = -EFSCORRUPTED;
- goto out_release;
- }
- ldip = item->ri_buf[1].i_addr;
- if (unlikely(ldip->di_magic != XFS_DINODE_MAGIC)) {
- xfs_alert(mp,
- "%s: Bad inode log record, rec ptr 0x%p, ino %Ld",
- __func__, item, in_f->ilf_ino);
- XFS_ERROR_REPORT("xlog_recover_inode_pass2(2)",
- XFS_ERRLEVEL_LOW, mp);
- error = -EFSCORRUPTED;
- goto out_release;
- }
-
- if (dip->di_version >= 3) {
- xfs_lsn_t lsn = be64_to_cpu(dip->di_lsn);
- if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) {
- trace_xfs_log_recover_inode_skip(log, in_f);
- error = 0;
- goto out_owner_change;
- }
- }
-
- if (!xfs_sb_version_hascrc(&mp->m_sb) &&
- ldip->di_flushiter < be16_to_cpu(dip->di_flushiter)) {
-
- if (be16_to_cpu(dip->di_flushiter) == DI_MAX_FLUSH &&
- ldip->di_flushiter < (DI_MAX_FLUSH >> 1)) {
-
- } else {
- trace_xfs_log_recover_inode_skip(log, in_f);
- error = 0;
- goto out_release;
- }
- }
-
- ldip->di_flushiter = 0;
- if (unlikely(S_ISREG(ldip->di_mode))) {
- if ((ldip->di_format != XFS_DINODE_FMT_EXTENTS) &&
- (ldip->di_format != XFS_DINODE_FMT_BTREE)) {
- XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(3)",
- XFS_ERRLEVEL_LOW, mp, ldip);
- xfs_alert(mp,
- "%s: Bad regular inode log record, rec ptr 0x%p, "
- "ino ptr = 0x%p, ino bp = 0x%p, ino %Ld",
- __func__, item, dip, bp, in_f->ilf_ino);
- error = -EFSCORRUPTED;
- goto out_release;
- }
- } else if (unlikely(S_ISDIR(ldip->di_mode))) {
- if ((ldip->di_format != XFS_DINODE_FMT_EXTENTS) &&
- (ldip->di_format != XFS_DINODE_FMT_BTREE) &&
- (ldip->di_format != XFS_DINODE_FMT_LOCAL)) {
- XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(4)",
- XFS_ERRLEVEL_LOW, mp, ldip);
- xfs_alert(mp,
- "%s: Bad dir inode log record, rec ptr 0x%p, "
- "ino ptr = 0x%p, ino bp = 0x%p, ino %Ld",
- __func__, item, dip, bp, in_f->ilf_ino);
- error = -EFSCORRUPTED;
- goto out_release;
- }
- }
- if (unlikely(ldip->di_nextents + ldip->di_anextents > ldip->di_nblocks)){
- XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(5)",
- XFS_ERRLEVEL_LOW, mp, ldip);
- xfs_alert(mp,
- "%s: Bad inode log record, rec ptr 0x%p, dino ptr 0x%p, "
- "dino bp 0x%p, ino %Ld, total extents = %d, nblocks = %Ld",
- __func__, item, dip, bp, in_f->ilf_ino,
- ldip->di_nextents + ldip->di_anextents,
- ldip->di_nblocks);
- error = -EFSCORRUPTED;
- goto out_release;
- }
- if (unlikely(ldip->di_forkoff > mp->m_sb.sb_inodesize)) {
- XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(6)",
- XFS_ERRLEVEL_LOW, mp, ldip);
- xfs_alert(mp,
- "%s: Bad inode log record, rec ptr 0x%p, dino ptr 0x%p, "
- "dino bp 0x%p, ino %Ld, forkoff 0x%x", __func__,
- item, dip, bp, in_f->ilf_ino, ldip->di_forkoff);
- error = -EFSCORRUPTED;
- goto out_release;
- }
- isize = xfs_log_dinode_size(ldip->di_version);
- if (unlikely(item->ri_buf[1].i_len > isize)) {
- XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(7)",
- XFS_ERRLEVEL_LOW, mp, ldip);
- xfs_alert(mp,
- "%s: Bad inode log record length %d, rec ptr 0x%p",
- __func__, item->ri_buf[1].i_len, item);
- error = -EFSCORRUPTED;
- goto out_release;
- }
-
- xfs_log_dinode_to_disk(ldip, dip);
-
- if (item->ri_buf[1].i_len > isize) {
- memcpy((char *)dip + isize,
- item->ri_buf[1].i_addr + isize,
- item->ri_buf[1].i_len - isize);
- }
- fields = in_f->ilf_fields;
- switch (fields & (XFS_ILOG_DEV | XFS_ILOG_UUID)) {
- case XFS_ILOG_DEV:
- xfs_dinode_put_rdev(dip, in_f->ilf_u.ilfu_rdev);
- break;
- case XFS_ILOG_UUID:
- memcpy(XFS_DFORK_DPTR(dip),
- &in_f->ilf_u.ilfu_uuid,
- sizeof(uuid_t));
- break;
- }
- if (in_f->ilf_size == 2)
- goto out_owner_change;
- len = item->ri_buf[2].i_len;
- src = item->ri_buf[2].i_addr;
- ASSERT(in_f->ilf_size <= 4);
- ASSERT((in_f->ilf_size == 3) || (fields & XFS_ILOG_AFORK));
- ASSERT(!(fields & XFS_ILOG_DFORK) ||
- (len == in_f->ilf_dsize));
- switch (fields & XFS_ILOG_DFORK) {
- case XFS_ILOG_DDATA:
- case XFS_ILOG_DEXT:
- memcpy(XFS_DFORK_DPTR(dip), src, len);
- break;
- case XFS_ILOG_DBROOT:
- xfs_bmbt_to_bmdr(mp, (struct xfs_btree_block *)src, len,
- (xfs_bmdr_block_t *)XFS_DFORK_DPTR(dip),
- XFS_DFORK_DSIZE(dip, mp));
- break;
- default:
-
- ASSERT((fields & XFS_ILOG_DFORK) == 0);
- break;
- }
-
- if (in_f->ilf_fields & XFS_ILOG_AFORK) {
- if (in_f->ilf_fields & XFS_ILOG_DFORK) {
- attr_index = 3;
- } else {
- attr_index = 2;
- }
- len = item->ri_buf[attr_index].i_len;
- src = item->ri_buf[attr_index].i_addr;
- ASSERT(len == in_f->ilf_asize);
- switch (in_f->ilf_fields & XFS_ILOG_AFORK) {
- case XFS_ILOG_ADATA:
- case XFS_ILOG_AEXT:
- dest = XFS_DFORK_APTR(dip);
- ASSERT(len <= XFS_DFORK_ASIZE(dip, mp));
- memcpy(dest, src, len);
- break;
- case XFS_ILOG_ABROOT:
- dest = XFS_DFORK_APTR(dip);
- xfs_bmbt_to_bmdr(mp, (struct xfs_btree_block *)src,
- len, (xfs_bmdr_block_t*)dest,
- XFS_DFORK_ASIZE(dip, mp));
- break;
- default:
- xfs_warn(log->l_mp, "%s: Invalid flag", __func__);
- ASSERT(0);
- error = -EIO;
- goto out_release;
- }
- }
- out_owner_change:
- if (in_f->ilf_fields & (XFS_ILOG_DOWNER|XFS_ILOG_AOWNER))
- error = xfs_recover_inode_owner_change(mp, dip, in_f,
- buffer_list);
-
- xfs_dinode_calc_crc(log->l_mp, dip);
- ASSERT(bp->b_target->bt_mount == mp);
- bp->b_iodone = xlog_recover_iodone;
- xfs_buf_delwri_queue(bp, buffer_list);
- out_release:
- xfs_buf_relse(bp);
- error:
- if (need_free)
- kmem_free(in_f);
- return error;
- }
- STATIC int
- xlog_recover_quotaoff_pass1(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- xfs_qoff_logformat_t *qoff_f = item->ri_buf[0].i_addr;
- ASSERT(qoff_f);
-
- if (qoff_f->qf_flags & XFS_UQUOTA_ACCT)
- log->l_quotaoffs_flag |= XFS_DQ_USER;
- if (qoff_f->qf_flags & XFS_PQUOTA_ACCT)
- log->l_quotaoffs_flag |= XFS_DQ_PROJ;
- if (qoff_f->qf_flags & XFS_GQUOTA_ACCT)
- log->l_quotaoffs_flag |= XFS_DQ_GROUP;
- return 0;
- }
- STATIC int
- xlog_recover_dquot_pass2(
- struct xlog *log,
- struct list_head *buffer_list,
- struct xlog_recover_item *item,
- xfs_lsn_t current_lsn)
- {
- xfs_mount_t *mp = log->l_mp;
- xfs_buf_t *bp;
- struct xfs_disk_dquot *ddq, *recddq;
- int error;
- xfs_dq_logformat_t *dq_f;
- uint type;
-
- if (mp->m_qflags == 0)
- return 0;
- recddq = item->ri_buf[1].i_addr;
- if (recddq == NULL) {
- xfs_alert(log->l_mp, "NULL dquot in %s.", __func__);
- return -EIO;
- }
- if (item->ri_buf[1].i_len < sizeof(xfs_disk_dquot_t)) {
- xfs_alert(log->l_mp, "dquot too small (%d) in %s.",
- item->ri_buf[1].i_len, __func__);
- return -EIO;
- }
-
- type = recddq->d_flags & (XFS_DQ_USER | XFS_DQ_PROJ | XFS_DQ_GROUP);
- ASSERT(type);
- if (log->l_quotaoffs_flag & type)
- return 0;
-
- dq_f = item->ri_buf[0].i_addr;
- ASSERT(dq_f);
- error = xfs_dqcheck(mp, recddq, dq_f->qlf_id, 0, XFS_QMOPT_DOWARN,
- "xlog_recover_dquot_pass2 (log copy)");
- if (error)
- return -EIO;
- ASSERT(dq_f->qlf_len == 1);
-
- error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp, dq_f->qlf_blkno,
- XFS_FSB_TO_BB(mp, dq_f->qlf_len), 0, &bp,
- &xfs_dquot_buf_ops);
- if (error)
- return error;
- ASSERT(bp);
- ddq = xfs_buf_offset(bp, dq_f->qlf_boffset);
-
- if (xfs_sb_version_hascrc(&mp->m_sb)) {
- struct xfs_dqblk *dqb = (struct xfs_dqblk *)ddq;
- xfs_lsn_t lsn = be64_to_cpu(dqb->dd_lsn);
- if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) {
- goto out_release;
- }
- }
- memcpy(ddq, recddq, item->ri_buf[1].i_len);
- if (xfs_sb_version_hascrc(&mp->m_sb)) {
- xfs_update_cksum((char *)ddq, sizeof(struct xfs_dqblk),
- XFS_DQUOT_CRC_OFF);
- }
- ASSERT(dq_f->qlf_size == 2);
- ASSERT(bp->b_target->bt_mount == mp);
- bp->b_iodone = xlog_recover_iodone;
- xfs_buf_delwri_queue(bp, buffer_list);
- out_release:
- xfs_buf_relse(bp);
- return 0;
- }
- STATIC int
- xlog_recover_efi_pass2(
- struct xlog *log,
- struct xlog_recover_item *item,
- xfs_lsn_t lsn)
- {
- int error;
- struct xfs_mount *mp = log->l_mp;
- struct xfs_efi_log_item *efip;
- struct xfs_efi_log_format *efi_formatp;
- efi_formatp = item->ri_buf[0].i_addr;
- efip = xfs_efi_init(mp, efi_formatp->efi_nextents);
- error = xfs_efi_copy_format(&item->ri_buf[0], &efip->efi_format);
- if (error) {
- xfs_efi_item_free(efip);
- return error;
- }
- atomic_set(&efip->efi_next_extent, efi_formatp->efi_nextents);
- spin_lock(&log->l_ailp->xa_lock);
-
- xfs_trans_ail_update(log->l_ailp, &efip->efi_item, lsn);
- xfs_efi_release(efip);
- return 0;
- }
- STATIC int
- xlog_recover_efd_pass2(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- xfs_efd_log_format_t *efd_formatp;
- xfs_efi_log_item_t *efip = NULL;
- xfs_log_item_t *lip;
- __uint64_t efi_id;
- struct xfs_ail_cursor cur;
- struct xfs_ail *ailp = log->l_ailp;
- efd_formatp = item->ri_buf[0].i_addr;
- ASSERT((item->ri_buf[0].i_len == (sizeof(xfs_efd_log_format_32_t) +
- ((efd_formatp->efd_nextents - 1) * sizeof(xfs_extent_32_t)))) ||
- (item->ri_buf[0].i_len == (sizeof(xfs_efd_log_format_64_t) +
- ((efd_formatp->efd_nextents - 1) * sizeof(xfs_extent_64_t)))));
- efi_id = efd_formatp->efd_efi_id;
-
- spin_lock(&ailp->xa_lock);
- lip = xfs_trans_ail_cursor_first(ailp, &cur, 0);
- while (lip != NULL) {
- if (lip->li_type == XFS_LI_EFI) {
- efip = (xfs_efi_log_item_t *)lip;
- if (efip->efi_format.efi_id == efi_id) {
-
- spin_unlock(&ailp->xa_lock);
- xfs_efi_release(efip);
- spin_lock(&ailp->xa_lock);
- break;
- }
- }
- lip = xfs_trans_ail_cursor_next(ailp, &cur);
- }
- xfs_trans_ail_cursor_done(&cur);
- spin_unlock(&ailp->xa_lock);
- return 0;
- }
- STATIC int
- xlog_recover_rui_pass2(
- struct xlog *log,
- struct xlog_recover_item *item,
- xfs_lsn_t lsn)
- {
- int error;
- struct xfs_mount *mp = log->l_mp;
- struct xfs_rui_log_item *ruip;
- struct xfs_rui_log_format *rui_formatp;
- rui_formatp = item->ri_buf[0].i_addr;
- ruip = xfs_rui_init(mp, rui_formatp->rui_nextents);
- error = xfs_rui_copy_format(&item->ri_buf[0], &ruip->rui_format);
- if (error) {
- xfs_rui_item_free(ruip);
- return error;
- }
- atomic_set(&ruip->rui_next_extent, rui_formatp->rui_nextents);
- spin_lock(&log->l_ailp->xa_lock);
-
- xfs_trans_ail_update(log->l_ailp, &ruip->rui_item, lsn);
- xfs_rui_release(ruip);
- return 0;
- }
- STATIC int
- xlog_recover_rud_pass2(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- struct xfs_rud_log_format *rud_formatp;
- struct xfs_rui_log_item *ruip = NULL;
- struct xfs_log_item *lip;
- __uint64_t rui_id;
- struct xfs_ail_cursor cur;
- struct xfs_ail *ailp = log->l_ailp;
- rud_formatp = item->ri_buf[0].i_addr;
- ASSERT(item->ri_buf[0].i_len == sizeof(struct xfs_rud_log_format));
- rui_id = rud_formatp->rud_rui_id;
-
- spin_lock(&ailp->xa_lock);
- lip = xfs_trans_ail_cursor_first(ailp, &cur, 0);
- while (lip != NULL) {
- if (lip->li_type == XFS_LI_RUI) {
- ruip = (struct xfs_rui_log_item *)lip;
- if (ruip->rui_format.rui_id == rui_id) {
-
- spin_unlock(&ailp->xa_lock);
- xfs_rui_release(ruip);
- spin_lock(&ailp->xa_lock);
- break;
- }
- }
- lip = xfs_trans_ail_cursor_next(ailp, &cur);
- }
- xfs_trans_ail_cursor_done(&cur);
- spin_unlock(&ailp->xa_lock);
- return 0;
- }
- static int
- xfs_cui_copy_format(
- struct xfs_log_iovec *buf,
- struct xfs_cui_log_format *dst_cui_fmt)
- {
- struct xfs_cui_log_format *src_cui_fmt;
- uint len;
- src_cui_fmt = buf->i_addr;
- len = xfs_cui_log_format_sizeof(src_cui_fmt->cui_nextents);
- if (buf->i_len == len) {
- memcpy(dst_cui_fmt, src_cui_fmt, len);
- return 0;
- }
- return -EFSCORRUPTED;
- }
- STATIC int
- xlog_recover_cui_pass2(
- struct xlog *log,
- struct xlog_recover_item *item,
- xfs_lsn_t lsn)
- {
- int error;
- struct xfs_mount *mp = log->l_mp;
- struct xfs_cui_log_item *cuip;
- struct xfs_cui_log_format *cui_formatp;
- cui_formatp = item->ri_buf[0].i_addr;
- cuip = xfs_cui_init(mp, cui_formatp->cui_nextents);
- error = xfs_cui_copy_format(&item->ri_buf[0], &cuip->cui_format);
- if (error) {
- xfs_cui_item_free(cuip);
- return error;
- }
- atomic_set(&cuip->cui_next_extent, cui_formatp->cui_nextents);
- spin_lock(&log->l_ailp->xa_lock);
-
- xfs_trans_ail_update(log->l_ailp, &cuip->cui_item, lsn);
- xfs_cui_release(cuip);
- return 0;
- }
- STATIC int
- xlog_recover_cud_pass2(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- struct xfs_cud_log_format *cud_formatp;
- struct xfs_cui_log_item *cuip = NULL;
- struct xfs_log_item *lip;
- __uint64_t cui_id;
- struct xfs_ail_cursor cur;
- struct xfs_ail *ailp = log->l_ailp;
- cud_formatp = item->ri_buf[0].i_addr;
- if (item->ri_buf[0].i_len != sizeof(struct xfs_cud_log_format))
- return -EFSCORRUPTED;
- cui_id = cud_formatp->cud_cui_id;
-
- spin_lock(&ailp->xa_lock);
- lip = xfs_trans_ail_cursor_first(ailp, &cur, 0);
- while (lip != NULL) {
- if (lip->li_type == XFS_LI_CUI) {
- cuip = (struct xfs_cui_log_item *)lip;
- if (cuip->cui_format.cui_id == cui_id) {
-
- spin_unlock(&ailp->xa_lock);
- xfs_cui_release(cuip);
- spin_lock(&ailp->xa_lock);
- break;
- }
- }
- lip = xfs_trans_ail_cursor_next(ailp, &cur);
- }
- xfs_trans_ail_cursor_done(&cur);
- spin_unlock(&ailp->xa_lock);
- return 0;
- }
- static int
- xfs_bui_copy_format(
- struct xfs_log_iovec *buf,
- struct xfs_bui_log_format *dst_bui_fmt)
- {
- struct xfs_bui_log_format *src_bui_fmt;
- uint len;
- src_bui_fmt = buf->i_addr;
- len = xfs_bui_log_format_sizeof(src_bui_fmt->bui_nextents);
- if (buf->i_len == len) {
- memcpy(dst_bui_fmt, src_bui_fmt, len);
- return 0;
- }
- return -EFSCORRUPTED;
- }
- STATIC int
- xlog_recover_bui_pass2(
- struct xlog *log,
- struct xlog_recover_item *item,
- xfs_lsn_t lsn)
- {
- int error;
- struct xfs_mount *mp = log->l_mp;
- struct xfs_bui_log_item *buip;
- struct xfs_bui_log_format *bui_formatp;
- bui_formatp = item->ri_buf[0].i_addr;
- if (bui_formatp->bui_nextents != XFS_BUI_MAX_FAST_EXTENTS)
- return -EFSCORRUPTED;
- buip = xfs_bui_init(mp);
- error = xfs_bui_copy_format(&item->ri_buf[0], &buip->bui_format);
- if (error) {
- xfs_bui_item_free(buip);
- return error;
- }
- atomic_set(&buip->bui_next_extent, bui_formatp->bui_nextents);
- spin_lock(&log->l_ailp->xa_lock);
-
- xfs_trans_ail_update(log->l_ailp, &buip->bui_item, lsn);
- xfs_bui_release(buip);
- return 0;
- }
- STATIC int
- xlog_recover_bud_pass2(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- struct xfs_bud_log_format *bud_formatp;
- struct xfs_bui_log_item *buip = NULL;
- struct xfs_log_item *lip;
- __uint64_t bui_id;
- struct xfs_ail_cursor cur;
- struct xfs_ail *ailp = log->l_ailp;
- bud_formatp = item->ri_buf[0].i_addr;
- if (item->ri_buf[0].i_len != sizeof(struct xfs_bud_log_format))
- return -EFSCORRUPTED;
- bui_id = bud_formatp->bud_bui_id;
-
- spin_lock(&ailp->xa_lock);
- lip = xfs_trans_ail_cursor_first(ailp, &cur, 0);
- while (lip != NULL) {
- if (lip->li_type == XFS_LI_BUI) {
- buip = (struct xfs_bui_log_item *)lip;
- if (buip->bui_format.bui_id == bui_id) {
-
- spin_unlock(&ailp->xa_lock);
- xfs_bui_release(buip);
- spin_lock(&ailp->xa_lock);
- break;
- }
- }
- lip = xfs_trans_ail_cursor_next(ailp, &cur);
- }
- xfs_trans_ail_cursor_done(&cur);
- spin_unlock(&ailp->xa_lock);
- return 0;
- }
- STATIC int
- xlog_recover_do_icreate_pass2(
- struct xlog *log,
- struct list_head *buffer_list,
- xlog_recover_item_t *item)
- {
- struct xfs_mount *mp = log->l_mp;
- struct xfs_icreate_log *icl;
- xfs_agnumber_t agno;
- xfs_agblock_t agbno;
- unsigned int count;
- unsigned int isize;
- xfs_agblock_t length;
- int blks_per_cluster;
- int bb_per_cluster;
- int cancel_count;
- int nbufs;
- int i;
- icl = (struct xfs_icreate_log *)item->ri_buf[0].i_addr;
- if (icl->icl_type != XFS_LI_ICREATE) {
- xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad type");
- return -EINVAL;
- }
- if (icl->icl_size != 1) {
- xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad icl size");
- return -EINVAL;
- }
- agno = be32_to_cpu(icl->icl_ag);
- if (agno >= mp->m_sb.sb_agcount) {
- xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad agno");
- return -EINVAL;
- }
- agbno = be32_to_cpu(icl->icl_agbno);
- if (!agbno || agbno == NULLAGBLOCK || agbno >= mp->m_sb.sb_agblocks) {
- xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad agbno");
- return -EINVAL;
- }
- isize = be32_to_cpu(icl->icl_isize);
- if (isize != mp->m_sb.sb_inodesize) {
- xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad isize");
- return -EINVAL;
- }
- count = be32_to_cpu(icl->icl_count);
- if (!count) {
- xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad count");
- return -EINVAL;
- }
- length = be32_to_cpu(icl->icl_length);
- if (!length || length >= mp->m_sb.sb_agblocks) {
- xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad length");
- return -EINVAL;
- }
-
- if (length != mp->m_ialloc_blks &&
- length != mp->m_ialloc_min_blks) {
- xfs_warn(log->l_mp,
- "%s: unsupported chunk length", __FUNCTION__);
- return -EINVAL;
- }
-
- if ((count >> mp->m_sb.sb_inopblog) != length) {
- xfs_warn(log->l_mp,
- "%s: inconsistent inode count and chunk length",
- __FUNCTION__);
- return -EINVAL;
- }
-
- blks_per_cluster = xfs_icluster_size_fsb(mp);
- bb_per_cluster = XFS_FSB_TO_BB(mp, blks_per_cluster);
- nbufs = length / blks_per_cluster;
- for (i = 0, cancel_count = 0; i < nbufs; i++) {
- xfs_daddr_t daddr;
- daddr = XFS_AGB_TO_DADDR(mp, agno,
- agbno + i * blks_per_cluster);
- if (xlog_check_buffer_cancelled(log, daddr, bb_per_cluster, 0))
- cancel_count++;
- }
-
- ASSERT(!cancel_count || cancel_count == nbufs);
- if (cancel_count) {
- if (cancel_count != nbufs)
- xfs_warn(mp,
- "WARNING: partial inode chunk cancellation, skipped icreate.");
- trace_xfs_log_recover_icreate_cancel(log, icl);
- return 0;
- }
- trace_xfs_log_recover_icreate_recover(log, icl);
- return xfs_ialloc_inode_init(mp, NULL, buffer_list, count, agno, agbno,
- length, be32_to_cpu(icl->icl_gen));
- }
- STATIC void
- xlog_recover_buffer_ra_pass2(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- struct xfs_buf_log_format *buf_f = item->ri_buf[0].i_addr;
- struct xfs_mount *mp = log->l_mp;
- if (xlog_peek_buffer_cancelled(log, buf_f->blf_blkno,
- buf_f->blf_len, buf_f->blf_flags)) {
- return;
- }
- xfs_buf_readahead(mp->m_ddev_targp, buf_f->blf_blkno,
- buf_f->blf_len, NULL);
- }
- STATIC void
- xlog_recover_inode_ra_pass2(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- struct xfs_inode_log_format ilf_buf;
- struct xfs_inode_log_format *ilfp;
- struct xfs_mount *mp = log->l_mp;
- int error;
- if (item->ri_buf[0].i_len == sizeof(struct xfs_inode_log_format)) {
- ilfp = item->ri_buf[0].i_addr;
- } else {
- ilfp = &ilf_buf;
- memset(ilfp, 0, sizeof(*ilfp));
- error = xfs_inode_item_format_convert(&item->ri_buf[0], ilfp);
- if (error)
- return;
- }
- if (xlog_peek_buffer_cancelled(log, ilfp->ilf_blkno, ilfp->ilf_len, 0))
- return;
- xfs_buf_readahead(mp->m_ddev_targp, ilfp->ilf_blkno,
- ilfp->ilf_len, &xfs_inode_buf_ra_ops);
- }
- STATIC void
- xlog_recover_dquot_ra_pass2(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- struct xfs_mount *mp = log->l_mp;
- struct xfs_disk_dquot *recddq;
- struct xfs_dq_logformat *dq_f;
- uint type;
- int len;
- if (mp->m_qflags == 0)
- return;
- recddq = item->ri_buf[1].i_addr;
- if (recddq == NULL)
- return;
- if (item->ri_buf[1].i_len < sizeof(struct xfs_disk_dquot))
- return;
- type = recddq->d_flags & (XFS_DQ_USER | XFS_DQ_PROJ | XFS_DQ_GROUP);
- ASSERT(type);
- if (log->l_quotaoffs_flag & type)
- return;
- dq_f = item->ri_buf[0].i_addr;
- ASSERT(dq_f);
- ASSERT(dq_f->qlf_len == 1);
- len = XFS_FSB_TO_BB(mp, dq_f->qlf_len);
- if (xlog_peek_buffer_cancelled(log, dq_f->qlf_blkno, len, 0))
- return;
- xfs_buf_readahead(mp->m_ddev_targp, dq_f->qlf_blkno, len,
- &xfs_dquot_buf_ra_ops);
- }
- STATIC void
- xlog_recover_ra_pass2(
- struct xlog *log,
- struct xlog_recover_item *item)
- {
- switch (ITEM_TYPE(item)) {
- case XFS_LI_BUF:
- xlog_recover_buffer_ra_pass2(log, item);
- break;
- case XFS_LI_INODE:
- xlog_recover_inode_ra_pass2(log, item);
- break;
- case XFS_LI_DQUOT:
- xlog_recover_dquot_ra_pass2(log, item);
- break;
- case XFS_LI_EFI:
- case XFS_LI_EFD:
- case XFS_LI_QUOTAOFF:
- case XFS_LI_RUI:
- case XFS_LI_RUD:
- case XFS_LI_CUI:
- case XFS_LI_CUD:
- case XFS_LI_BUI:
- case XFS_LI_BUD:
- default:
- break;
- }
- }
- STATIC int
- xlog_recover_commit_pass1(
- struct xlog *log,
- struct xlog_recover *trans,
- struct xlog_recover_item *item)
- {
- trace_xfs_log_recover_item_recover(log, trans, item, XLOG_RECOVER_PASS1);
- switch (ITEM_TYPE(item)) {
- case XFS_LI_BUF:
- return xlog_recover_buffer_pass1(log, item);
- case XFS_LI_QUOTAOFF:
- return xlog_recover_quotaoff_pass1(log, item);
- case XFS_LI_INODE:
- case XFS_LI_EFI:
- case XFS_LI_EFD:
- case XFS_LI_DQUOT:
- case XFS_LI_ICREATE:
- case XFS_LI_RUI:
- case XFS_LI_RUD:
- case XFS_LI_CUI:
- case XFS_LI_CUD:
- case XFS_LI_BUI:
- case XFS_LI_BUD:
-
- return 0;
- default:
- xfs_warn(log->l_mp, "%s: invalid item type (%d)",
- __func__, ITEM_TYPE(item));
- ASSERT(0);
- return -EIO;
- }
- }
- STATIC int
- xlog_recover_commit_pass2(
- struct xlog *log,
- struct xlog_recover *trans,
- struct list_head *buffer_list,
- struct xlog_recover_item *item)
- {
- trace_xfs_log_recover_item_recover(log, trans, item, XLOG_RECOVER_PASS2);
- switch (ITEM_TYPE(item)) {
- case XFS_LI_BUF:
- return xlog_recover_buffer_pass2(log, buffer_list, item,
- trans->r_lsn);
- case XFS_LI_INODE:
- return xlog_recover_inode_pass2(log, buffer_list, item,
- trans->r_lsn);
- case XFS_LI_EFI:
- return xlog_recover_efi_pass2(log, item, trans->r_lsn);
- case XFS_LI_EFD:
- return xlog_recover_efd_pass2(log, item);
- case XFS_LI_RUI:
- return xlog_recover_rui_pass2(log, item, trans->r_lsn);
- case XFS_LI_RUD:
- return xlog_recover_rud_pass2(log, item);
- case XFS_LI_CUI:
- return xlog_recover_cui_pass2(log, item, trans->r_lsn);
- case XFS_LI_CUD:
- return xlog_recover_cud_pass2(log, item);
- case XFS_LI_BUI:
- return xlog_recover_bui_pass2(log, item, trans->r_lsn);
- case XFS_LI_BUD:
- return xlog_recover_bud_pass2(log, item);
- case XFS_LI_DQUOT:
- return xlog_recover_dquot_pass2(log, buffer_list, item,
- trans->r_lsn);
- case XFS_LI_ICREATE:
- return xlog_recover_do_icreate_pass2(log, buffer_list, item);
- case XFS_LI_QUOTAOFF:
-
- return 0;
- default:
- xfs_warn(log->l_mp, "%s: invalid item type (%d)",
- __func__, ITEM_TYPE(item));
- ASSERT(0);
- return -EIO;
- }
- }
- STATIC int
- xlog_recover_items_pass2(
- struct xlog *log,
- struct xlog_recover *trans,
- struct list_head *buffer_list,
- struct list_head *item_list)
- {
- struct xlog_recover_item *item;
- int error = 0;
- list_for_each_entry(item, item_list, ri_list) {
- error = xlog_recover_commit_pass2(log, trans,
- buffer_list, item);
- if (error)
- return error;
- }
- return error;
- }
- STATIC int
- xlog_recover_commit_trans(
- struct xlog *log,
- struct xlog_recover *trans,
- int pass,
- struct list_head *buffer_list)
- {
- int error = 0;
- int items_queued = 0;
- struct xlog_recover_item *item;
- struct xlog_recover_item *next;
- LIST_HEAD (ra_list);
- LIST_HEAD (done_list);
- #define XLOG_RECOVER_COMMIT_QUEUE_MAX 100
- hlist_del_init(&trans->r_list);
- error = xlog_recover_reorder_trans(log, trans, pass);
- if (error)
- return error;
- list_for_each_entry_safe(item, next, &trans->r_itemq, ri_list) {
- switch (pass) {
- case XLOG_RECOVER_PASS1:
- error = xlog_recover_commit_pass1(log, trans, item);
- break;
- case XLOG_RECOVER_PASS2:
- xlog_recover_ra_pass2(log, item);
- list_move_tail(&item->ri_list, &ra_list);
- items_queued++;
- if (items_queued >= XLOG_RECOVER_COMMIT_QUEUE_MAX) {
- error = xlog_recover_items_pass2(log, trans,
- buffer_list, &ra_list);
- list_splice_tail_init(&ra_list, &done_list);
- items_queued = 0;
- }
- break;
- default:
- ASSERT(0);
- }
- if (error)
- goto out;
- }
- out:
- if (!list_empty(&ra_list)) {
- if (!error)
- error = xlog_recover_items_pass2(log, trans,
- buffer_list, &ra_list);
- list_splice_tail_init(&ra_list, &done_list);
- }
- if (!list_empty(&done_list))
- list_splice_init(&done_list, &trans->r_itemq);
- return error;
- }
- STATIC void
- xlog_recover_add_item(
- struct list_head *head)
- {
- xlog_recover_item_t *item;
- item = kmem_zalloc(sizeof(xlog_recover_item_t), KM_SLEEP);
- INIT_LIST_HEAD(&item->ri_list);
- list_add_tail(&item->ri_list, head);
- }
- STATIC int
- xlog_recover_add_to_cont_trans(
- struct xlog *log,
- struct xlog_recover *trans,
- char *dp,
- int len)
- {
- xlog_recover_item_t *item;
- char *ptr, *old_ptr;
- int old_len;
-
- if (list_empty(&trans->r_itemq)) {
- ASSERT(len <= sizeof(struct xfs_trans_header));
- if (len > sizeof(struct xfs_trans_header)) {
- xfs_warn(log->l_mp, "%s: bad header length", __func__);
- return -EIO;
- }
- xlog_recover_add_item(&trans->r_itemq);
- ptr = (char *)&trans->r_theader +
- sizeof(struct xfs_trans_header) - len;
- memcpy(ptr, dp, len);
- return 0;
- }
-
- item = list_entry(trans->r_itemq.prev, xlog_recover_item_t, ri_list);
- old_ptr = item->ri_buf[item->ri_cnt-1].i_addr;
- old_len = item->ri_buf[item->ri_cnt-1].i_len;
- ptr = kmem_realloc(old_ptr, len + old_len, KM_SLEEP);
- memcpy(&ptr[old_len], dp, len);
- item->ri_buf[item->ri_cnt-1].i_len += len;
- item->ri_buf[item->ri_cnt-1].i_addr = ptr;
- trace_xfs_log_recover_item_add_cont(log, trans, item, 0);
- return 0;
- }
- STATIC int
- xlog_recover_add_to_trans(
- struct xlog *log,
- struct xlog_recover *trans,
- char *dp,
- int len)
- {
- xfs_inode_log_format_t *in_f;
- xlog_recover_item_t *item;
- char *ptr;
- if (!len)
- return 0;
- if (list_empty(&trans->r_itemq)) {
-
- if (*(uint *)dp != XFS_TRANS_HEADER_MAGIC) {
- xfs_warn(log->l_mp, "%s: bad header magic number",
- __func__);
- ASSERT(0);
- return -EIO;
- }
- if (len > sizeof(struct xfs_trans_header)) {
- xfs_warn(log->l_mp, "%s: bad header length", __func__);
- ASSERT(0);
- return -EIO;
- }
-
- if (len == sizeof(struct xfs_trans_header))
- xlog_recover_add_item(&trans->r_itemq);
- memcpy(&trans->r_theader, dp, len);
- return 0;
- }
- ptr = kmem_alloc(len, KM_SLEEP);
- memcpy(ptr, dp, len);
- in_f = (xfs_inode_log_format_t *)ptr;
-
- item = list_entry(trans->r_itemq.prev, xlog_recover_item_t, ri_list);
- if (item->ri_total != 0 &&
- item->ri_total == item->ri_cnt) {
-
- xlog_recover_add_item(&trans->r_itemq);
- item = list_entry(trans->r_itemq.prev,
- xlog_recover_item_t, ri_list);
- }
- if (item->ri_total == 0) {
- if (in_f->ilf_size == 0 ||
- in_f->ilf_size > XLOG_MAX_REGIONS_IN_ITEM) {
- xfs_warn(log->l_mp,
- "bad number of regions (%d) in inode log format",
- in_f->ilf_size);
- ASSERT(0);
- kmem_free(ptr);
- return -EIO;
- }
- item->ri_total = in_f->ilf_size;
- item->ri_buf =
- kmem_zalloc(item->ri_total * sizeof(xfs_log_iovec_t),
- KM_SLEEP);
- }
- ASSERT(item->ri_total > item->ri_cnt);
-
- item->ri_buf[item->ri_cnt].i_addr = ptr;
- item->ri_buf[item->ri_cnt].i_len = len;
- item->ri_cnt++;
- trace_xfs_log_recover_item_add(log, trans, item, 0);
- return 0;
- }
- STATIC void
- xlog_recover_free_trans(
- struct xlog_recover *trans)
- {
- xlog_recover_item_t *item, *n;
- int i;
- hlist_del_init(&trans->r_list);
- list_for_each_entry_safe(item, n, &trans->r_itemq, ri_list) {
-
- list_del(&item->ri_list);
- for (i = 0; i < item->ri_cnt; i++)
- kmem_free(item->ri_buf[i].i_addr);
-
- kmem_free(item->ri_buf);
- kmem_free(item);
- }
-
- kmem_free(trans);
- }
- STATIC int
- xlog_recovery_process_trans(
- struct xlog *log,
- struct xlog_recover *trans,
- char *dp,
- unsigned int len,
- unsigned int flags,
- int pass,
- struct list_head *buffer_list)
- {
- int error = 0;
- bool freeit = false;
-
- flags &= ~XLOG_END_TRANS;
- if (flags & XLOG_WAS_CONT_TRANS)
- flags &= ~XLOG_CONTINUE_TRANS;
-
- switch (flags) {
-
- case 0:
- case XLOG_CONTINUE_TRANS:
- error = xlog_recover_add_to_trans(log, trans, dp, len);
- break;
- case XLOG_WAS_CONT_TRANS:
- error = xlog_recover_add_to_cont_trans(log, trans, dp, len);
- break;
- case XLOG_COMMIT_TRANS:
- error = xlog_recover_commit_trans(log, trans, pass,
- buffer_list);
-
- freeit = true;
- break;
-
- case XLOG_UNMOUNT_TRANS:
-
- xfs_warn(log->l_mp, "%s: Unmount LR", __func__);
- freeit = true;
- break;
- case XLOG_START_TRANS:
- default:
- xfs_warn(log->l_mp, "%s: bad flag 0x%x", __func__, flags);
- ASSERT(0);
- error = -EIO;
- break;
- }
- if (error || freeit)
- xlog_recover_free_trans(trans);
- return error;
- }
- STATIC struct xlog_recover *
- xlog_recover_ophdr_to_trans(
- struct hlist_head rhash[],
- struct xlog_rec_header *rhead,
- struct xlog_op_header *ohead)
- {
- struct xlog_recover *trans;
- xlog_tid_t tid;
- struct hlist_head *rhp;
- tid = be32_to_cpu(ohead->oh_tid);
- rhp = &rhash[XLOG_RHASH(tid)];
- hlist_for_each_entry(trans, rhp, r_list) {
- if (trans->r_log_tid == tid)
- return trans;
- }
-
- if (!(ohead->oh_flags & XLOG_START_TRANS))
- return NULL;
- ASSERT(be32_to_cpu(ohead->oh_len) == 0);
-
- trans = kmem_zalloc(sizeof(struct xlog_recover), KM_SLEEP);
- trans->r_log_tid = tid;
- trans->r_lsn = be64_to_cpu(rhead->h_lsn);
- INIT_LIST_HEAD(&trans->r_itemq);
- INIT_HLIST_NODE(&trans->r_list);
- hlist_add_head(&trans->r_list, rhp);
-
- return NULL;
- }
- STATIC int
- xlog_recover_process_ophdr(
- struct xlog *log,
- struct hlist_head rhash[],
- struct xlog_rec_header *rhead,
- struct xlog_op_header *ohead,
- char *dp,
- char *end,
- int pass,
- struct list_head *buffer_list)
- {
- struct xlog_recover *trans;
- unsigned int len;
- int error;
-
- if (ohead->oh_clientid != XFS_TRANSACTION &&
- ohead->oh_clientid != XFS_LOG) {
- xfs_warn(log->l_mp, "%s: bad clientid 0x%x",
- __func__, ohead->oh_clientid);
- ASSERT(0);
- return -EIO;
- }
-
- len = be32_to_cpu(ohead->oh_len);
- if (dp + len > end) {
- xfs_warn(log->l_mp, "%s: bad length 0x%x", __func__, len);
- WARN_ON(1);
- return -EIO;
- }
- trans = xlog_recover_ophdr_to_trans(rhash, rhead, ohead);
- if (!trans) {
-
- return 0;
- }
-
- if (log->l_recovery_lsn != trans->r_lsn &&
- ohead->oh_flags & XLOG_COMMIT_TRANS) {
- error = xfs_buf_delwri_submit(buffer_list);
- if (error)
- return error;
- log->l_recovery_lsn = trans->r_lsn;
- }
- return xlog_recovery_process_trans(log, trans, dp, len,
- ohead->oh_flags, pass, buffer_list);
- }
- STATIC int
- xlog_recover_process_data(
- struct xlog *log,
- struct hlist_head rhash[],
- struct xlog_rec_header *rhead,
- char *dp,
- int pass,
- struct list_head *buffer_list)
- {
- struct xlog_op_header *ohead;
- char *end;
- int num_logops;
- int error;
- end = dp + be32_to_cpu(rhead->h_len);
- num_logops = be32_to_cpu(rhead->h_num_logops);
-
- if (xlog_header_check_recover(log->l_mp, rhead))
- return -EIO;
- trace_xfs_log_recover_record(log, rhead, pass);
- while ((dp < end) && num_logops) {
- ohead = (struct xlog_op_header *)dp;
- dp += sizeof(*ohead);
- ASSERT(dp <= end);
-
- error = xlog_recover_process_ophdr(log, rhash, rhead, ohead,
- dp, end, pass, buffer_list);
- if (error)
- return error;
- dp += be32_to_cpu(ohead->oh_len);
- num_logops--;
- }
- return 0;
- }
- STATIC int
- xlog_recover_process_efi(
- struct xfs_mount *mp,
- struct xfs_ail *ailp,
- struct xfs_log_item *lip)
- {
- struct xfs_efi_log_item *efip;
- int error;
-
- efip = container_of(lip, struct xfs_efi_log_item, efi_item);
- if (test_bit(XFS_EFI_RECOVERED, &efip->efi_flags))
- return 0;
- spin_unlock(&ailp->xa_lock);
- error = xfs_efi_recover(mp, efip);
- spin_lock(&ailp->xa_lock);
- return error;
- }
- STATIC void
- xlog_recover_cancel_efi(
- struct xfs_mount *mp,
- struct xfs_ail *ailp,
- struct xfs_log_item *lip)
- {
- struct xfs_efi_log_item *efip;
- efip = container_of(lip, struct xfs_efi_log_item, efi_item);
- spin_unlock(&ailp->xa_lock);
- xfs_efi_release(efip);
- spin_lock(&ailp->xa_lock);
- }
- STATIC int
- xlog_recover_process_rui(
- struct xfs_mount *mp,
- struct xfs_ail *ailp,
- struct xfs_log_item *lip)
- {
- struct xfs_rui_log_item *ruip;
- int error;
-
- ruip = container_of(lip, struct xfs_rui_log_item, rui_item);
- if (test_bit(XFS_RUI_RECOVERED, &ruip->rui_flags))
- return 0;
- spin_unlock(&ailp->xa_lock);
- error = xfs_rui_recover(mp, ruip);
- spin_lock(&ailp->xa_lock);
- return error;
- }
- STATIC void
- xlog_recover_cancel_rui(
- struct xfs_mount *mp,
- struct xfs_ail *ailp,
- struct xfs_log_item *lip)
- {
- struct xfs_rui_log_item *ruip;
- ruip = container_of(lip, struct xfs_rui_log_item, rui_item);
- spin_unlock(&ailp->xa_lock);
- xfs_rui_release(ruip);
- spin_lock(&ailp->xa_lock);
- }
- STATIC int
- xlog_recover_process_cui(
- struct xfs_mount *mp,
- struct xfs_ail *ailp,
- struct xfs_log_item *lip)
- {
- struct xfs_cui_log_item *cuip;
- int error;
-
- cuip = container_of(lip, struct xfs_cui_log_item, cui_item);
- if (test_bit(XFS_CUI_RECOVERED, &cuip->cui_flags))
- return 0;
- spin_unlock(&ailp->xa_lock);
- error = xfs_cui_recover(mp, cuip);
- spin_lock(&ailp->xa_lock);
- return error;
- }
- STATIC void
- xlog_recover_cancel_cui(
- struct xfs_mount *mp,
- struct xfs_ail *ailp,
- struct xfs_log_item *lip)
- {
- struct xfs_cui_log_item *cuip;
- cuip = container_of(lip, struct xfs_cui_log_item, cui_item);
- spin_unlock(&ailp->xa_lock);
- xfs_cui_release(cuip);
- spin_lock(&ailp->xa_lock);
- }
- STATIC int
- xlog_recover_process_bui(
- struct xfs_mount *mp,
- struct xfs_ail *ailp,
- struct xfs_log_item *lip)
- {
- struct xfs_bui_log_item *buip;
- int error;
-
- buip = container_of(lip, struct xfs_bui_log_item, bui_item);
- if (test_bit(XFS_BUI_RECOVERED, &buip->bui_flags))
- return 0;
- spin_unlock(&ailp->xa_lock);
- error = xfs_bui_recover(mp, buip);
- spin_lock(&ailp->xa_lock);
- return error;
- }
- STATIC void
- xlog_recover_cancel_bui(
- struct xfs_mount *mp,
- struct xfs_ail *ailp,
- struct xfs_log_item *lip)
- {
- struct xfs_bui_log_item *buip;
- buip = container_of(lip, struct xfs_bui_log_item, bui_item);
- spin_unlock(&ailp->xa_lock);
- xfs_bui_release(buip);
- spin_lock(&ailp->xa_lock);
- }
- static inline bool xlog_item_is_intent(struct xfs_log_item *lip)
- {
- switch (lip->li_type) {
- case XFS_LI_EFI:
- case XFS_LI_RUI:
- case XFS_LI_CUI:
- case XFS_LI_BUI:
- return true;
- default:
- return false;
- }
- }
- STATIC int
- xlog_recover_process_intents(
- struct xlog *log)
- {
- struct xfs_log_item *lip;
- int error = 0;
- struct xfs_ail_cursor cur;
- struct xfs_ail *ailp;
- #if defined(DEBUG) || defined(XFS_WARN)
- xfs_lsn_t last_lsn;
- #endif
- ailp = log->l_ailp;
- spin_lock(&ailp->xa_lock);
- lip = xfs_trans_ail_cursor_first(ailp, &cur, 0);
- #if defined(DEBUG) || defined(XFS_WARN)
- last_lsn = xlog_assign_lsn(log->l_curr_cycle, log->l_curr_block);
- #endif
- while (lip != NULL) {
-
- if (!xlog_item_is_intent(lip)) {
- #ifdef DEBUG
- for (; lip; lip = xfs_trans_ail_cursor_next(ailp, &cur))
- ASSERT(!xlog_item_is_intent(lip));
- #endif
- break;
- }
-
- ASSERT(XFS_LSN_CMP(last_lsn, lip->li_lsn) >= 0);
- switch (lip->li_type) {
- case XFS_LI_EFI:
- error = xlog_recover_process_efi(log->l_mp, ailp, lip);
- break;
- case XFS_LI_RUI:
- error = xlog_recover_process_rui(log->l_mp, ailp, lip);
- break;
- case XFS_LI_CUI:
- error = xlog_recover_process_cui(log->l_mp, ailp, lip);
- break;
- case XFS_LI_BUI:
- error = xlog_recover_process_bui(log->l_mp, ailp, lip);
- break;
- }
- if (error)
- goto out;
- lip = xfs_trans_ail_cursor_next(ailp, &cur);
- }
- out:
- xfs_trans_ail_cursor_done(&cur);
- spin_unlock(&ailp->xa_lock);
- return error;
- }
- STATIC int
- xlog_recover_cancel_intents(
- struct xlog *log)
- {
- struct xfs_log_item *lip;
- int error = 0;
- struct xfs_ail_cursor cur;
- struct xfs_ail *ailp;
- ailp = log->l_ailp;
- spin_lock(&ailp->xa_lock);
- lip = xfs_trans_ail_cursor_first(ailp, &cur, 0);
- while (lip != NULL) {
-
- if (!xlog_item_is_intent(lip)) {
- #ifdef DEBUG
- for (; lip; lip = xfs_trans_ail_cursor_next(ailp, &cur))
- ASSERT(!xlog_item_is_intent(lip));
- #endif
- break;
- }
- switch (lip->li_type) {
- case XFS_LI_EFI:
- xlog_recover_cancel_efi(log->l_mp, ailp, lip);
- break;
- case XFS_LI_RUI:
- xlog_recover_cancel_rui(log->l_mp, ailp, lip);
- break;
- case XFS_LI_CUI:
- xlog_recover_cancel_cui(log->l_mp, ailp, lip);
- break;
- case XFS_LI_BUI:
- xlog_recover_cancel_bui(log->l_mp, ailp, lip);
- break;
- }
- lip = xfs_trans_ail_cursor_next(ailp, &cur);
- }
- xfs_trans_ail_cursor_done(&cur);
- spin_unlock(&ailp->xa_lock);
- return error;
- }
- STATIC void
- xlog_recover_clear_agi_bucket(
- xfs_mount_t *mp,
- xfs_agnumber_t agno,
- int bucket)
- {
- xfs_trans_t *tp;
- xfs_agi_t *agi;
- xfs_buf_t *agibp;
- int offset;
- int error;
- error = xfs_trans_alloc(mp, &M_RES(mp)->tr_clearagi, 0, 0, 0, &tp);
- if (error)
- goto out_error;
- error = xfs_read_agi(mp, tp, agno, &agibp);
- if (error)
- goto out_abort;
- agi = XFS_BUF_TO_AGI(agibp);
- agi->agi_unlinked[bucket] = cpu_to_be32(NULLAGINO);
- offset = offsetof(xfs_agi_t, agi_unlinked) +
- (sizeof(xfs_agino_t) * bucket);
- xfs_trans_log_buf(tp, agibp, offset,
- (offset + sizeof(xfs_agino_t) - 1));
- error = xfs_trans_commit(tp);
- if (error)
- goto out_error;
- return;
- out_abort:
- xfs_trans_cancel(tp);
- out_error:
- xfs_warn(mp, "%s: failed to clear agi %d. Continuing.", __func__, agno);
- return;
- }
- STATIC xfs_agino_t
- xlog_recover_process_one_iunlink(
- struct xfs_mount *mp,
- xfs_agnumber_t agno,
- xfs_agino_t agino,
- int bucket)
- {
- struct xfs_buf *ibp;
- struct xfs_dinode *dip;
- struct xfs_inode *ip;
- xfs_ino_t ino;
- int error;
- ino = XFS_AGINO_TO_INO(mp, agno, agino);
- error = xfs_iget(mp, NULL, ino, 0, 0, &ip);
- if (error)
- goto fail;
-
- error = xfs_imap_to_bp(mp, NULL, &ip->i_imap, &dip, &ibp, 0, 0);
- if (error)
- goto fail_iput;
- xfs_iflags_clear(ip, XFS_IRECOVERY);
- ASSERT(VFS_I(ip)->i_nlink == 0);
- ASSERT(VFS_I(ip)->i_mode != 0);
-
- agino = be32_to_cpu(dip->di_next_unlinked);
- xfs_buf_relse(ibp);
-
- ip->i_d.di_dmevmask = 0;
- IRELE(ip);
- return agino;
- fail_iput:
- IRELE(ip);
- fail:
-
- xlog_recover_clear_agi_bucket(mp, agno, bucket);
- return NULLAGINO;
- }
- STATIC void
- xlog_recover_process_iunlinks(
- struct xlog *log)
- {
- xfs_mount_t *mp;
- xfs_agnumber_t agno;
- xfs_agi_t *agi;
- xfs_buf_t *agibp;
- xfs_agino_t agino;
- int bucket;
- int error;
- uint mp_dmevmask;
- mp = log->l_mp;
-
- mp_dmevmask = mp->m_dmevmask;
- mp->m_dmevmask = 0;
- for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
-
- error = xfs_read_agi(mp, NULL, agno, &agibp);
- if (error) {
-
- continue;
- }
-
- agi = XFS_BUF_TO_AGI(agibp);
- xfs_buf_unlock(agibp);
- for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++) {
- agino = be32_to_cpu(agi->agi_unlinked[bucket]);
- while (agino != NULLAGINO) {
- agino = xlog_recover_process_one_iunlink(mp,
- agno, agino, bucket);
- }
- }
- xfs_buf_rele(agibp);
- }
- mp->m_dmevmask = mp_dmevmask;
- }
- STATIC int
- xlog_unpack_data(
- struct xlog_rec_header *rhead,
- char *dp,
- struct xlog *log)
- {
- int i, j, k;
- for (i = 0; i < BTOBB(be32_to_cpu(rhead->h_len)) &&
- i < (XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++) {
- *(__be32 *)dp = *(__be32 *)&rhead->h_cycle_data[i];
- dp += BBSIZE;
- }
- if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
- xlog_in_core_2_t *xhdr = (xlog_in_core_2_t *)rhead;
- for ( ; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) {
- j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
- k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
- *(__be32 *)dp = xhdr[j].hic_xheader.xh_cycle_data[k];
- dp += BBSIZE;
- }
- }
- return 0;
- }
- STATIC int
- xlog_recover_process(
- struct xlog *log,
- struct hlist_head rhash[],
- struct xlog_rec_header *rhead,
- char *dp,
- int pass,
- struct list_head *buffer_list)
- {
- int error;
- __le32 crc;
- crc = xlog_cksum(log, rhead, dp, be32_to_cpu(rhead->h_len));
-
- if (pass == XLOG_RECOVER_CRCPASS) {
- if (rhead->h_crc && crc != rhead->h_crc)
- return -EFSBADCRC;
- return 0;
- }
-
- if (crc != rhead->h_crc) {
- if (rhead->h_crc || xfs_sb_version_hascrc(&log->l_mp->m_sb)) {
- xfs_alert(log->l_mp,
- "log record CRC mismatch: found 0x%x, expected 0x%x.",
- le32_to_cpu(rhead->h_crc),
- le32_to_cpu(crc));
- xfs_hex_dump(dp, 32);
- }
-
- if (xfs_sb_version_hascrc(&log->l_mp->m_sb))
- return -EFSCORRUPTED;
- }
- error = xlog_unpack_data(rhead, dp, log);
- if (error)
- return error;
- return xlog_recover_process_data(log, rhash, rhead, dp, pass,
- buffer_list);
- }
- STATIC int
- xlog_valid_rec_header(
- struct xlog *log,
- struct xlog_rec_header *rhead,
- xfs_daddr_t blkno)
- {
- int hlen;
- if (unlikely(rhead->h_magicno != cpu_to_be32(XLOG_HEADER_MAGIC_NUM))) {
- XFS_ERROR_REPORT("xlog_valid_rec_header(1)",
- XFS_ERRLEVEL_LOW, log->l_mp);
- return -EFSCORRUPTED;
- }
- if (unlikely(
- (!rhead->h_version ||
- (be32_to_cpu(rhead->h_version) & (~XLOG_VERSION_OKBITS))))) {
- xfs_warn(log->l_mp, "%s: unrecognised log version (%d).",
- __func__, be32_to_cpu(rhead->h_version));
- return -EIO;
- }
-
- hlen = be32_to_cpu(rhead->h_len);
- if (unlikely( hlen <= 0 || hlen > INT_MAX )) {
- XFS_ERROR_REPORT("xlog_valid_rec_header(2)",
- XFS_ERRLEVEL_LOW, log->l_mp);
- return -EFSCORRUPTED;
- }
- if (unlikely( blkno > log->l_logBBsize || blkno > INT_MAX )) {
- XFS_ERROR_REPORT("xlog_valid_rec_header(3)",
- XFS_ERRLEVEL_LOW, log->l_mp);
- return -EFSCORRUPTED;
- }
- return 0;
- }
- STATIC int
- xlog_do_recovery_pass(
- struct xlog *log,
- xfs_daddr_t head_blk,
- xfs_daddr_t tail_blk,
- int pass,
- xfs_daddr_t *first_bad)
- {
- xlog_rec_header_t *rhead;
- xfs_daddr_t blk_no, rblk_no;
- xfs_daddr_t rhead_blk;
- char *offset;
- xfs_buf_t *hbp, *dbp;
- int error = 0, h_size, h_len;
- int error2 = 0;
- int bblks, split_bblks;
- int hblks, split_hblks, wrapped_hblks;
- int i;
- struct hlist_head rhash[XLOG_RHASH_SIZE];
- LIST_HEAD (buffer_list);
- ASSERT(head_blk != tail_blk);
- blk_no = rhead_blk = tail_blk;
- for (i = 0; i < XLOG_RHASH_SIZE; i++)
- INIT_HLIST_HEAD(&rhash[i]);
-
- if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
-
- hbp = xlog_get_bp(log, 1);
- if (!hbp)
- return -ENOMEM;
- error = xlog_bread(log, tail_blk, 1, hbp, &offset);
- if (error)
- goto bread_err1;
- rhead = (xlog_rec_header_t *)offset;
- error = xlog_valid_rec_header(log, rhead, tail_blk);
- if (error)
- goto bread_err1;
-
- h_size = be32_to_cpu(rhead->h_size);
- h_len = be32_to_cpu(rhead->h_len);
- if (h_len > h_size) {
- if (h_len <= log->l_mp->m_logbsize &&
- be32_to_cpu(rhead->h_num_logops) == 1) {
- xfs_warn(log->l_mp,
- "invalid iclog size (%d bytes), using lsunit (%d bytes)",
- h_size, log->l_mp->m_logbsize);
- h_size = log->l_mp->m_logbsize;
- } else
- return -EFSCORRUPTED;
- }
- if ((be32_to_cpu(rhead->h_version) & XLOG_VERSION_2) &&
- (h_size > XLOG_HEADER_CYCLE_SIZE)) {
- hblks = h_size / XLOG_HEADER_CYCLE_SIZE;
- if (h_size % XLOG_HEADER_CYCLE_SIZE)
- hblks++;
- xlog_put_bp(hbp);
- hbp = xlog_get_bp(log, hblks);
- } else {
- hblks = 1;
- }
- } else {
- ASSERT(log->l_sectBBsize == 1);
- hblks = 1;
- hbp = xlog_get_bp(log, 1);
- h_size = XLOG_BIG_RECORD_BSIZE;
- }
- if (!hbp)
- return -ENOMEM;
- dbp = xlog_get_bp(log, BTOBB(h_size));
- if (!dbp) {
- xlog_put_bp(hbp);
- return -ENOMEM;
- }
- memset(rhash, 0, sizeof(rhash));
- if (tail_blk > head_blk) {
-
- while (blk_no < log->l_logBBsize) {
-
- offset = hbp->b_addr;
- split_hblks = 0;
- wrapped_hblks = 0;
- if (blk_no + hblks <= log->l_logBBsize) {
-
- error = xlog_bread(log, blk_no, hblks, hbp,
- &offset);
- if (error)
- goto bread_err2;
- } else {
-
- if (blk_no != log->l_logBBsize) {
-
- ASSERT(blk_no <= INT_MAX);
- split_hblks = log->l_logBBsize - (int)blk_no;
- ASSERT(split_hblks > 0);
- error = xlog_bread(log, blk_no,
- split_hblks, hbp,
- &offset);
- if (error)
- goto bread_err2;
- }
-
- wrapped_hblks = hblks - split_hblks;
- error = xlog_bread_offset(log, 0,
- wrapped_hblks, hbp,
- offset + BBTOB(split_hblks));
- if (error)
- goto bread_err2;
- }
- rhead = (xlog_rec_header_t *)offset;
- error = xlog_valid_rec_header(log, rhead,
- split_hblks ? blk_no : 0);
- if (error)
- goto bread_err2;
- bblks = (int)BTOBB(be32_to_cpu(rhead->h_len));
- blk_no += hblks;
-
- if (blk_no + bblks <= log->l_logBBsize ||
- blk_no >= log->l_logBBsize) {
-
- rblk_no = do_mod(blk_no, log->l_logBBsize);
- error = xlog_bread(log, rblk_no, bblks, dbp,
- &offset);
- if (error)
- goto bread_err2;
- } else {
-
- offset = dbp->b_addr;
- split_bblks = 0;
- if (blk_no != log->l_logBBsize) {
-
- ASSERT(!wrapped_hblks);
- ASSERT(blk_no <= INT_MAX);
- split_bblks =
- log->l_logBBsize - (int)blk_no;
- ASSERT(split_bblks > 0);
- error = xlog_bread(log, blk_no,
- split_bblks, dbp,
- &offset);
- if (error)
- goto bread_err2;
- }
-
- error = xlog_bread_offset(log, 0,
- bblks - split_bblks, dbp,
- offset + BBTOB(split_bblks));
- if (error)
- goto bread_err2;
- }
- error = xlog_recover_process(log, rhash, rhead, offset,
- pass, &buffer_list);
- if (error)
- goto bread_err2;
- blk_no += bblks;
- rhead_blk = blk_no;
- }
- ASSERT(blk_no >= log->l_logBBsize);
- blk_no -= log->l_logBBsize;
- rhead_blk = blk_no;
- }
-
- while (blk_no < head_blk) {
- error = xlog_bread(log, blk_no, hblks, hbp, &offset);
- if (error)
- goto bread_err2;
- rhead = (xlog_rec_header_t *)offset;
- error = xlog_valid_rec_header(log, rhead, blk_no);
- if (error)
- goto bread_err2;
-
- bblks = (int)BTOBB(be32_to_cpu(rhead->h_len));
- error = xlog_bread(log, blk_no+hblks, bblks, dbp,
- &offset);
- if (error)
- goto bread_err2;
- error = xlog_recover_process(log, rhash, rhead, offset, pass,
- &buffer_list);
- if (error)
- goto bread_err2;
- blk_no += bblks + hblks;
- rhead_blk = blk_no;
- }
- bread_err2:
- xlog_put_bp(dbp);
- bread_err1:
- xlog_put_bp(hbp);
-
- if (!list_empty(&buffer_list))
- error2 = xfs_buf_delwri_submit(&buffer_list);
- if (error && first_bad)
- *first_bad = rhead_blk;
-
- for (i = 0; i < XLOG_RHASH_SIZE; i++) {
- struct hlist_node *tmp;
- struct xlog_recover *trans;
- hlist_for_each_entry_safe(trans, tmp, &rhash[i], r_list)
- xlog_recover_free_trans(trans);
- }
- return error ? error : error2;
- }
- STATIC int
- xlog_do_log_recovery(
- struct xlog *log,
- xfs_daddr_t head_blk,
- xfs_daddr_t tail_blk)
- {
- int error, i;
- ASSERT(head_blk != tail_blk);
-
- log->l_buf_cancel_table = kmem_zalloc(XLOG_BC_TABLE_SIZE *
- sizeof(struct list_head),
- KM_SLEEP);
- for (i = 0; i < XLOG_BC_TABLE_SIZE; i++)
- INIT_LIST_HEAD(&log->l_buf_cancel_table[i]);
- error = xlog_do_recovery_pass(log, head_blk, tail_blk,
- XLOG_RECOVER_PASS1, NULL);
- if (error != 0) {
- kmem_free(log->l_buf_cancel_table);
- log->l_buf_cancel_table = NULL;
- return error;
- }
-
- error = xlog_do_recovery_pass(log, head_blk, tail_blk,
- XLOG_RECOVER_PASS2, NULL);
- #ifdef DEBUG
- if (!error) {
- int i;
- for (i = 0; i < XLOG_BC_TABLE_SIZE; i++)
- ASSERT(list_empty(&log->l_buf_cancel_table[i]));
- }
- #endif
- kmem_free(log->l_buf_cancel_table);
- log->l_buf_cancel_table = NULL;
- return error;
- }
- STATIC int
- xlog_do_recover(
- struct xlog *log,
- xfs_daddr_t head_blk,
- xfs_daddr_t tail_blk)
- {
- struct xfs_mount *mp = log->l_mp;
- int error;
- xfs_buf_t *bp;
- xfs_sb_t *sbp;
- trace_xfs_log_recover(log, head_blk, tail_blk);
-
- error = xlog_do_log_recovery(log, head_blk, tail_blk);
- if (error)
- return error;
-
- if (XFS_FORCED_SHUTDOWN(mp)) {
- return -EIO;
- }
-
- xlog_assign_tail_lsn(mp);
-
- bp = xfs_getsb(mp, 0);
- bp->b_flags &= ~(XBF_DONE | XBF_ASYNC);
- ASSERT(!(bp->b_flags & XBF_WRITE));
- bp->b_flags |= XBF_READ;
- bp->b_ops = &xfs_sb_buf_ops;
- error = xfs_buf_submit_wait(bp);
- if (error) {
- if (!XFS_FORCED_SHUTDOWN(mp)) {
- xfs_buf_ioerror_alert(bp, __func__);
- ASSERT(0);
- }
- xfs_buf_relse(bp);
- return error;
- }
-
- sbp = &mp->m_sb;
- xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp));
- xfs_buf_relse(bp);
-
- xfs_reinit_percpu_counters(mp);
- error = xfs_initialize_perag(mp, sbp->sb_agcount, &mp->m_maxagi);
- if (error) {
- xfs_warn(mp, "Failed post-recovery per-ag init: %d", error);
- return error;
- }
- mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
- xlog_recover_check_summary(log);
-
- log->l_flags &= ~XLOG_ACTIVE_RECOVERY;
- return 0;
- }
- int
- xlog_recover(
- struct xlog *log)
- {
- xfs_daddr_t head_blk, tail_blk;
- int error;
-
- error = xlog_find_tail(log, &head_blk, &tail_blk);
- if (error)
- return error;
-
- if (xfs_sb_version_hascrc(&log->l_mp->m_sb) &&
- !xfs_log_check_lsn(log->l_mp, log->l_mp->m_sb.sb_lsn))
- return -EINVAL;
- if (tail_blk != head_blk) {
-
- if ((error = xfs_dev_is_read_only(log->l_mp, "recovery"))) {
- return error;
- }
-
- if (XFS_SB_VERSION_NUM(&log->l_mp->m_sb) == XFS_SB_VERSION_5 &&
- xfs_sb_has_incompat_log_feature(&log->l_mp->m_sb,
- XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN)) {
- xfs_warn(log->l_mp,
- "Superblock has unknown incompatible log features (0x%x) enabled.",
- (log->l_mp->m_sb.sb_features_log_incompat &
- XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN));
- xfs_warn(log->l_mp,
- "The log can not be fully and/or safely recovered by this kernel.");
- xfs_warn(log->l_mp,
- "Please recover the log on a kernel that supports the unknown features.");
- return -EINVAL;
- }
-
- if (xfs_globals.log_recovery_delay) {
- xfs_notice(log->l_mp,
- "Delaying log recovery for %d seconds.",
- xfs_globals.log_recovery_delay);
- msleep(xfs_globals.log_recovery_delay * 1000);
- }
- xfs_notice(log->l_mp, "Starting recovery (logdev: %s)",
- log->l_mp->m_logname ? log->l_mp->m_logname
- : "internal");
- error = xlog_do_recover(log, head_blk, tail_blk);
- log->l_flags |= XLOG_RECOVERY_NEEDED;
- }
- return error;
- }
- int
- xlog_recover_finish(
- struct xlog *log)
- {
-
- if (log->l_flags & XLOG_RECOVERY_NEEDED) {
- int error;
- error = xlog_recover_process_intents(log);
- if (error) {
- xfs_alert(log->l_mp, "Failed to recover intents");
- return error;
- }
-
- xfs_log_force(log->l_mp, XFS_LOG_SYNC);
- xlog_recover_process_iunlinks(log);
- xlog_recover_check_summary(log);
- xfs_notice(log->l_mp, "Ending recovery (logdev: %s)",
- log->l_mp->m_logname ? log->l_mp->m_logname
- : "internal");
- log->l_flags &= ~XLOG_RECOVERY_NEEDED;
- } else {
- xfs_info(log->l_mp, "Ending clean mount");
- }
- return 0;
- }
- int
- xlog_recover_cancel(
- struct xlog *log)
- {
- int error = 0;
- if (log->l_flags & XLOG_RECOVERY_NEEDED)
- error = xlog_recover_cancel_intents(log);
- return error;
- }
- #if defined(DEBUG)
- void
- xlog_recover_check_summary(
- struct xlog *log)
- {
- xfs_mount_t *mp;
- xfs_agf_t *agfp;
- xfs_buf_t *agfbp;
- xfs_buf_t *agibp;
- xfs_agnumber_t agno;
- __uint64_t freeblks;
- __uint64_t itotal;
- __uint64_t ifree;
- int error;
- mp = log->l_mp;
- freeblks = 0LL;
- itotal = 0LL;
- ifree = 0LL;
- for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
- error = xfs_read_agf(mp, NULL, agno, 0, &agfbp);
- if (error) {
- xfs_alert(mp, "%s agf read failed agno %d error %d",
- __func__, agno, error);
- } else {
- agfp = XFS_BUF_TO_AGF(agfbp);
- freeblks += be32_to_cpu(agfp->agf_freeblks) +
- be32_to_cpu(agfp->agf_flcount);
- xfs_buf_relse(agfbp);
- }
- error = xfs_read_agi(mp, NULL, agno, &agibp);
- if (error) {
- xfs_alert(mp, "%s agi read failed agno %d error %d",
- __func__, agno, error);
- } else {
- struct xfs_agi *agi = XFS_BUF_TO_AGI(agibp);
- itotal += be32_to_cpu(agi->agi_count);
- ifree += be32_to_cpu(agi->agi_freecount);
- xfs_buf_relse(agibp);
- }
- }
- }
- #endif
|