1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869 |
- #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 = min_t(int, log_bbnum, 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
|