ctree.h 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528
  1. /*
  2. * Copyright (C) 2007 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #ifndef __BTRFS_CTREE__
  19. #define __BTRFS_CTREE__
  20. #include <linux/mm.h>
  21. #include <linux/highmem.h>
  22. #include <linux/fs.h>
  23. #include <linux/rwsem.h>
  24. #include <linux/completion.h>
  25. #include <linux/backing-dev.h>
  26. #include <linux/wait.h>
  27. #include <linux/slab.h>
  28. #include <linux/kobject.h>
  29. #include <trace/events/btrfs.h>
  30. #include <asm/kmap_types.h>
  31. #include <linux/pagemap.h>
  32. #include "extent_io.h"
  33. #include "extent_map.h"
  34. #include "async-thread.h"
  35. #include "ioctl.h"
  36. struct btrfs_trans_handle;
  37. struct btrfs_transaction;
  38. struct btrfs_pending_snapshot;
  39. extern struct kmem_cache *btrfs_trans_handle_cachep;
  40. extern struct kmem_cache *btrfs_transaction_cachep;
  41. extern struct kmem_cache *btrfs_bit_radix_cachep;
  42. extern struct kmem_cache *btrfs_path_cachep;
  43. extern struct kmem_cache *btrfs_free_space_cachep;
  44. struct btrfs_ordered_sum;
  45. #define BTRFS_MAGIC "_BHRfS_M"
  46. #define BTRFS_MAX_MIRRORS 2
  47. #define BTRFS_MAX_LEVEL 8
  48. #define BTRFS_COMPAT_EXTENT_TREE_V0
  49. /*
  50. * files bigger than this get some pre-flushing when they are added
  51. * to the ordered operations list. That way we limit the total
  52. * work done by the commit
  53. */
  54. #define BTRFS_ORDERED_OPERATIONS_FLUSH_LIMIT (8 * 1024 * 1024)
  55. /* holds pointers to all of the tree roots */
  56. #define BTRFS_ROOT_TREE_OBJECTID 1ULL
  57. /* stores information about which extents are in use, and reference counts */
  58. #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
  59. /*
  60. * chunk tree stores translations from logical -> physical block numbering
  61. * the super block points to the chunk tree
  62. */
  63. #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
  64. /*
  65. * stores information about which areas of a given device are in use.
  66. * one per device. The tree of tree roots points to the device tree
  67. */
  68. #define BTRFS_DEV_TREE_OBJECTID 4ULL
  69. /* one per subvolume, storing files and directories */
  70. #define BTRFS_FS_TREE_OBJECTID 5ULL
  71. /* directory objectid inside the root tree */
  72. #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
  73. /* holds checksums of all the data extents */
  74. #define BTRFS_CSUM_TREE_OBJECTID 7ULL
  75. /* for storing balance parameters in the root tree */
  76. #define BTRFS_BALANCE_OBJECTID -4ULL
  77. /* holds quota configuration and tracking */
  78. #define BTRFS_QUOTA_TREE_OBJECTID 8ULL
  79. /* orhpan objectid for tracking unlinked/truncated files */
  80. #define BTRFS_ORPHAN_OBJECTID -5ULL
  81. /* does write ahead logging to speed up fsyncs */
  82. #define BTRFS_TREE_LOG_OBJECTID -6ULL
  83. #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
  84. /* for space balancing */
  85. #define BTRFS_TREE_RELOC_OBJECTID -8ULL
  86. #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
  87. /*
  88. * extent checksums all have this objectid
  89. * this allows them to share the logging tree
  90. * for fsyncs
  91. */
  92. #define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
  93. /* For storing free space cache */
  94. #define BTRFS_FREE_SPACE_OBJECTID -11ULL
  95. /*
  96. * The inode number assigned to the special inode for sotring
  97. * free ino cache
  98. */
  99. #define BTRFS_FREE_INO_OBJECTID -12ULL
  100. /* dummy objectid represents multiple objectids */
  101. #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
  102. /*
  103. * All files have objectids in this range.
  104. */
  105. #define BTRFS_FIRST_FREE_OBJECTID 256ULL
  106. #define BTRFS_LAST_FREE_OBJECTID -256ULL
  107. #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
  108. /*
  109. * the device items go into the chunk tree. The key is in the form
  110. * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
  111. */
  112. #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
  113. #define BTRFS_BTREE_INODE_OBJECTID 1
  114. #define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
  115. /*
  116. * the max metadata block size. This limit is somewhat artificial,
  117. * but the memmove costs go through the roof for larger blocks.
  118. */
  119. #define BTRFS_MAX_METADATA_BLOCKSIZE 65536
  120. /*
  121. * we can actually store much bigger names, but lets not confuse the rest
  122. * of linux
  123. */
  124. #define BTRFS_NAME_LEN 255
  125. /* 32 bytes in various csum fields */
  126. #define BTRFS_CSUM_SIZE 32
  127. /* csum types */
  128. #define BTRFS_CSUM_TYPE_CRC32 0
  129. static int btrfs_csum_sizes[] = { 4, 0 };
  130. /* four bytes for CRC32 */
  131. #define BTRFS_EMPTY_DIR_SIZE 0
  132. #define BTRFS_FT_UNKNOWN 0
  133. #define BTRFS_FT_REG_FILE 1
  134. #define BTRFS_FT_DIR 2
  135. #define BTRFS_FT_CHRDEV 3
  136. #define BTRFS_FT_BLKDEV 4
  137. #define BTRFS_FT_FIFO 5
  138. #define BTRFS_FT_SOCK 6
  139. #define BTRFS_FT_SYMLINK 7
  140. #define BTRFS_FT_XATTR 8
  141. #define BTRFS_FT_MAX 9
  142. /* ioprio of readahead is set to idle */
  143. #define BTRFS_IOPRIO_READA (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0))
  144. /*
  145. * The key defines the order in the tree, and so it also defines (optimal)
  146. * block layout.
  147. *
  148. * objectid corresponds to the inode number.
  149. *
  150. * type tells us things about the object, and is a kind of stream selector.
  151. * so for a given inode, keys with type of 1 might refer to the inode data,
  152. * type of 2 may point to file data in the btree and type == 3 may point to
  153. * extents.
  154. *
  155. * offset is the starting byte offset for this key in the stream.
  156. *
  157. * btrfs_disk_key is in disk byte order. struct btrfs_key is always
  158. * in cpu native order. Otherwise they are identical and their sizes
  159. * should be the same (ie both packed)
  160. */
  161. struct btrfs_disk_key {
  162. __le64 objectid;
  163. u8 type;
  164. __le64 offset;
  165. } __attribute__ ((__packed__));
  166. struct btrfs_key {
  167. u64 objectid;
  168. u8 type;
  169. u64 offset;
  170. } __attribute__ ((__packed__));
  171. struct btrfs_mapping_tree {
  172. struct extent_map_tree map_tree;
  173. };
  174. struct btrfs_dev_item {
  175. /* the internal btrfs device id */
  176. __le64 devid;
  177. /* size of the device */
  178. __le64 total_bytes;
  179. /* bytes used */
  180. __le64 bytes_used;
  181. /* optimal io alignment for this device */
  182. __le32 io_align;
  183. /* optimal io width for this device */
  184. __le32 io_width;
  185. /* minimal io size for this device */
  186. __le32 sector_size;
  187. /* type and info about this device */
  188. __le64 type;
  189. /* expected generation for this device */
  190. __le64 generation;
  191. /*
  192. * starting byte of this partition on the device,
  193. * to allow for stripe alignment in the future
  194. */
  195. __le64 start_offset;
  196. /* grouping information for allocation decisions */
  197. __le32 dev_group;
  198. /* seek speed 0-100 where 100 is fastest */
  199. u8 seek_speed;
  200. /* bandwidth 0-100 where 100 is fastest */
  201. u8 bandwidth;
  202. /* btrfs generated uuid for this device */
  203. u8 uuid[BTRFS_UUID_SIZE];
  204. /* uuid of FS who owns this device */
  205. u8 fsid[BTRFS_UUID_SIZE];
  206. } __attribute__ ((__packed__));
  207. struct btrfs_stripe {
  208. __le64 devid;
  209. __le64 offset;
  210. u8 dev_uuid[BTRFS_UUID_SIZE];
  211. } __attribute__ ((__packed__));
  212. struct btrfs_chunk {
  213. /* size of this chunk in bytes */
  214. __le64 length;
  215. /* objectid of the root referencing this chunk */
  216. __le64 owner;
  217. __le64 stripe_len;
  218. __le64 type;
  219. /* optimal io alignment for this chunk */
  220. __le32 io_align;
  221. /* optimal io width for this chunk */
  222. __le32 io_width;
  223. /* minimal io size for this chunk */
  224. __le32 sector_size;
  225. /* 2^16 stripes is quite a lot, a second limit is the size of a single
  226. * item in the btree
  227. */
  228. __le16 num_stripes;
  229. /* sub stripes only matter for raid10 */
  230. __le16 sub_stripes;
  231. struct btrfs_stripe stripe;
  232. /* additional stripes go here */
  233. } __attribute__ ((__packed__));
  234. #define BTRFS_FREE_SPACE_EXTENT 1
  235. #define BTRFS_FREE_SPACE_BITMAP 2
  236. struct btrfs_free_space_entry {
  237. __le64 offset;
  238. __le64 bytes;
  239. u8 type;
  240. } __attribute__ ((__packed__));
  241. struct btrfs_free_space_header {
  242. struct btrfs_disk_key location;
  243. __le64 generation;
  244. __le64 num_entries;
  245. __le64 num_bitmaps;
  246. } __attribute__ ((__packed__));
  247. static inline unsigned long btrfs_chunk_item_size(int num_stripes)
  248. {
  249. BUG_ON(num_stripes == 0);
  250. return sizeof(struct btrfs_chunk) +
  251. sizeof(struct btrfs_stripe) * (num_stripes - 1);
  252. }
  253. #define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
  254. #define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
  255. /*
  256. * File system states
  257. */
  258. /* Errors detected */
  259. #define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
  260. #define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
  261. #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
  262. #define BTRFS_BACKREF_REV_MAX 256
  263. #define BTRFS_BACKREF_REV_SHIFT 56
  264. #define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
  265. BTRFS_BACKREF_REV_SHIFT)
  266. #define BTRFS_OLD_BACKREF_REV 0
  267. #define BTRFS_MIXED_BACKREF_REV 1
  268. /*
  269. * every tree block (leaf or node) starts with this header.
  270. */
  271. struct btrfs_header {
  272. /* these first four must match the super block */
  273. u8 csum[BTRFS_CSUM_SIZE];
  274. u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
  275. __le64 bytenr; /* which block this node is supposed to live in */
  276. __le64 flags;
  277. /* allowed to be different from the super from here on down */
  278. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  279. __le64 generation;
  280. __le64 owner;
  281. __le32 nritems;
  282. u8 level;
  283. } __attribute__ ((__packed__));
  284. #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
  285. sizeof(struct btrfs_header)) / \
  286. sizeof(struct btrfs_key_ptr))
  287. #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
  288. #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
  289. #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
  290. sizeof(struct btrfs_item) - \
  291. sizeof(struct btrfs_file_extent_item))
  292. #define BTRFS_MAX_XATTR_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
  293. sizeof(struct btrfs_item) -\
  294. sizeof(struct btrfs_dir_item))
  295. /*
  296. * this is a very generous portion of the super block, giving us
  297. * room to translate 14 chunks with 3 stripes each.
  298. */
  299. #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
  300. #define BTRFS_LABEL_SIZE 256
  301. /*
  302. * just in case we somehow lose the roots and are not able to mount,
  303. * we store an array of the roots from previous transactions
  304. * in the super.
  305. */
  306. #define BTRFS_NUM_BACKUP_ROOTS 4
  307. struct btrfs_root_backup {
  308. __le64 tree_root;
  309. __le64 tree_root_gen;
  310. __le64 chunk_root;
  311. __le64 chunk_root_gen;
  312. __le64 extent_root;
  313. __le64 extent_root_gen;
  314. __le64 fs_root;
  315. __le64 fs_root_gen;
  316. __le64 dev_root;
  317. __le64 dev_root_gen;
  318. __le64 csum_root;
  319. __le64 csum_root_gen;
  320. __le64 total_bytes;
  321. __le64 bytes_used;
  322. __le64 num_devices;
  323. /* future */
  324. __le64 unsed_64[4];
  325. u8 tree_root_level;
  326. u8 chunk_root_level;
  327. u8 extent_root_level;
  328. u8 fs_root_level;
  329. u8 dev_root_level;
  330. u8 csum_root_level;
  331. /* future and to align */
  332. u8 unused_8[10];
  333. } __attribute__ ((__packed__));
  334. /*
  335. * the super block basically lists the main trees of the FS
  336. * it currently lacks any block count etc etc
  337. */
  338. struct btrfs_super_block {
  339. u8 csum[BTRFS_CSUM_SIZE];
  340. /* the first 4 fields must match struct btrfs_header */
  341. u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
  342. __le64 bytenr; /* this block number */
  343. __le64 flags;
  344. /* allowed to be different from the btrfs_header from here own down */
  345. __le64 magic;
  346. __le64 generation;
  347. __le64 root;
  348. __le64 chunk_root;
  349. __le64 log_root;
  350. /* this will help find the new super based on the log root */
  351. __le64 log_root_transid;
  352. __le64 total_bytes;
  353. __le64 bytes_used;
  354. __le64 root_dir_objectid;
  355. __le64 num_devices;
  356. __le32 sectorsize;
  357. __le32 nodesize;
  358. __le32 leafsize;
  359. __le32 stripesize;
  360. __le32 sys_chunk_array_size;
  361. __le64 chunk_root_generation;
  362. __le64 compat_flags;
  363. __le64 compat_ro_flags;
  364. __le64 incompat_flags;
  365. __le16 csum_type;
  366. u8 root_level;
  367. u8 chunk_root_level;
  368. u8 log_root_level;
  369. struct btrfs_dev_item dev_item;
  370. char label[BTRFS_LABEL_SIZE];
  371. __le64 cache_generation;
  372. /* future expansion */
  373. __le64 reserved[31];
  374. u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
  375. struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
  376. } __attribute__ ((__packed__));
  377. /*
  378. * Compat flags that we support. If any incompat flags are set other than the
  379. * ones specified below then we will fail to mount
  380. */
  381. #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
  382. #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
  383. #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
  384. #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
  385. /*
  386. * some patches floated around with a second compression method
  387. * lets save that incompat here for when they do get in
  388. * Note we don't actually support it, we're just reserving the
  389. * number
  390. */
  391. #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2 (1ULL << 4)
  392. /*
  393. * older kernels tried to do bigger metadata blocks, but the
  394. * code was pretty buggy. Lets not let them try anymore.
  395. */
  396. #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
  397. #define BTRFS_FEATURE_COMPAT_SUPP 0ULL
  398. #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL
  399. #define BTRFS_FEATURE_INCOMPAT_SUPP \
  400. (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
  401. BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
  402. BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
  403. BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
  404. BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO)
  405. /*
  406. * A leaf is full of items. offset and size tell us where to find
  407. * the item in the leaf (relative to the start of the data area)
  408. */
  409. struct btrfs_item {
  410. struct btrfs_disk_key key;
  411. __le32 offset;
  412. __le32 size;
  413. } __attribute__ ((__packed__));
  414. /*
  415. * leaves have an item area and a data area:
  416. * [item0, item1....itemN] [free space] [dataN...data1, data0]
  417. *
  418. * The data is separate from the items to get the keys closer together
  419. * during searches.
  420. */
  421. struct btrfs_leaf {
  422. struct btrfs_header header;
  423. struct btrfs_item items[];
  424. } __attribute__ ((__packed__));
  425. /*
  426. * all non-leaf blocks are nodes, they hold only keys and pointers to
  427. * other blocks
  428. */
  429. struct btrfs_key_ptr {
  430. struct btrfs_disk_key key;
  431. __le64 blockptr;
  432. __le64 generation;
  433. } __attribute__ ((__packed__));
  434. struct btrfs_node {
  435. struct btrfs_header header;
  436. struct btrfs_key_ptr ptrs[];
  437. } __attribute__ ((__packed__));
  438. /*
  439. * btrfs_paths remember the path taken from the root down to the leaf.
  440. * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
  441. * to any other levels that are present.
  442. *
  443. * The slots array records the index of the item or block pointer
  444. * used while walking the tree.
  445. */
  446. struct btrfs_path {
  447. struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
  448. int slots[BTRFS_MAX_LEVEL];
  449. /* if there is real range locking, this locks field will change */
  450. int locks[BTRFS_MAX_LEVEL];
  451. int reada;
  452. /* keep some upper locks as we walk down */
  453. int lowest_level;
  454. /*
  455. * set by btrfs_split_item, tells search_slot to keep all locks
  456. * and to force calls to keep space in the nodes
  457. */
  458. unsigned int search_for_split:1;
  459. unsigned int keep_locks:1;
  460. unsigned int skip_locking:1;
  461. unsigned int leave_spinning:1;
  462. unsigned int search_commit_root:1;
  463. };
  464. /*
  465. * items in the extent btree are used to record the objectid of the
  466. * owner of the block and the number of references
  467. */
  468. struct btrfs_extent_item {
  469. __le64 refs;
  470. __le64 generation;
  471. __le64 flags;
  472. } __attribute__ ((__packed__));
  473. struct btrfs_extent_item_v0 {
  474. __le32 refs;
  475. } __attribute__ ((__packed__));
  476. #define BTRFS_MAX_EXTENT_ITEM_SIZE(r) ((BTRFS_LEAF_DATA_SIZE(r) >> 4) - \
  477. sizeof(struct btrfs_item))
  478. #define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
  479. #define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
  480. /* following flags only apply to tree blocks */
  481. /* use full backrefs for extent pointers in the block */
  482. #define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
  483. /*
  484. * this flag is only used internally by scrub and may be changed at any time
  485. * it is only declared here to avoid collisions
  486. */
  487. #define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
  488. struct btrfs_tree_block_info {
  489. struct btrfs_disk_key key;
  490. u8 level;
  491. } __attribute__ ((__packed__));
  492. struct btrfs_extent_data_ref {
  493. __le64 root;
  494. __le64 objectid;
  495. __le64 offset;
  496. __le32 count;
  497. } __attribute__ ((__packed__));
  498. struct btrfs_shared_data_ref {
  499. __le32 count;
  500. } __attribute__ ((__packed__));
  501. struct btrfs_extent_inline_ref {
  502. u8 type;
  503. __le64 offset;
  504. } __attribute__ ((__packed__));
  505. /* old style backrefs item */
  506. struct btrfs_extent_ref_v0 {
  507. __le64 root;
  508. __le64 generation;
  509. __le64 objectid;
  510. __le32 count;
  511. } __attribute__ ((__packed__));
  512. /* dev extents record free space on individual devices. The owner
  513. * field points back to the chunk allocation mapping tree that allocated
  514. * the extent. The chunk tree uuid field is a way to double check the owner
  515. */
  516. struct btrfs_dev_extent {
  517. __le64 chunk_tree;
  518. __le64 chunk_objectid;
  519. __le64 chunk_offset;
  520. __le64 length;
  521. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  522. } __attribute__ ((__packed__));
  523. struct btrfs_inode_ref {
  524. __le64 index;
  525. __le16 name_len;
  526. /* name goes here */
  527. } __attribute__ ((__packed__));
  528. struct btrfs_timespec {
  529. __le64 sec;
  530. __le32 nsec;
  531. } __attribute__ ((__packed__));
  532. enum btrfs_compression_type {
  533. BTRFS_COMPRESS_NONE = 0,
  534. BTRFS_COMPRESS_ZLIB = 1,
  535. BTRFS_COMPRESS_LZO = 2,
  536. BTRFS_COMPRESS_TYPES = 2,
  537. BTRFS_COMPRESS_LAST = 3,
  538. };
  539. struct btrfs_inode_item {
  540. /* nfs style generation number */
  541. __le64 generation;
  542. /* transid that last touched this inode */
  543. __le64 transid;
  544. __le64 size;
  545. __le64 nbytes;
  546. __le64 block_group;
  547. __le32 nlink;
  548. __le32 uid;
  549. __le32 gid;
  550. __le32 mode;
  551. __le64 rdev;
  552. __le64 flags;
  553. /* modification sequence number for NFS */
  554. __le64 sequence;
  555. /*
  556. * a little future expansion, for more than this we can
  557. * just grow the inode item and version it
  558. */
  559. __le64 reserved[4];
  560. struct btrfs_timespec atime;
  561. struct btrfs_timespec ctime;
  562. struct btrfs_timespec mtime;
  563. struct btrfs_timespec otime;
  564. } __attribute__ ((__packed__));
  565. struct btrfs_dir_log_item {
  566. __le64 end;
  567. } __attribute__ ((__packed__));
  568. struct btrfs_dir_item {
  569. struct btrfs_disk_key location;
  570. __le64 transid;
  571. __le16 data_len;
  572. __le16 name_len;
  573. u8 type;
  574. } __attribute__ ((__packed__));
  575. #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
  576. struct btrfs_root_item {
  577. struct btrfs_inode_item inode;
  578. __le64 generation;
  579. __le64 root_dirid;
  580. __le64 bytenr;
  581. __le64 byte_limit;
  582. __le64 bytes_used;
  583. __le64 last_snapshot;
  584. __le64 flags;
  585. __le32 refs;
  586. struct btrfs_disk_key drop_progress;
  587. u8 drop_level;
  588. u8 level;
  589. /*
  590. * The following fields appear after subvol_uuids+subvol_times
  591. * were introduced.
  592. */
  593. /*
  594. * This generation number is used to test if the new fields are valid
  595. * and up to date while reading the root item. Everytime the root item
  596. * is written out, the "generation" field is copied into this field. If
  597. * anyone ever mounted the fs with an older kernel, we will have
  598. * mismatching generation values here and thus must invalidate the
  599. * new fields. See btrfs_update_root and btrfs_find_last_root for
  600. * details.
  601. * the offset of generation_v2 is also used as the start for the memset
  602. * when invalidating the fields.
  603. */
  604. __le64 generation_v2;
  605. u8 uuid[BTRFS_UUID_SIZE];
  606. u8 parent_uuid[BTRFS_UUID_SIZE];
  607. u8 received_uuid[BTRFS_UUID_SIZE];
  608. __le64 ctransid; /* updated when an inode changes */
  609. __le64 otransid; /* trans when created */
  610. __le64 stransid; /* trans when sent. non-zero for received subvol */
  611. __le64 rtransid; /* trans when received. non-zero for received subvol */
  612. struct btrfs_timespec ctime;
  613. struct btrfs_timespec otime;
  614. struct btrfs_timespec stime;
  615. struct btrfs_timespec rtime;
  616. __le64 reserved[8]; /* for future */
  617. } __attribute__ ((__packed__));
  618. /*
  619. * this is used for both forward and backward root refs
  620. */
  621. struct btrfs_root_ref {
  622. __le64 dirid;
  623. __le64 sequence;
  624. __le16 name_len;
  625. } __attribute__ ((__packed__));
  626. struct btrfs_disk_balance_args {
  627. /*
  628. * profiles to operate on, single is denoted by
  629. * BTRFS_AVAIL_ALLOC_BIT_SINGLE
  630. */
  631. __le64 profiles;
  632. /* usage filter */
  633. __le64 usage;
  634. /* devid filter */
  635. __le64 devid;
  636. /* devid subset filter [pstart..pend) */
  637. __le64 pstart;
  638. __le64 pend;
  639. /* btrfs virtual address space subset filter [vstart..vend) */
  640. __le64 vstart;
  641. __le64 vend;
  642. /*
  643. * profile to convert to, single is denoted by
  644. * BTRFS_AVAIL_ALLOC_BIT_SINGLE
  645. */
  646. __le64 target;
  647. /* BTRFS_BALANCE_ARGS_* */
  648. __le64 flags;
  649. __le64 unused[8];
  650. } __attribute__ ((__packed__));
  651. /*
  652. * store balance parameters to disk so that balance can be properly
  653. * resumed after crash or unmount
  654. */
  655. struct btrfs_balance_item {
  656. /* BTRFS_BALANCE_* */
  657. __le64 flags;
  658. struct btrfs_disk_balance_args data;
  659. struct btrfs_disk_balance_args meta;
  660. struct btrfs_disk_balance_args sys;
  661. __le64 unused[4];
  662. } __attribute__ ((__packed__));
  663. #define BTRFS_FILE_EXTENT_INLINE 0
  664. #define BTRFS_FILE_EXTENT_REG 1
  665. #define BTRFS_FILE_EXTENT_PREALLOC 2
  666. struct btrfs_file_extent_item {
  667. /*
  668. * transaction id that created this extent
  669. */
  670. __le64 generation;
  671. /*
  672. * max number of bytes to hold this extent in ram
  673. * when we split a compressed extent we can't know how big
  674. * each of the resulting pieces will be. So, this is
  675. * an upper limit on the size of the extent in ram instead of
  676. * an exact limit.
  677. */
  678. __le64 ram_bytes;
  679. /*
  680. * 32 bits for the various ways we might encode the data,
  681. * including compression and encryption. If any of these
  682. * are set to something a given disk format doesn't understand
  683. * it is treated like an incompat flag for reading and writing,
  684. * but not for stat.
  685. */
  686. u8 compression;
  687. u8 encryption;
  688. __le16 other_encoding; /* spare for later use */
  689. /* are we inline data or a real extent? */
  690. u8 type;
  691. /*
  692. * disk space consumed by the extent, checksum blocks are included
  693. * in these numbers
  694. */
  695. __le64 disk_bytenr;
  696. __le64 disk_num_bytes;
  697. /*
  698. * the logical offset in file blocks (no csums)
  699. * this extent record is for. This allows a file extent to point
  700. * into the middle of an existing extent on disk, sharing it
  701. * between two snapshots (useful if some bytes in the middle of the
  702. * extent have changed
  703. */
  704. __le64 offset;
  705. /*
  706. * the logical number of file blocks (no csums included). This
  707. * always reflects the size uncompressed and without encoding.
  708. */
  709. __le64 num_bytes;
  710. } __attribute__ ((__packed__));
  711. struct btrfs_csum_item {
  712. u8 csum;
  713. } __attribute__ ((__packed__));
  714. struct btrfs_dev_stats_item {
  715. /*
  716. * grow this item struct at the end for future enhancements and keep
  717. * the existing values unchanged
  718. */
  719. __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
  720. } __attribute__ ((__packed__));
  721. /* different types of block groups (and chunks) */
  722. #define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
  723. #define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
  724. #define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
  725. #define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
  726. #define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
  727. #define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
  728. #define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
  729. #define BTRFS_BLOCK_GROUP_RESERVED BTRFS_AVAIL_ALLOC_BIT_SINGLE
  730. #define BTRFS_NR_RAID_TYPES 5
  731. #define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
  732. BTRFS_BLOCK_GROUP_SYSTEM | \
  733. BTRFS_BLOCK_GROUP_METADATA)
  734. #define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
  735. BTRFS_BLOCK_GROUP_RAID1 | \
  736. BTRFS_BLOCK_GROUP_DUP | \
  737. BTRFS_BLOCK_GROUP_RAID10)
  738. /*
  739. * We need a bit for restriper to be able to tell when chunks of type
  740. * SINGLE are available. This "extended" profile format is used in
  741. * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
  742. * (on-disk). The corresponding on-disk bit in chunk.type is reserved
  743. * to avoid remappings between two formats in future.
  744. */
  745. #define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
  746. #define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
  747. BTRFS_AVAIL_ALLOC_BIT_SINGLE)
  748. static inline u64 chunk_to_extended(u64 flags)
  749. {
  750. if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
  751. flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
  752. return flags;
  753. }
  754. static inline u64 extended_to_chunk(u64 flags)
  755. {
  756. return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
  757. }
  758. struct btrfs_block_group_item {
  759. __le64 used;
  760. __le64 chunk_objectid;
  761. __le64 flags;
  762. } __attribute__ ((__packed__));
  763. /*
  764. * is subvolume quota turned on?
  765. */
  766. #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
  767. /*
  768. * SCANNING is set during the initialization phase
  769. */
  770. #define BTRFS_QGROUP_STATUS_FLAG_SCANNING (1ULL << 1)
  771. /*
  772. * Some qgroup entries are known to be out of date,
  773. * either because the configuration has changed in a way that
  774. * makes a rescan necessary, or because the fs has been mounted
  775. * with a non-qgroup-aware version.
  776. * Turning qouta off and on again makes it inconsistent, too.
  777. */
  778. #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
  779. #define BTRFS_QGROUP_STATUS_VERSION 1
  780. struct btrfs_qgroup_status_item {
  781. __le64 version;
  782. /*
  783. * the generation is updated during every commit. As older
  784. * versions of btrfs are not aware of qgroups, it will be
  785. * possible to detect inconsistencies by checking the
  786. * generation on mount time
  787. */
  788. __le64 generation;
  789. /* flag definitions see above */
  790. __le64 flags;
  791. /*
  792. * only used during scanning to record the progress
  793. * of the scan. It contains a logical address
  794. */
  795. __le64 scan;
  796. } __attribute__ ((__packed__));
  797. struct btrfs_qgroup_info_item {
  798. __le64 generation;
  799. __le64 rfer;
  800. __le64 rfer_cmpr;
  801. __le64 excl;
  802. __le64 excl_cmpr;
  803. } __attribute__ ((__packed__));
  804. /* flags definition for qgroup limits */
  805. #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
  806. #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
  807. #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
  808. #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
  809. #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
  810. #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
  811. struct btrfs_qgroup_limit_item {
  812. /*
  813. * only updated when any of the other values change
  814. */
  815. __le64 flags;
  816. __le64 max_rfer;
  817. __le64 max_excl;
  818. __le64 rsv_rfer;
  819. __le64 rsv_excl;
  820. } __attribute__ ((__packed__));
  821. struct btrfs_space_info {
  822. u64 flags;
  823. u64 total_bytes; /* total bytes in the space,
  824. this doesn't take mirrors into account */
  825. u64 bytes_used; /* total bytes used,
  826. this doesn't take mirrors into account */
  827. u64 bytes_pinned; /* total bytes pinned, will be freed when the
  828. transaction finishes */
  829. u64 bytes_reserved; /* total bytes the allocator has reserved for
  830. current allocations */
  831. u64 bytes_readonly; /* total bytes that are read only */
  832. u64 bytes_may_use; /* number of bytes that may be used for
  833. delalloc/allocations */
  834. u64 disk_used; /* total bytes used on disk */
  835. u64 disk_total; /* total bytes on disk, takes mirrors into
  836. account */
  837. /*
  838. * we bump reservation progress every time we decrement
  839. * bytes_reserved. This way people waiting for reservations
  840. * know something good has happened and they can check
  841. * for progress. The number here isn't to be trusted, it
  842. * just shows reclaim activity
  843. */
  844. unsigned long reservation_progress;
  845. unsigned int full:1; /* indicates that we cannot allocate any more
  846. chunks for this space */
  847. unsigned int chunk_alloc:1; /* set if we are allocating a chunk */
  848. unsigned int flush:1; /* set if we are trying to make space */
  849. unsigned int force_alloc; /* set if we need to force a chunk
  850. alloc for this space */
  851. struct list_head list;
  852. /* for block groups in our same type */
  853. struct list_head block_groups[BTRFS_NR_RAID_TYPES];
  854. spinlock_t lock;
  855. struct rw_semaphore groups_sem;
  856. wait_queue_head_t wait;
  857. };
  858. struct btrfs_block_rsv {
  859. u64 size;
  860. u64 reserved;
  861. struct btrfs_space_info *space_info;
  862. spinlock_t lock;
  863. unsigned int full;
  864. };
  865. /*
  866. * free clusters are used to claim free space in relatively large chunks,
  867. * allowing us to do less seeky writes. They are used for all metadata
  868. * allocations and data allocations in ssd mode.
  869. */
  870. struct btrfs_free_cluster {
  871. spinlock_t lock;
  872. spinlock_t refill_lock;
  873. struct rb_root root;
  874. /* largest extent in this cluster */
  875. u64 max_size;
  876. /* first extent starting offset */
  877. u64 window_start;
  878. struct btrfs_block_group_cache *block_group;
  879. /*
  880. * when a cluster is allocated from a block group, we put the
  881. * cluster onto a list in the block group so that it can
  882. * be freed before the block group is freed.
  883. */
  884. struct list_head block_group_list;
  885. };
  886. enum btrfs_caching_type {
  887. BTRFS_CACHE_NO = 0,
  888. BTRFS_CACHE_STARTED = 1,
  889. BTRFS_CACHE_FAST = 2,
  890. BTRFS_CACHE_FINISHED = 3,
  891. };
  892. enum btrfs_disk_cache_state {
  893. BTRFS_DC_WRITTEN = 0,
  894. BTRFS_DC_ERROR = 1,
  895. BTRFS_DC_CLEAR = 2,
  896. BTRFS_DC_SETUP = 3,
  897. BTRFS_DC_NEED_WRITE = 4,
  898. };
  899. struct btrfs_caching_control {
  900. struct list_head list;
  901. struct mutex mutex;
  902. wait_queue_head_t wait;
  903. struct btrfs_work work;
  904. struct btrfs_block_group_cache *block_group;
  905. u64 progress;
  906. atomic_t count;
  907. };
  908. struct btrfs_block_group_cache {
  909. struct btrfs_key key;
  910. struct btrfs_block_group_item item;
  911. struct btrfs_fs_info *fs_info;
  912. struct inode *inode;
  913. spinlock_t lock;
  914. u64 pinned;
  915. u64 reserved;
  916. u64 bytes_super;
  917. u64 flags;
  918. u64 sectorsize;
  919. u64 cache_generation;
  920. unsigned int ro:1;
  921. unsigned int dirty:1;
  922. unsigned int iref:1;
  923. int disk_cache_state;
  924. /* cache tracking stuff */
  925. int cached;
  926. struct btrfs_caching_control *caching_ctl;
  927. u64 last_byte_to_unpin;
  928. struct btrfs_space_info *space_info;
  929. /* free space cache stuff */
  930. struct btrfs_free_space_ctl *free_space_ctl;
  931. /* block group cache stuff */
  932. struct rb_node cache_node;
  933. /* for block groups in the same raid type */
  934. struct list_head list;
  935. /* usage count */
  936. atomic_t count;
  937. /* List of struct btrfs_free_clusters for this block group.
  938. * Today it will only have one thing on it, but that may change
  939. */
  940. struct list_head cluster_list;
  941. };
  942. /* delayed seq elem */
  943. struct seq_list {
  944. struct list_head list;
  945. u64 seq;
  946. };
  947. /* fs_info */
  948. struct reloc_control;
  949. struct btrfs_device;
  950. struct btrfs_fs_devices;
  951. struct btrfs_balance_control;
  952. struct btrfs_delayed_root;
  953. struct btrfs_fs_info {
  954. u8 fsid[BTRFS_FSID_SIZE];
  955. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  956. struct btrfs_root *extent_root;
  957. struct btrfs_root *tree_root;
  958. struct btrfs_root *chunk_root;
  959. struct btrfs_root *dev_root;
  960. struct btrfs_root *fs_root;
  961. struct btrfs_root *csum_root;
  962. struct btrfs_root *quota_root;
  963. /* the log root tree is a directory of all the other log roots */
  964. struct btrfs_root *log_root_tree;
  965. spinlock_t fs_roots_radix_lock;
  966. struct radix_tree_root fs_roots_radix;
  967. /* block group cache stuff */
  968. spinlock_t block_group_cache_lock;
  969. struct rb_root block_group_cache_tree;
  970. /* keep track of unallocated space */
  971. spinlock_t free_chunk_lock;
  972. u64 free_chunk_space;
  973. struct extent_io_tree freed_extents[2];
  974. struct extent_io_tree *pinned_extents;
  975. /* logical->physical extent mapping */
  976. struct btrfs_mapping_tree mapping_tree;
  977. /*
  978. * block reservation for extent, checksum, root tree and
  979. * delayed dir index item
  980. */
  981. struct btrfs_block_rsv global_block_rsv;
  982. /* block reservation for delay allocation */
  983. struct btrfs_block_rsv delalloc_block_rsv;
  984. /* block reservation for metadata operations */
  985. struct btrfs_block_rsv trans_block_rsv;
  986. /* block reservation for chunk tree */
  987. struct btrfs_block_rsv chunk_block_rsv;
  988. /* block reservation for delayed operations */
  989. struct btrfs_block_rsv delayed_block_rsv;
  990. struct btrfs_block_rsv empty_block_rsv;
  991. u64 generation;
  992. u64 last_trans_committed;
  993. /*
  994. * this is updated to the current trans every time a full commit
  995. * is required instead of the faster short fsync log commits
  996. */
  997. u64 last_trans_log_full_commit;
  998. unsigned long mount_opt;
  999. unsigned long compress_type:4;
  1000. u64 max_inline;
  1001. u64 alloc_start;
  1002. struct btrfs_transaction *running_transaction;
  1003. wait_queue_head_t transaction_throttle;
  1004. wait_queue_head_t transaction_wait;
  1005. wait_queue_head_t transaction_blocked_wait;
  1006. wait_queue_head_t async_submit_wait;
  1007. struct btrfs_super_block *super_copy;
  1008. struct btrfs_super_block *super_for_commit;
  1009. struct block_device *__bdev;
  1010. struct super_block *sb;
  1011. struct inode *btree_inode;
  1012. struct backing_dev_info bdi;
  1013. struct mutex tree_log_mutex;
  1014. struct mutex transaction_kthread_mutex;
  1015. struct mutex cleaner_mutex;
  1016. struct mutex chunk_mutex;
  1017. struct mutex volume_mutex;
  1018. /*
  1019. * this protects the ordered operations list only while we are
  1020. * processing all of the entries on it. This way we make
  1021. * sure the commit code doesn't find the list temporarily empty
  1022. * because another function happens to be doing non-waiting preflush
  1023. * before jumping into the main commit.
  1024. */
  1025. struct mutex ordered_operations_mutex;
  1026. struct rw_semaphore extent_commit_sem;
  1027. struct rw_semaphore cleanup_work_sem;
  1028. struct rw_semaphore subvol_sem;
  1029. struct srcu_struct subvol_srcu;
  1030. spinlock_t trans_lock;
  1031. /*
  1032. * the reloc mutex goes with the trans lock, it is taken
  1033. * during commit to protect us from the relocation code
  1034. */
  1035. struct mutex reloc_mutex;
  1036. struct list_head trans_list;
  1037. struct list_head hashers;
  1038. struct list_head dead_roots;
  1039. struct list_head caching_block_groups;
  1040. spinlock_t delayed_iput_lock;
  1041. struct list_head delayed_iputs;
  1042. /* this protects tree_mod_seq_list */
  1043. spinlock_t tree_mod_seq_lock;
  1044. atomic_t tree_mod_seq;
  1045. struct list_head tree_mod_seq_list;
  1046. struct seq_list tree_mod_seq_elem;
  1047. /* this protects tree_mod_log */
  1048. rwlock_t tree_mod_log_lock;
  1049. struct rb_root tree_mod_log;
  1050. atomic_t nr_async_submits;
  1051. atomic_t async_submit_draining;
  1052. atomic_t nr_async_bios;
  1053. atomic_t async_delalloc_pages;
  1054. atomic_t open_ioctl_trans;
  1055. /*
  1056. * this is used by the balancing code to wait for all the pending
  1057. * ordered extents
  1058. */
  1059. spinlock_t ordered_extent_lock;
  1060. /*
  1061. * all of the data=ordered extents pending writeback
  1062. * these can span multiple transactions and basically include
  1063. * every dirty data page that isn't from nodatacow
  1064. */
  1065. struct list_head ordered_extents;
  1066. /*
  1067. * all of the inodes that have delalloc bytes. It is possible for
  1068. * this list to be empty even when there is still dirty data=ordered
  1069. * extents waiting to finish IO.
  1070. */
  1071. struct list_head delalloc_inodes;
  1072. /*
  1073. * special rename and truncate targets that must be on disk before
  1074. * we're allowed to commit. This is basically the ext3 style
  1075. * data=ordered list.
  1076. */
  1077. struct list_head ordered_operations;
  1078. /*
  1079. * there is a pool of worker threads for checksumming during writes
  1080. * and a pool for checksumming after reads. This is because readers
  1081. * can run with FS locks held, and the writers may be waiting for
  1082. * those locks. We don't want ordering in the pending list to cause
  1083. * deadlocks, and so the two are serviced separately.
  1084. *
  1085. * A third pool does submit_bio to avoid deadlocking with the other
  1086. * two
  1087. */
  1088. struct btrfs_workers generic_worker;
  1089. struct btrfs_workers workers;
  1090. struct btrfs_workers delalloc_workers;
  1091. struct btrfs_workers endio_workers;
  1092. struct btrfs_workers endio_meta_workers;
  1093. struct btrfs_workers endio_meta_write_workers;
  1094. struct btrfs_workers endio_write_workers;
  1095. struct btrfs_workers endio_freespace_worker;
  1096. struct btrfs_workers submit_workers;
  1097. struct btrfs_workers caching_workers;
  1098. struct btrfs_workers readahead_workers;
  1099. /*
  1100. * fixup workers take dirty pages that didn't properly go through
  1101. * the cow mechanism and make them safe to write. It happens
  1102. * for the sys_munmap function call path
  1103. */
  1104. struct btrfs_workers fixup_workers;
  1105. struct btrfs_workers delayed_workers;
  1106. struct task_struct *transaction_kthread;
  1107. struct task_struct *cleaner_kthread;
  1108. int thread_pool_size;
  1109. struct kobject super_kobj;
  1110. struct completion kobj_unregister;
  1111. int do_barriers;
  1112. int closing;
  1113. int log_root_recovering;
  1114. int enospc_unlink;
  1115. int trans_no_join;
  1116. u64 total_pinned;
  1117. /* protected by the delalloc lock, used to keep from writing
  1118. * metadata until there is a nice batch
  1119. */
  1120. u64 dirty_metadata_bytes;
  1121. struct list_head dirty_cowonly_roots;
  1122. struct btrfs_fs_devices *fs_devices;
  1123. /*
  1124. * the space_info list is almost entirely read only. It only changes
  1125. * when we add a new raid type to the FS, and that happens
  1126. * very rarely. RCU is used to protect it.
  1127. */
  1128. struct list_head space_info;
  1129. struct btrfs_space_info *data_sinfo;
  1130. struct reloc_control *reloc_ctl;
  1131. spinlock_t delalloc_lock;
  1132. u64 delalloc_bytes;
  1133. /* data_alloc_cluster is only used in ssd mode */
  1134. struct btrfs_free_cluster data_alloc_cluster;
  1135. /* all metadata allocations go through this cluster */
  1136. struct btrfs_free_cluster meta_alloc_cluster;
  1137. /* auto defrag inodes go here */
  1138. spinlock_t defrag_inodes_lock;
  1139. struct rb_root defrag_inodes;
  1140. atomic_t defrag_running;
  1141. spinlock_t ref_cache_lock;
  1142. u64 total_ref_cache_size;
  1143. /*
  1144. * these three are in extended format (availability of single
  1145. * chunks is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE bit, other
  1146. * types are denoted by corresponding BTRFS_BLOCK_GROUP_* bits)
  1147. */
  1148. u64 avail_data_alloc_bits;
  1149. u64 avail_metadata_alloc_bits;
  1150. u64 avail_system_alloc_bits;
  1151. /* restriper state */
  1152. spinlock_t balance_lock;
  1153. struct mutex balance_mutex;
  1154. atomic_t balance_running;
  1155. atomic_t balance_pause_req;
  1156. atomic_t balance_cancel_req;
  1157. struct btrfs_balance_control *balance_ctl;
  1158. wait_queue_head_t balance_wait_q;
  1159. unsigned data_chunk_allocations;
  1160. unsigned metadata_ratio;
  1161. void *bdev_holder;
  1162. /* private scrub information */
  1163. struct mutex scrub_lock;
  1164. atomic_t scrubs_running;
  1165. atomic_t scrub_pause_req;
  1166. atomic_t scrubs_paused;
  1167. atomic_t scrub_cancel_req;
  1168. wait_queue_head_t scrub_pause_wait;
  1169. struct rw_semaphore scrub_super_lock;
  1170. int scrub_workers_refcnt;
  1171. struct btrfs_workers scrub_workers;
  1172. #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
  1173. u32 check_integrity_print_mask;
  1174. #endif
  1175. /*
  1176. * quota information
  1177. */
  1178. unsigned int quota_enabled:1;
  1179. /*
  1180. * quota_enabled only changes state after a commit. This holds the
  1181. * next state.
  1182. */
  1183. unsigned int pending_quota_state:1;
  1184. /* is qgroup tracking in a consistent state? */
  1185. u64 qgroup_flags;
  1186. /* holds configuration and tracking. Protected by qgroup_lock */
  1187. struct rb_root qgroup_tree;
  1188. spinlock_t qgroup_lock;
  1189. /* list of dirty qgroups to be written at next commit */
  1190. struct list_head dirty_qgroups;
  1191. /* used by btrfs_qgroup_record_ref for an efficient tree traversal */
  1192. u64 qgroup_seq;
  1193. /* filesystem state */
  1194. u64 fs_state;
  1195. struct btrfs_delayed_root *delayed_root;
  1196. /* readahead tree */
  1197. spinlock_t reada_lock;
  1198. struct radix_tree_root reada_tree;
  1199. /* next backup root to be overwritten */
  1200. int backup_root_index;
  1201. };
  1202. /*
  1203. * in ram representation of the tree. extent_root is used for all allocations
  1204. * and for the extent tree extent_root root.
  1205. */
  1206. struct btrfs_root {
  1207. struct extent_buffer *node;
  1208. struct extent_buffer *commit_root;
  1209. struct btrfs_root *log_root;
  1210. struct btrfs_root *reloc_root;
  1211. struct btrfs_root_item root_item;
  1212. struct btrfs_key root_key;
  1213. struct btrfs_fs_info *fs_info;
  1214. struct extent_io_tree dirty_log_pages;
  1215. struct kobject root_kobj;
  1216. struct completion kobj_unregister;
  1217. struct mutex objectid_mutex;
  1218. spinlock_t accounting_lock;
  1219. struct btrfs_block_rsv *block_rsv;
  1220. /* free ino cache stuff */
  1221. struct mutex fs_commit_mutex;
  1222. struct btrfs_free_space_ctl *free_ino_ctl;
  1223. enum btrfs_caching_type cached;
  1224. spinlock_t cache_lock;
  1225. wait_queue_head_t cache_wait;
  1226. struct btrfs_free_space_ctl *free_ino_pinned;
  1227. u64 cache_progress;
  1228. struct inode *cache_inode;
  1229. struct mutex log_mutex;
  1230. wait_queue_head_t log_writer_wait;
  1231. wait_queue_head_t log_commit_wait[2];
  1232. atomic_t log_writers;
  1233. atomic_t log_commit[2];
  1234. unsigned long log_transid;
  1235. unsigned long last_log_commit;
  1236. unsigned long log_batch;
  1237. pid_t log_start_pid;
  1238. bool log_multiple_pids;
  1239. u64 objectid;
  1240. u64 last_trans;
  1241. /* data allocations are done in sectorsize units */
  1242. u32 sectorsize;
  1243. /* node allocations are done in nodesize units */
  1244. u32 nodesize;
  1245. /* leaf allocations are done in leafsize units */
  1246. u32 leafsize;
  1247. u32 stripesize;
  1248. u32 type;
  1249. u64 highest_objectid;
  1250. /* btrfs_record_root_in_trans is a multi-step process,
  1251. * and it can race with the balancing code. But the
  1252. * race is very small, and only the first time the root
  1253. * is added to each transaction. So in_trans_setup
  1254. * is used to tell us when more checks are required
  1255. */
  1256. unsigned long in_trans_setup;
  1257. int ref_cows;
  1258. int track_dirty;
  1259. int in_radix;
  1260. u64 defrag_trans_start;
  1261. struct btrfs_key defrag_progress;
  1262. struct btrfs_key defrag_max;
  1263. int defrag_running;
  1264. char *name;
  1265. /* the dirty list is only used by non-reference counted roots */
  1266. struct list_head dirty_list;
  1267. struct list_head root_list;
  1268. spinlock_t orphan_lock;
  1269. atomic_t orphan_inodes;
  1270. struct btrfs_block_rsv *orphan_block_rsv;
  1271. int orphan_item_inserted;
  1272. int orphan_cleanup_state;
  1273. spinlock_t inode_lock;
  1274. /* red-black tree that keeps track of in-memory inodes */
  1275. struct rb_root inode_tree;
  1276. /*
  1277. * radix tree that keeps track of delayed nodes of every inode,
  1278. * protected by inode_lock
  1279. */
  1280. struct radix_tree_root delayed_nodes_tree;
  1281. /*
  1282. * right now this just gets used so that a root has its own devid
  1283. * for stat. It may be used for more later
  1284. */
  1285. dev_t anon_dev;
  1286. int force_cow;
  1287. spinlock_t root_times_lock;
  1288. };
  1289. struct btrfs_ioctl_defrag_range_args {
  1290. /* start of the defrag operation */
  1291. __u64 start;
  1292. /* number of bytes to defrag, use (u64)-1 to say all */
  1293. __u64 len;
  1294. /*
  1295. * flags for the operation, which can include turning
  1296. * on compression for this one defrag
  1297. */
  1298. __u64 flags;
  1299. /*
  1300. * any extent bigger than this will be considered
  1301. * already defragged. Use 0 to take the kernel default
  1302. * Use 1 to say every single extent must be rewritten
  1303. */
  1304. __u32 extent_thresh;
  1305. /*
  1306. * which compression method to use if turning on compression
  1307. * for this defrag operation. If unspecified, zlib will
  1308. * be used
  1309. */
  1310. __u32 compress_type;
  1311. /* spare for later */
  1312. __u32 unused[4];
  1313. };
  1314. /*
  1315. * inode items have the data typically returned from stat and store other
  1316. * info about object characteristics. There is one for every file and dir in
  1317. * the FS
  1318. */
  1319. #define BTRFS_INODE_ITEM_KEY 1
  1320. #define BTRFS_INODE_REF_KEY 12
  1321. #define BTRFS_XATTR_ITEM_KEY 24
  1322. #define BTRFS_ORPHAN_ITEM_KEY 48
  1323. /* reserve 2-15 close to the inode for later flexibility */
  1324. /*
  1325. * dir items are the name -> inode pointers in a directory. There is one
  1326. * for every name in a directory.
  1327. */
  1328. #define BTRFS_DIR_LOG_ITEM_KEY 60
  1329. #define BTRFS_DIR_LOG_INDEX_KEY 72
  1330. #define BTRFS_DIR_ITEM_KEY 84
  1331. #define BTRFS_DIR_INDEX_KEY 96
  1332. /*
  1333. * extent data is for file data
  1334. */
  1335. #define BTRFS_EXTENT_DATA_KEY 108
  1336. /*
  1337. * extent csums are stored in a separate tree and hold csums for
  1338. * an entire extent on disk.
  1339. */
  1340. #define BTRFS_EXTENT_CSUM_KEY 128
  1341. /*
  1342. * root items point to tree roots. They are typically in the root
  1343. * tree used by the super block to find all the other trees
  1344. */
  1345. #define BTRFS_ROOT_ITEM_KEY 132
  1346. /*
  1347. * root backrefs tie subvols and snapshots to the directory entries that
  1348. * reference them
  1349. */
  1350. #define BTRFS_ROOT_BACKREF_KEY 144
  1351. /*
  1352. * root refs make a fast index for listing all of the snapshots and
  1353. * subvolumes referenced by a given root. They point directly to the
  1354. * directory item in the root that references the subvol
  1355. */
  1356. #define BTRFS_ROOT_REF_KEY 156
  1357. /*
  1358. * extent items are in the extent map tree. These record which blocks
  1359. * are used, and how many references there are to each block
  1360. */
  1361. #define BTRFS_EXTENT_ITEM_KEY 168
  1362. #define BTRFS_TREE_BLOCK_REF_KEY 176
  1363. #define BTRFS_EXTENT_DATA_REF_KEY 178
  1364. #define BTRFS_EXTENT_REF_V0_KEY 180
  1365. #define BTRFS_SHARED_BLOCK_REF_KEY 182
  1366. #define BTRFS_SHARED_DATA_REF_KEY 184
  1367. /*
  1368. * block groups give us hints into the extent allocation trees. Which
  1369. * blocks are free etc etc
  1370. */
  1371. #define BTRFS_BLOCK_GROUP_ITEM_KEY 192
  1372. #define BTRFS_DEV_EXTENT_KEY 204
  1373. #define BTRFS_DEV_ITEM_KEY 216
  1374. #define BTRFS_CHUNK_ITEM_KEY 228
  1375. /*
  1376. * Records the overall state of the qgroups.
  1377. * There's only one instance of this key present,
  1378. * (0, BTRFS_QGROUP_STATUS_KEY, 0)
  1379. */
  1380. #define BTRFS_QGROUP_STATUS_KEY 240
  1381. /*
  1382. * Records the currently used space of the qgroup.
  1383. * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
  1384. */
  1385. #define BTRFS_QGROUP_INFO_KEY 242
  1386. /*
  1387. * Contains the user configured limits for the qgroup.
  1388. * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
  1389. */
  1390. #define BTRFS_QGROUP_LIMIT_KEY 244
  1391. /*
  1392. * Records the child-parent relationship of qgroups. For
  1393. * each relation, 2 keys are present:
  1394. * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
  1395. * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
  1396. */
  1397. #define BTRFS_QGROUP_RELATION_KEY 246
  1398. #define BTRFS_BALANCE_ITEM_KEY 248
  1399. /*
  1400. * Persistantly stores the io stats in the device tree.
  1401. * One key for all stats, (0, BTRFS_DEV_STATS_KEY, devid).
  1402. */
  1403. #define BTRFS_DEV_STATS_KEY 249
  1404. /*
  1405. * string items are for debugging. They just store a short string of
  1406. * data in the FS
  1407. */
  1408. #define BTRFS_STRING_ITEM_KEY 253
  1409. /*
  1410. * Flags for mount options.
  1411. *
  1412. * Note: don't forget to add new options to btrfs_show_options()
  1413. */
  1414. #define BTRFS_MOUNT_NODATASUM (1 << 0)
  1415. #define BTRFS_MOUNT_NODATACOW (1 << 1)
  1416. #define BTRFS_MOUNT_NOBARRIER (1 << 2)
  1417. #define BTRFS_MOUNT_SSD (1 << 3)
  1418. #define BTRFS_MOUNT_DEGRADED (1 << 4)
  1419. #define BTRFS_MOUNT_COMPRESS (1 << 5)
  1420. #define BTRFS_MOUNT_NOTREELOG (1 << 6)
  1421. #define BTRFS_MOUNT_FLUSHONCOMMIT (1 << 7)
  1422. #define BTRFS_MOUNT_SSD_SPREAD (1 << 8)
  1423. #define BTRFS_MOUNT_NOSSD (1 << 9)
  1424. #define BTRFS_MOUNT_DISCARD (1 << 10)
  1425. #define BTRFS_MOUNT_FORCE_COMPRESS (1 << 11)
  1426. #define BTRFS_MOUNT_SPACE_CACHE (1 << 12)
  1427. #define BTRFS_MOUNT_CLEAR_CACHE (1 << 13)
  1428. #define BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED (1 << 14)
  1429. #define BTRFS_MOUNT_ENOSPC_DEBUG (1 << 15)
  1430. #define BTRFS_MOUNT_AUTO_DEFRAG (1 << 16)
  1431. #define BTRFS_MOUNT_INODE_MAP_CACHE (1 << 17)
  1432. #define BTRFS_MOUNT_RECOVERY (1 << 18)
  1433. #define BTRFS_MOUNT_SKIP_BALANCE (1 << 19)
  1434. #define BTRFS_MOUNT_CHECK_INTEGRITY (1 << 20)
  1435. #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
  1436. #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22)
  1437. #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
  1438. #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
  1439. #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
  1440. BTRFS_MOUNT_##opt)
  1441. /*
  1442. * Inode flags
  1443. */
  1444. #define BTRFS_INODE_NODATASUM (1 << 0)
  1445. #define BTRFS_INODE_NODATACOW (1 << 1)
  1446. #define BTRFS_INODE_READONLY (1 << 2)
  1447. #define BTRFS_INODE_NOCOMPRESS (1 << 3)
  1448. #define BTRFS_INODE_PREALLOC (1 << 4)
  1449. #define BTRFS_INODE_SYNC (1 << 5)
  1450. #define BTRFS_INODE_IMMUTABLE (1 << 6)
  1451. #define BTRFS_INODE_APPEND (1 << 7)
  1452. #define BTRFS_INODE_NODUMP (1 << 8)
  1453. #define BTRFS_INODE_NOATIME (1 << 9)
  1454. #define BTRFS_INODE_DIRSYNC (1 << 10)
  1455. #define BTRFS_INODE_COMPRESS (1 << 11)
  1456. #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)
  1457. struct btrfs_map_token {
  1458. struct extent_buffer *eb;
  1459. char *kaddr;
  1460. unsigned long offset;
  1461. };
  1462. static inline void btrfs_init_map_token (struct btrfs_map_token *token)
  1463. {
  1464. memset(token, 0, sizeof(*token));
  1465. }
  1466. /* some macros to generate set/get funcs for the struct fields. This
  1467. * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  1468. * one for u8:
  1469. */
  1470. #define le8_to_cpu(v) (v)
  1471. #define cpu_to_le8(v) (v)
  1472. #define __le8 u8
  1473. #define read_eb_member(eb, ptr, type, member, result) ( \
  1474. read_extent_buffer(eb, (char *)(result), \
  1475. ((unsigned long)(ptr)) + \
  1476. offsetof(type, member), \
  1477. sizeof(((type *)0)->member)))
  1478. #define write_eb_member(eb, ptr, type, member, result) ( \
  1479. write_extent_buffer(eb, (char *)(result), \
  1480. ((unsigned long)(ptr)) + \
  1481. offsetof(type, member), \
  1482. sizeof(((type *)0)->member)))
  1483. #define DECLARE_BTRFS_SETGET_BITS(bits) \
  1484. u##bits btrfs_get_token_##bits(struct extent_buffer *eb, void *ptr, \
  1485. unsigned long off, \
  1486. struct btrfs_map_token *token); \
  1487. void btrfs_set_token_##bits(struct extent_buffer *eb, void *ptr, \
  1488. unsigned long off, u##bits val, \
  1489. struct btrfs_map_token *token); \
  1490. static inline u##bits btrfs_get_##bits(struct extent_buffer *eb, void *ptr, \
  1491. unsigned long off) \
  1492. { \
  1493. return btrfs_get_token_##bits(eb, ptr, off, NULL); \
  1494. } \
  1495. static inline void btrfs_set_##bits(struct extent_buffer *eb, void *ptr, \
  1496. unsigned long off, u##bits val) \
  1497. { \
  1498. btrfs_set_token_##bits(eb, ptr, off, val, NULL); \
  1499. }
  1500. DECLARE_BTRFS_SETGET_BITS(8)
  1501. DECLARE_BTRFS_SETGET_BITS(16)
  1502. DECLARE_BTRFS_SETGET_BITS(32)
  1503. DECLARE_BTRFS_SETGET_BITS(64)
  1504. #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
  1505. static inline u##bits btrfs_##name(struct extent_buffer *eb, type *s) \
  1506. { \
  1507. BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
  1508. return btrfs_get_##bits(eb, s, offsetof(type, member)); \
  1509. } \
  1510. static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \
  1511. u##bits val) \
  1512. { \
  1513. BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
  1514. btrfs_set_##bits(eb, s, offsetof(type, member), val); \
  1515. } \
  1516. static inline u##bits btrfs_token_##name(struct extent_buffer *eb, type *s, \
  1517. struct btrfs_map_token *token) \
  1518. { \
  1519. BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
  1520. return btrfs_get_token_##bits(eb, s, offsetof(type, member), token); \
  1521. } \
  1522. static inline void btrfs_set_token_##name(struct extent_buffer *eb, \
  1523. type *s, u##bits val, \
  1524. struct btrfs_map_token *token) \
  1525. { \
  1526. BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
  1527. btrfs_set_token_##bits(eb, s, offsetof(type, member), val, token); \
  1528. }
  1529. #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
  1530. static inline u##bits btrfs_##name(struct extent_buffer *eb) \
  1531. { \
  1532. type *p = page_address(eb->pages[0]); \
  1533. u##bits res = le##bits##_to_cpu(p->member); \
  1534. return res; \
  1535. } \
  1536. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  1537. u##bits val) \
  1538. { \
  1539. type *p = page_address(eb->pages[0]); \
  1540. p->member = cpu_to_le##bits(val); \
  1541. }
  1542. #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
  1543. static inline u##bits btrfs_##name(type *s) \
  1544. { \
  1545. return le##bits##_to_cpu(s->member); \
  1546. } \
  1547. static inline void btrfs_set_##name(type *s, u##bits val) \
  1548. { \
  1549. s->member = cpu_to_le##bits(val); \
  1550. }
  1551. BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
  1552. BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
  1553. BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
  1554. BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
  1555. BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
  1556. BTRFS_SETGET_FUNCS(device_start_offset, struct btrfs_dev_item,
  1557. start_offset, 64);
  1558. BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
  1559. BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
  1560. BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
  1561. BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
  1562. BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
  1563. BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64);
  1564. BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
  1565. BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
  1566. total_bytes, 64);
  1567. BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
  1568. bytes_used, 64);
  1569. BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
  1570. io_align, 32);
  1571. BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
  1572. io_width, 32);
  1573. BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
  1574. sector_size, 32);
  1575. BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
  1576. BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
  1577. dev_group, 32);
  1578. BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
  1579. seek_speed, 8);
  1580. BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
  1581. bandwidth, 8);
  1582. BTRFS_SETGET_STACK_FUNCS(stack_device_generation, struct btrfs_dev_item,
  1583. generation, 64);
  1584. static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
  1585. {
  1586. return (char *)d + offsetof(struct btrfs_dev_item, uuid);
  1587. }
  1588. static inline char *btrfs_device_fsid(struct btrfs_dev_item *d)
  1589. {
  1590. return (char *)d + offsetof(struct btrfs_dev_item, fsid);
  1591. }
  1592. BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
  1593. BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
  1594. BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
  1595. BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
  1596. BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
  1597. BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
  1598. BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
  1599. BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
  1600. BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
  1601. BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
  1602. BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
  1603. static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
  1604. {
  1605. return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
  1606. }
  1607. BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
  1608. BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
  1609. BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
  1610. stripe_len, 64);
  1611. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
  1612. io_align, 32);
  1613. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
  1614. io_width, 32);
  1615. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
  1616. sector_size, 32);
  1617. BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
  1618. BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
  1619. num_stripes, 16);
  1620. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
  1621. sub_stripes, 16);
  1622. BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
  1623. BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
  1624. static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
  1625. int nr)
  1626. {
  1627. unsigned long offset = (unsigned long)c;
  1628. offset += offsetof(struct btrfs_chunk, stripe);
  1629. offset += nr * sizeof(struct btrfs_stripe);
  1630. return (struct btrfs_stripe *)offset;
  1631. }
  1632. static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
  1633. {
  1634. return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
  1635. }
  1636. static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
  1637. struct btrfs_chunk *c, int nr)
  1638. {
  1639. return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
  1640. }
  1641. static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
  1642. struct btrfs_chunk *c, int nr)
  1643. {
  1644. return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
  1645. }
  1646. /* struct btrfs_block_group_item */
  1647. BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
  1648. used, 64);
  1649. BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
  1650. used, 64);
  1651. BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
  1652. struct btrfs_block_group_item, chunk_objectid, 64);
  1653. BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
  1654. struct btrfs_block_group_item, chunk_objectid, 64);
  1655. BTRFS_SETGET_FUNCS(disk_block_group_flags,
  1656. struct btrfs_block_group_item, flags, 64);
  1657. BTRFS_SETGET_STACK_FUNCS(block_group_flags,
  1658. struct btrfs_block_group_item, flags, 64);
  1659. /* struct btrfs_inode_ref */
  1660. BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
  1661. BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
  1662. /* struct btrfs_inode_item */
  1663. BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
  1664. BTRFS_SETGET_FUNCS(inode_sequence, struct btrfs_inode_item, sequence, 64);
  1665. BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
  1666. BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
  1667. BTRFS_SETGET_FUNCS(inode_nbytes, struct btrfs_inode_item, nbytes, 64);
  1668. BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
  1669. BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
  1670. BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
  1671. BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
  1672. BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
  1673. BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
  1674. BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
  1675. static inline struct btrfs_timespec *
  1676. btrfs_inode_atime(struct btrfs_inode_item *inode_item)
  1677. {
  1678. unsigned long ptr = (unsigned long)inode_item;
  1679. ptr += offsetof(struct btrfs_inode_item, atime);
  1680. return (struct btrfs_timespec *)ptr;
  1681. }
  1682. static inline struct btrfs_timespec *
  1683. btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
  1684. {
  1685. unsigned long ptr = (unsigned long)inode_item;
  1686. ptr += offsetof(struct btrfs_inode_item, mtime);
  1687. return (struct btrfs_timespec *)ptr;
  1688. }
  1689. static inline struct btrfs_timespec *
  1690. btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
  1691. {
  1692. unsigned long ptr = (unsigned long)inode_item;
  1693. ptr += offsetof(struct btrfs_inode_item, ctime);
  1694. return (struct btrfs_timespec *)ptr;
  1695. }
  1696. BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
  1697. BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
  1698. /* struct btrfs_dev_extent */
  1699. BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
  1700. chunk_tree, 64);
  1701. BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
  1702. chunk_objectid, 64);
  1703. BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
  1704. chunk_offset, 64);
  1705. BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
  1706. static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
  1707. {
  1708. unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
  1709. return (u8 *)((unsigned long)dev + ptr);
  1710. }
  1711. BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64);
  1712. BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item,
  1713. generation, 64);
  1714. BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
  1715. BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
  1716. BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
  1717. static inline void btrfs_tree_block_key(struct extent_buffer *eb,
  1718. struct btrfs_tree_block_info *item,
  1719. struct btrfs_disk_key *key)
  1720. {
  1721. read_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
  1722. }
  1723. static inline void btrfs_set_tree_block_key(struct extent_buffer *eb,
  1724. struct btrfs_tree_block_info *item,
  1725. struct btrfs_disk_key *key)
  1726. {
  1727. write_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
  1728. }
  1729. BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref,
  1730. root, 64);
  1731. BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref,
  1732. objectid, 64);
  1733. BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref,
  1734. offset, 64);
  1735. BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref,
  1736. count, 32);
  1737. BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref,
  1738. count, 32);
  1739. BTRFS_SETGET_FUNCS(extent_inline_ref_type, struct btrfs_extent_inline_ref,
  1740. type, 8);
  1741. BTRFS_SETGET_FUNCS(extent_inline_ref_offset, struct btrfs_extent_inline_ref,
  1742. offset, 64);
  1743. static inline u32 btrfs_extent_inline_ref_size(int type)
  1744. {
  1745. if (type == BTRFS_TREE_BLOCK_REF_KEY ||
  1746. type == BTRFS_SHARED_BLOCK_REF_KEY)
  1747. return sizeof(struct btrfs_extent_inline_ref);
  1748. if (type == BTRFS_SHARED_DATA_REF_KEY)
  1749. return sizeof(struct btrfs_shared_data_ref) +
  1750. sizeof(struct btrfs_extent_inline_ref);
  1751. if (type == BTRFS_EXTENT_DATA_REF_KEY)
  1752. return sizeof(struct btrfs_extent_data_ref) +
  1753. offsetof(struct btrfs_extent_inline_ref, offset);
  1754. BUG();
  1755. return 0;
  1756. }
  1757. BTRFS_SETGET_FUNCS(ref_root_v0, struct btrfs_extent_ref_v0, root, 64);
  1758. BTRFS_SETGET_FUNCS(ref_generation_v0, struct btrfs_extent_ref_v0,
  1759. generation, 64);
  1760. BTRFS_SETGET_FUNCS(ref_objectid_v0, struct btrfs_extent_ref_v0, objectid, 64);
  1761. BTRFS_SETGET_FUNCS(ref_count_v0, struct btrfs_extent_ref_v0, count, 32);
  1762. /* struct btrfs_node */
  1763. BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
  1764. BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
  1765. static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
  1766. {
  1767. unsigned long ptr;
  1768. ptr = offsetof(struct btrfs_node, ptrs) +
  1769. sizeof(struct btrfs_key_ptr) * nr;
  1770. return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
  1771. }
  1772. static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
  1773. int nr, u64 val)
  1774. {
  1775. unsigned long ptr;
  1776. ptr = offsetof(struct btrfs_node, ptrs) +
  1777. sizeof(struct btrfs_key_ptr) * nr;
  1778. btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
  1779. }
  1780. static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
  1781. {
  1782. unsigned long ptr;
  1783. ptr = offsetof(struct btrfs_node, ptrs) +
  1784. sizeof(struct btrfs_key_ptr) * nr;
  1785. return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
  1786. }
  1787. static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
  1788. int nr, u64 val)
  1789. {
  1790. unsigned long ptr;
  1791. ptr = offsetof(struct btrfs_node, ptrs) +
  1792. sizeof(struct btrfs_key_ptr) * nr;
  1793. btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
  1794. }
  1795. static inline unsigned long btrfs_node_key_ptr_offset(int nr)
  1796. {
  1797. return offsetof(struct btrfs_node, ptrs) +
  1798. sizeof(struct btrfs_key_ptr) * nr;
  1799. }
  1800. void btrfs_node_key(struct extent_buffer *eb,
  1801. struct btrfs_disk_key *disk_key, int nr);
  1802. static inline void btrfs_set_node_key(struct extent_buffer *eb,
  1803. struct btrfs_disk_key *disk_key, int nr)
  1804. {
  1805. unsigned long ptr;
  1806. ptr = btrfs_node_key_ptr_offset(nr);
  1807. write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  1808. struct btrfs_key_ptr, key, disk_key);
  1809. }
  1810. /* struct btrfs_item */
  1811. BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
  1812. BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
  1813. static inline unsigned long btrfs_item_nr_offset(int nr)
  1814. {
  1815. return offsetof(struct btrfs_leaf, items) +
  1816. sizeof(struct btrfs_item) * nr;
  1817. }
  1818. static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
  1819. int nr)
  1820. {
  1821. return (struct btrfs_item *)btrfs_item_nr_offset(nr);
  1822. }
  1823. static inline u32 btrfs_item_end(struct extent_buffer *eb,
  1824. struct btrfs_item *item)
  1825. {
  1826. return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
  1827. }
  1828. static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
  1829. {
  1830. return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
  1831. }
  1832. static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
  1833. {
  1834. return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
  1835. }
  1836. static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
  1837. {
  1838. return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
  1839. }
  1840. static inline void btrfs_item_key(struct extent_buffer *eb,
  1841. struct btrfs_disk_key *disk_key, int nr)
  1842. {
  1843. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  1844. read_eb_member(eb, item, struct btrfs_item, key, disk_key);
  1845. }
  1846. static inline void btrfs_set_item_key(struct extent_buffer *eb,
  1847. struct btrfs_disk_key *disk_key, int nr)
  1848. {
  1849. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  1850. write_eb_member(eb, item, struct btrfs_item, key, disk_key);
  1851. }
  1852. BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
  1853. /*
  1854. * struct btrfs_root_ref
  1855. */
  1856. BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64);
  1857. BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64);
  1858. BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16);
  1859. /* struct btrfs_dir_item */
  1860. BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
  1861. BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
  1862. BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
  1863. BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
  1864. static inline void btrfs_dir_item_key(struct extent_buffer *eb,
  1865. struct btrfs_dir_item *item,
  1866. struct btrfs_disk_key *key)
  1867. {
  1868. read_eb_member(eb, item, struct btrfs_dir_item, location, key);
  1869. }
  1870. static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
  1871. struct btrfs_dir_item *item,
  1872. struct btrfs_disk_key *key)
  1873. {
  1874. write_eb_member(eb, item, struct btrfs_dir_item, location, key);
  1875. }
  1876. BTRFS_SETGET_FUNCS(free_space_entries, struct btrfs_free_space_header,
  1877. num_entries, 64);
  1878. BTRFS_SETGET_FUNCS(free_space_bitmaps, struct btrfs_free_space_header,
  1879. num_bitmaps, 64);
  1880. BTRFS_SETGET_FUNCS(free_space_generation, struct btrfs_free_space_header,
  1881. generation, 64);
  1882. static inline void btrfs_free_space_key(struct extent_buffer *eb,
  1883. struct btrfs_free_space_header *h,
  1884. struct btrfs_disk_key *key)
  1885. {
  1886. read_eb_member(eb, h, struct btrfs_free_space_header, location, key);
  1887. }
  1888. static inline void btrfs_set_free_space_key(struct extent_buffer *eb,
  1889. struct btrfs_free_space_header *h,
  1890. struct btrfs_disk_key *key)
  1891. {
  1892. write_eb_member(eb, h, struct btrfs_free_space_header, location, key);
  1893. }
  1894. /* struct btrfs_disk_key */
  1895. BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
  1896. objectid, 64);
  1897. BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
  1898. BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
  1899. static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
  1900. struct btrfs_disk_key *disk)
  1901. {
  1902. cpu->offset = le64_to_cpu(disk->offset);
  1903. cpu->type = disk->type;
  1904. cpu->objectid = le64_to_cpu(disk->objectid);
  1905. }
  1906. static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
  1907. struct btrfs_key *cpu)
  1908. {
  1909. disk->offset = cpu_to_le64(cpu->offset);
  1910. disk->type = cpu->type;
  1911. disk->objectid = cpu_to_le64(cpu->objectid);
  1912. }
  1913. static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
  1914. struct btrfs_key *key, int nr)
  1915. {
  1916. struct btrfs_disk_key disk_key;
  1917. btrfs_node_key(eb, &disk_key, nr);
  1918. btrfs_disk_key_to_cpu(key, &disk_key);
  1919. }
  1920. static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
  1921. struct btrfs_key *key, int nr)
  1922. {
  1923. struct btrfs_disk_key disk_key;
  1924. btrfs_item_key(eb, &disk_key, nr);
  1925. btrfs_disk_key_to_cpu(key, &disk_key);
  1926. }
  1927. static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
  1928. struct btrfs_dir_item *item,
  1929. struct btrfs_key *key)
  1930. {
  1931. struct btrfs_disk_key disk_key;
  1932. btrfs_dir_item_key(eb, item, &disk_key);
  1933. btrfs_disk_key_to_cpu(key, &disk_key);
  1934. }
  1935. static inline u8 btrfs_key_type(struct btrfs_key *key)
  1936. {
  1937. return key->type;
  1938. }
  1939. static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
  1940. {
  1941. key->type = val;
  1942. }
  1943. /* struct btrfs_header */
  1944. BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
  1945. BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
  1946. generation, 64);
  1947. BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
  1948. BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
  1949. BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
  1950. BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
  1951. static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
  1952. {
  1953. return (btrfs_header_flags(eb) & flag) == flag;
  1954. }
  1955. static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
  1956. {
  1957. u64 flags = btrfs_header_flags(eb);
  1958. btrfs_set_header_flags(eb, flags | flag);
  1959. return (flags & flag) == flag;
  1960. }
  1961. static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
  1962. {
  1963. u64 flags = btrfs_header_flags(eb);
  1964. btrfs_set_header_flags(eb, flags & ~flag);
  1965. return (flags & flag) == flag;
  1966. }
  1967. static inline int btrfs_header_backref_rev(struct extent_buffer *eb)
  1968. {
  1969. u64 flags = btrfs_header_flags(eb);
  1970. return flags >> BTRFS_BACKREF_REV_SHIFT;
  1971. }
  1972. static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
  1973. int rev)
  1974. {
  1975. u64 flags = btrfs_header_flags(eb);
  1976. flags &= ~BTRFS_BACKREF_REV_MASK;
  1977. flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
  1978. btrfs_set_header_flags(eb, flags);
  1979. }
  1980. static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
  1981. {
  1982. unsigned long ptr = offsetof(struct btrfs_header, fsid);
  1983. return (u8 *)ptr;
  1984. }
  1985. static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
  1986. {
  1987. unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
  1988. return (u8 *)ptr;
  1989. }
  1990. static inline int btrfs_is_leaf(struct extent_buffer *eb)
  1991. {
  1992. return btrfs_header_level(eb) == 0;
  1993. }
  1994. /* struct btrfs_root_item */
  1995. BTRFS_SETGET_FUNCS(disk_root_generation, struct btrfs_root_item,
  1996. generation, 64);
  1997. BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
  1998. BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
  1999. BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
  2000. BTRFS_SETGET_STACK_FUNCS(root_generation, struct btrfs_root_item,
  2001. generation, 64);
  2002. BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
  2003. BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
  2004. BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
  2005. BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
  2006. BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 64);
  2007. BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
  2008. BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
  2009. BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item,
  2010. last_snapshot, 64);
  2011. BTRFS_SETGET_STACK_FUNCS(root_generation_v2, struct btrfs_root_item,
  2012. generation_v2, 64);
  2013. BTRFS_SETGET_STACK_FUNCS(root_ctransid, struct btrfs_root_item,
  2014. ctransid, 64);
  2015. BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item,
  2016. otransid, 64);
  2017. BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item,
  2018. stransid, 64);
  2019. BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item,
  2020. rtransid, 64);
  2021. static inline bool btrfs_root_readonly(struct btrfs_root *root)
  2022. {
  2023. return (root->root_item.flags & cpu_to_le64(BTRFS_ROOT_SUBVOL_RDONLY)) != 0;
  2024. }
  2025. /* struct btrfs_root_backup */
  2026. BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup,
  2027. tree_root, 64);
  2028. BTRFS_SETGET_STACK_FUNCS(backup_tree_root_gen, struct btrfs_root_backup,
  2029. tree_root_gen, 64);
  2030. BTRFS_SETGET_STACK_FUNCS(backup_tree_root_level, struct btrfs_root_backup,
  2031. tree_root_level, 8);
  2032. BTRFS_SETGET_STACK_FUNCS(backup_chunk_root, struct btrfs_root_backup,
  2033. chunk_root, 64);
  2034. BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_gen, struct btrfs_root_backup,
  2035. chunk_root_gen, 64);
  2036. BTRFS_SETGET_STACK_FUNCS(backup_chunk_root_level, struct btrfs_root_backup,
  2037. chunk_root_level, 8);
  2038. BTRFS_SETGET_STACK_FUNCS(backup_extent_root, struct btrfs_root_backup,
  2039. extent_root, 64);
  2040. BTRFS_SETGET_STACK_FUNCS(backup_extent_root_gen, struct btrfs_root_backup,
  2041. extent_root_gen, 64);
  2042. BTRFS_SETGET_STACK_FUNCS(backup_extent_root_level, struct btrfs_root_backup,
  2043. extent_root_level, 8);
  2044. BTRFS_SETGET_STACK_FUNCS(backup_fs_root, struct btrfs_root_backup,
  2045. fs_root, 64);
  2046. BTRFS_SETGET_STACK_FUNCS(backup_fs_root_gen, struct btrfs_root_backup,
  2047. fs_root_gen, 64);
  2048. BTRFS_SETGET_STACK_FUNCS(backup_fs_root_level, struct btrfs_root_backup,
  2049. fs_root_level, 8);
  2050. BTRFS_SETGET_STACK_FUNCS(backup_dev_root, struct btrfs_root_backup,
  2051. dev_root, 64);
  2052. BTRFS_SETGET_STACK_FUNCS(backup_dev_root_gen, struct btrfs_root_backup,
  2053. dev_root_gen, 64);
  2054. BTRFS_SETGET_STACK_FUNCS(backup_dev_root_level, struct btrfs_root_backup,
  2055. dev_root_level, 8);
  2056. BTRFS_SETGET_STACK_FUNCS(backup_csum_root, struct btrfs_root_backup,
  2057. csum_root, 64);
  2058. BTRFS_SETGET_STACK_FUNCS(backup_csum_root_gen, struct btrfs_root_backup,
  2059. csum_root_gen, 64);
  2060. BTRFS_SETGET_STACK_FUNCS(backup_csum_root_level, struct btrfs_root_backup,
  2061. csum_root_level, 8);
  2062. BTRFS_SETGET_STACK_FUNCS(backup_total_bytes, struct btrfs_root_backup,
  2063. total_bytes, 64);
  2064. BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup,
  2065. bytes_used, 64);
  2066. BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup,
  2067. num_devices, 64);
  2068. /* struct btrfs_balance_item */
  2069. BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64);
  2070. static inline void btrfs_balance_data(struct extent_buffer *eb,
  2071. struct btrfs_balance_item *bi,
  2072. struct btrfs_disk_balance_args *ba)
  2073. {
  2074. read_eb_member(eb, bi, struct btrfs_balance_item, data, ba);
  2075. }
  2076. static inline void btrfs_set_balance_data(struct extent_buffer *eb,
  2077. struct btrfs_balance_item *bi,
  2078. struct btrfs_disk_balance_args *ba)
  2079. {
  2080. write_eb_member(eb, bi, struct btrfs_balance_item, data, ba);
  2081. }
  2082. static inline void btrfs_balance_meta(struct extent_buffer *eb,
  2083. struct btrfs_balance_item *bi,
  2084. struct btrfs_disk_balance_args *ba)
  2085. {
  2086. read_eb_member(eb, bi, struct btrfs_balance_item, meta, ba);
  2087. }
  2088. static inline void btrfs_set_balance_meta(struct extent_buffer *eb,
  2089. struct btrfs_balance_item *bi,
  2090. struct btrfs_disk_balance_args *ba)
  2091. {
  2092. write_eb_member(eb, bi, struct btrfs_balance_item, meta, ba);
  2093. }
  2094. static inline void btrfs_balance_sys(struct extent_buffer *eb,
  2095. struct btrfs_balance_item *bi,
  2096. struct btrfs_disk_balance_args *ba)
  2097. {
  2098. read_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
  2099. }
  2100. static inline void btrfs_set_balance_sys(struct extent_buffer *eb,
  2101. struct btrfs_balance_item *bi,
  2102. struct btrfs_disk_balance_args *ba)
  2103. {
  2104. write_eb_member(eb, bi, struct btrfs_balance_item, sys, ba);
  2105. }
  2106. static inline void
  2107. btrfs_disk_balance_args_to_cpu(struct btrfs_balance_args *cpu,
  2108. struct btrfs_disk_balance_args *disk)
  2109. {
  2110. memset(cpu, 0, sizeof(*cpu));
  2111. cpu->profiles = le64_to_cpu(disk->profiles);
  2112. cpu->usage = le64_to_cpu(disk->usage);
  2113. cpu->devid = le64_to_cpu(disk->devid);
  2114. cpu->pstart = le64_to_cpu(disk->pstart);
  2115. cpu->pend = le64_to_cpu(disk->pend);
  2116. cpu->vstart = le64_to_cpu(disk->vstart);
  2117. cpu->vend = le64_to_cpu(disk->vend);
  2118. cpu->target = le64_to_cpu(disk->target);
  2119. cpu->flags = le64_to_cpu(disk->flags);
  2120. }
  2121. static inline void
  2122. btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk,
  2123. struct btrfs_balance_args *cpu)
  2124. {
  2125. memset(disk, 0, sizeof(*disk));
  2126. disk->profiles = cpu_to_le64(cpu->profiles);
  2127. disk->usage = cpu_to_le64(cpu->usage);
  2128. disk->devid = cpu_to_le64(cpu->devid);
  2129. disk->pstart = cpu_to_le64(cpu->pstart);
  2130. disk->pend = cpu_to_le64(cpu->pend);
  2131. disk->vstart = cpu_to_le64(cpu->vstart);
  2132. disk->vend = cpu_to_le64(cpu->vend);
  2133. disk->target = cpu_to_le64(cpu->target);
  2134. disk->flags = cpu_to_le64(cpu->flags);
  2135. }
  2136. /* struct btrfs_super_block */
  2137. BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
  2138. BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
  2139. BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
  2140. generation, 64);
  2141. BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
  2142. BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
  2143. struct btrfs_super_block, sys_chunk_array_size, 32);
  2144. BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
  2145. struct btrfs_super_block, chunk_root_generation, 64);
  2146. BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
  2147. root_level, 8);
  2148. BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
  2149. chunk_root, 64);
  2150. BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
  2151. chunk_root_level, 8);
  2152. BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
  2153. log_root, 64);
  2154. BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
  2155. log_root_transid, 64);
  2156. BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
  2157. log_root_level, 8);
  2158. BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
  2159. total_bytes, 64);
  2160. BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
  2161. bytes_used, 64);
  2162. BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
  2163. sectorsize, 32);
  2164. BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
  2165. nodesize, 32);
  2166. BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
  2167. leafsize, 32);
  2168. BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
  2169. stripesize, 32);
  2170. BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
  2171. root_dir_objectid, 64);
  2172. BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
  2173. num_devices, 64);
  2174. BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
  2175. compat_flags, 64);
  2176. BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
  2177. compat_ro_flags, 64);
  2178. BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
  2179. incompat_flags, 64);
  2180. BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
  2181. csum_type, 16);
  2182. BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
  2183. cache_generation, 64);
  2184. static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
  2185. {
  2186. int t = btrfs_super_csum_type(s);
  2187. BUG_ON(t >= ARRAY_SIZE(btrfs_csum_sizes));
  2188. return btrfs_csum_sizes[t];
  2189. }
  2190. static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
  2191. {
  2192. return offsetof(struct btrfs_leaf, items);
  2193. }
  2194. /* struct btrfs_file_extent_item */
  2195. BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
  2196. static inline unsigned long
  2197. btrfs_file_extent_inline_start(struct btrfs_file_extent_item *e)
  2198. {
  2199. unsigned long offset = (unsigned long)e;
  2200. offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
  2201. return offset;
  2202. }
  2203. static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
  2204. {
  2205. return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
  2206. }
  2207. BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
  2208. disk_bytenr, 64);
  2209. BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
  2210. generation, 64);
  2211. BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
  2212. disk_num_bytes, 64);
  2213. BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
  2214. offset, 64);
  2215. BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
  2216. num_bytes, 64);
  2217. BTRFS_SETGET_FUNCS(file_extent_ram_bytes, struct btrfs_file_extent_item,
  2218. ram_bytes, 64);
  2219. BTRFS_SETGET_FUNCS(file_extent_compression, struct btrfs_file_extent_item,
  2220. compression, 8);
  2221. BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item,
  2222. encryption, 8);
  2223. BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item,
  2224. other_encoding, 16);
  2225. /* this returns the number of file bytes represented by the inline item.
  2226. * If an item is compressed, this is the uncompressed size
  2227. */
  2228. static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
  2229. struct btrfs_file_extent_item *e)
  2230. {
  2231. return btrfs_file_extent_ram_bytes(eb, e);
  2232. }
  2233. /*
  2234. * this returns the number of bytes used by the item on disk, minus the
  2235. * size of any extent headers. If a file is compressed on disk, this is
  2236. * the compressed size
  2237. */
  2238. static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
  2239. struct btrfs_item *e)
  2240. {
  2241. unsigned long offset;
  2242. offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
  2243. return btrfs_item_size(eb, e) - offset;
  2244. }
  2245. /* btrfs_dev_stats_item */
  2246. static inline u64 btrfs_dev_stats_value(struct extent_buffer *eb,
  2247. struct btrfs_dev_stats_item *ptr,
  2248. int index)
  2249. {
  2250. u64 val;
  2251. read_extent_buffer(eb, &val,
  2252. offsetof(struct btrfs_dev_stats_item, values) +
  2253. ((unsigned long)ptr) + (index * sizeof(u64)),
  2254. sizeof(val));
  2255. return val;
  2256. }
  2257. static inline void btrfs_set_dev_stats_value(struct extent_buffer *eb,
  2258. struct btrfs_dev_stats_item *ptr,
  2259. int index, u64 val)
  2260. {
  2261. write_extent_buffer(eb, &val,
  2262. offsetof(struct btrfs_dev_stats_item, values) +
  2263. ((unsigned long)ptr) + (index * sizeof(u64)),
  2264. sizeof(val));
  2265. }
  2266. /* btrfs_qgroup_status_item */
  2267. BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item,
  2268. generation, 64);
  2269. BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item,
  2270. version, 64);
  2271. BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item,
  2272. flags, 64);
  2273. BTRFS_SETGET_FUNCS(qgroup_status_scan, struct btrfs_qgroup_status_item,
  2274. scan, 64);
  2275. /* btrfs_qgroup_info_item */
  2276. BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item,
  2277. generation, 64);
  2278. BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64);
  2279. BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item,
  2280. rfer_cmpr, 64);
  2281. BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64);
  2282. BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item,
  2283. excl_cmpr, 64);
  2284. BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation,
  2285. struct btrfs_qgroup_info_item, generation, 64);
  2286. BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item,
  2287. rfer, 64);
  2288. BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr,
  2289. struct btrfs_qgroup_info_item, rfer_cmpr, 64);
  2290. BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item,
  2291. excl, 64);
  2292. BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr,
  2293. struct btrfs_qgroup_info_item, excl_cmpr, 64);
  2294. /* btrfs_qgroup_limit_item */
  2295. BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item,
  2296. flags, 64);
  2297. BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item,
  2298. max_rfer, 64);
  2299. BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item,
  2300. max_excl, 64);
  2301. BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item,
  2302. rsv_rfer, 64);
  2303. BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item,
  2304. rsv_excl, 64);
  2305. static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb)
  2306. {
  2307. return sb->s_fs_info;
  2308. }
  2309. static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
  2310. {
  2311. if (level == 0)
  2312. return root->leafsize;
  2313. return root->nodesize;
  2314. }
  2315. /* helper function to cast into the data area of the leaf. */
  2316. #define btrfs_item_ptr(leaf, slot, type) \
  2317. ((type *)(btrfs_leaf_data(leaf) + \
  2318. btrfs_item_offset_nr(leaf, slot)))
  2319. #define btrfs_item_ptr_offset(leaf, slot) \
  2320. ((unsigned long)(btrfs_leaf_data(leaf) + \
  2321. btrfs_item_offset_nr(leaf, slot)))
  2322. static inline struct dentry *fdentry(struct file *file)
  2323. {
  2324. return file->f_path.dentry;
  2325. }
  2326. static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info)
  2327. {
  2328. return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) &&
  2329. (space_info->flags & BTRFS_BLOCK_GROUP_DATA));
  2330. }
  2331. static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)
  2332. {
  2333. return mapping_gfp_mask(mapping) & ~__GFP_FS;
  2334. }
  2335. /* extent-tree.c */
  2336. static inline u64 btrfs_calc_trans_metadata_size(struct btrfs_root *root,
  2337. unsigned num_items)
  2338. {
  2339. return (root->leafsize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
  2340. 3 * num_items;
  2341. }
  2342. /*
  2343. * Doing a truncate won't result in new nodes or leaves, just what we need for
  2344. * COW.
  2345. */
  2346. static inline u64 btrfs_calc_trunc_metadata_size(struct btrfs_root *root,
  2347. unsigned num_items)
  2348. {
  2349. return (root->leafsize + root->nodesize * (BTRFS_MAX_LEVEL - 1)) *
  2350. num_items;
  2351. }
  2352. void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
  2353. int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
  2354. struct btrfs_root *root, unsigned long count);
  2355. int btrfs_lookup_extent(struct btrfs_root *root, u64 start, u64 len);
  2356. int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
  2357. struct btrfs_root *root, u64 bytenr,
  2358. u64 num_bytes, u64 *refs, u64 *flags);
  2359. int btrfs_pin_extent(struct btrfs_root *root,
  2360. u64 bytenr, u64 num, int reserved);
  2361. int btrfs_pin_extent_for_log_replay(struct btrfs_trans_handle *trans,
  2362. struct btrfs_root *root,
  2363. u64 bytenr, u64 num_bytes);
  2364. int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans,
  2365. struct btrfs_root *root,
  2366. u64 objectid, u64 offset, u64 bytenr);
  2367. struct btrfs_block_group_cache *btrfs_lookup_block_group(
  2368. struct btrfs_fs_info *info,
  2369. u64 bytenr);
  2370. void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
  2371. u64 btrfs_find_block_group(struct btrfs_root *root,
  2372. u64 search_start, u64 search_hint, int owner);
  2373. struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
  2374. struct btrfs_root *root, u32 blocksize,
  2375. u64 parent, u64 root_objectid,
  2376. struct btrfs_disk_key *key, int level,
  2377. u64 hint, u64 empty_size);
  2378. void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
  2379. struct btrfs_root *root,
  2380. struct extent_buffer *buf,
  2381. u64 parent, int last_ref);
  2382. struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans,
  2383. struct btrfs_root *root,
  2384. u64 bytenr, u32 blocksize,
  2385. int level);
  2386. int btrfs_alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
  2387. struct btrfs_root *root,
  2388. u64 root_objectid, u64 owner,
  2389. u64 offset, struct btrfs_key *ins);
  2390. int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans,
  2391. struct btrfs_root *root,
  2392. u64 root_objectid, u64 owner, u64 offset,
  2393. struct btrfs_key *ins);
  2394. int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
  2395. struct btrfs_root *root,
  2396. u64 num_bytes, u64 min_alloc_size,
  2397. u64 empty_size, u64 hint_byte,
  2398. struct btrfs_key *ins, u64 data);
  2399. int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  2400. struct extent_buffer *buf, int full_backref, int for_cow);
  2401. int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  2402. struct extent_buffer *buf, int full_backref, int for_cow);
  2403. int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
  2404. struct btrfs_root *root,
  2405. u64 bytenr, u64 num_bytes, u64 flags,
  2406. int is_data);
  2407. int btrfs_free_extent(struct btrfs_trans_handle *trans,
  2408. struct btrfs_root *root,
  2409. u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid,
  2410. u64 owner, u64 offset, int for_cow);
  2411. int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len);
  2412. int btrfs_free_and_pin_reserved_extent(struct btrfs_root *root,
  2413. u64 start, u64 len);
  2414. void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans,
  2415. struct btrfs_root *root);
  2416. int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
  2417. struct btrfs_root *root);
  2418. int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
  2419. struct btrfs_root *root,
  2420. u64 bytenr, u64 num_bytes, u64 parent,
  2421. u64 root_objectid, u64 owner, u64 offset, int for_cow);
  2422. int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
  2423. struct btrfs_root *root);
  2424. int btrfs_extent_readonly(struct btrfs_root *root, u64 bytenr);
  2425. int btrfs_free_block_groups(struct btrfs_fs_info *info);
  2426. int btrfs_read_block_groups(struct btrfs_root *root);
  2427. int btrfs_can_relocate(struct btrfs_root *root, u64 bytenr);
  2428. int btrfs_make_block_group(struct btrfs_trans_handle *trans,
  2429. struct btrfs_root *root, u64 bytes_used,
  2430. u64 type, u64 chunk_objectid, u64 chunk_offset,
  2431. u64 size);
  2432. int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
  2433. struct btrfs_root *root, u64 group_start);
  2434. u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags);
  2435. u64 btrfs_get_alloc_profile(struct btrfs_root *root, int data);
  2436. void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
  2437. int btrfs_check_data_free_space(struct inode *inode, u64 bytes);
  2438. void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes);
  2439. void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans,
  2440. struct btrfs_root *root);
  2441. int btrfs_orphan_reserve_metadata(struct btrfs_trans_handle *trans,
  2442. struct inode *inode);
  2443. void btrfs_orphan_release_metadata(struct inode *inode);
  2444. int btrfs_snap_reserve_metadata(struct btrfs_trans_handle *trans,
  2445. struct btrfs_pending_snapshot *pending);
  2446. int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes);
  2447. void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes);
  2448. int btrfs_delalloc_reserve_space(struct inode *inode, u64 num_bytes);
  2449. void btrfs_delalloc_release_space(struct inode *inode, u64 num_bytes);
  2450. void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv);
  2451. struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root);
  2452. void btrfs_free_block_rsv(struct btrfs_root *root,
  2453. struct btrfs_block_rsv *rsv);
  2454. int btrfs_block_rsv_add(struct btrfs_root *root,
  2455. struct btrfs_block_rsv *block_rsv,
  2456. u64 num_bytes);
  2457. int btrfs_block_rsv_add_noflush(struct btrfs_root *root,
  2458. struct btrfs_block_rsv *block_rsv,
  2459. u64 num_bytes);
  2460. int btrfs_block_rsv_check(struct btrfs_root *root,
  2461. struct btrfs_block_rsv *block_rsv, int min_factor);
  2462. int btrfs_block_rsv_refill(struct btrfs_root *root,
  2463. struct btrfs_block_rsv *block_rsv,
  2464. u64 min_reserved);
  2465. int btrfs_block_rsv_refill_noflush(struct btrfs_root *root,
  2466. struct btrfs_block_rsv *block_rsv,
  2467. u64 min_reserved);
  2468. int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
  2469. struct btrfs_block_rsv *dst_rsv,
  2470. u64 num_bytes);
  2471. void btrfs_block_rsv_release(struct btrfs_root *root,
  2472. struct btrfs_block_rsv *block_rsv,
  2473. u64 num_bytes);
  2474. int btrfs_set_block_group_ro(struct btrfs_root *root,
  2475. struct btrfs_block_group_cache *cache);
  2476. void btrfs_set_block_group_rw(struct btrfs_root *root,
  2477. struct btrfs_block_group_cache *cache);
  2478. void btrfs_put_block_group_cache(struct btrfs_fs_info *info);
  2479. u64 btrfs_account_ro_block_groups_free_space(struct btrfs_space_info *sinfo);
  2480. int btrfs_error_unpin_extent_range(struct btrfs_root *root,
  2481. u64 start, u64 end);
  2482. int btrfs_error_discard_extent(struct btrfs_root *root, u64 bytenr,
  2483. u64 num_bytes, u64 *actual_bytes);
  2484. int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans,
  2485. struct btrfs_root *root, u64 type);
  2486. int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range);
  2487. int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
  2488. int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans,
  2489. struct btrfs_fs_info *fs_info);
  2490. /* ctree.c */
  2491. int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key,
  2492. int level, int *slot);
  2493. int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2);
  2494. int btrfs_previous_item(struct btrfs_root *root,
  2495. struct btrfs_path *path, u64 min_objectid,
  2496. int type);
  2497. void btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
  2498. struct btrfs_root *root, struct btrfs_path *path,
  2499. struct btrfs_key *new_key);
  2500. struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
  2501. struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
  2502. int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
  2503. struct btrfs_key *key, int lowest_level,
  2504. int cache_only, u64 min_trans);
  2505. int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
  2506. struct btrfs_key *max_key,
  2507. struct btrfs_path *path, int cache_only,
  2508. u64 min_trans);
  2509. enum btrfs_compare_tree_result {
  2510. BTRFS_COMPARE_TREE_NEW,
  2511. BTRFS_COMPARE_TREE_DELETED,
  2512. BTRFS_COMPARE_TREE_CHANGED,
  2513. };
  2514. typedef int (*btrfs_changed_cb_t)(struct btrfs_root *left_root,
  2515. struct btrfs_root *right_root,
  2516. struct btrfs_path *left_path,
  2517. struct btrfs_path *right_path,
  2518. struct btrfs_key *key,
  2519. enum btrfs_compare_tree_result result,
  2520. void *ctx);
  2521. int btrfs_compare_trees(struct btrfs_root *left_root,
  2522. struct btrfs_root *right_root,
  2523. btrfs_changed_cb_t cb, void *ctx);
  2524. int btrfs_cow_block(struct btrfs_trans_handle *trans,
  2525. struct btrfs_root *root, struct extent_buffer *buf,
  2526. struct extent_buffer *parent, int parent_slot,
  2527. struct extent_buffer **cow_ret);
  2528. int btrfs_copy_root(struct btrfs_trans_handle *trans,
  2529. struct btrfs_root *root,
  2530. struct extent_buffer *buf,
  2531. struct extent_buffer **cow_ret, u64 new_root_objectid);
  2532. int btrfs_block_can_be_shared(struct btrfs_root *root,
  2533. struct extent_buffer *buf);
  2534. void btrfs_extend_item(struct btrfs_trans_handle *trans,
  2535. struct btrfs_root *root, struct btrfs_path *path,
  2536. u32 data_size);
  2537. void btrfs_truncate_item(struct btrfs_trans_handle *trans,
  2538. struct btrfs_root *root,
  2539. struct btrfs_path *path,
  2540. u32 new_size, int from_end);
  2541. int btrfs_split_item(struct btrfs_trans_handle *trans,
  2542. struct btrfs_root *root,
  2543. struct btrfs_path *path,
  2544. struct btrfs_key *new_key,
  2545. unsigned long split_offset);
  2546. int btrfs_duplicate_item(struct btrfs_trans_handle *trans,
  2547. struct btrfs_root *root,
  2548. struct btrfs_path *path,
  2549. struct btrfs_key *new_key);
  2550. int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
  2551. *root, struct btrfs_key *key, struct btrfs_path *p, int
  2552. ins_len, int cow);
  2553. int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key,
  2554. struct btrfs_path *p, u64 time_seq);
  2555. int btrfs_search_slot_for_read(struct btrfs_root *root,
  2556. struct btrfs_key *key, struct btrfs_path *p,
  2557. int find_higher, int return_any);
  2558. int btrfs_realloc_node(struct btrfs_trans_handle *trans,
  2559. struct btrfs_root *root, struct extent_buffer *parent,
  2560. int start_slot, int cache_only, u64 *last_ret,
  2561. struct btrfs_key *progress);
  2562. void btrfs_release_path(struct btrfs_path *p);
  2563. struct btrfs_path *btrfs_alloc_path(void);
  2564. void btrfs_free_path(struct btrfs_path *p);
  2565. void btrfs_set_path_blocking(struct btrfs_path *p);
  2566. void btrfs_clear_path_blocking(struct btrfs_path *p,
  2567. struct extent_buffer *held, int held_rw);
  2568. void btrfs_unlock_up_safe(struct btrfs_path *p, int level);
  2569. int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  2570. struct btrfs_path *path, int slot, int nr);
  2571. static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
  2572. struct btrfs_root *root,
  2573. struct btrfs_path *path)
  2574. {
  2575. return btrfs_del_items(trans, root, path, path->slots[0], 1);
  2576. }
  2577. void setup_items_for_insert(struct btrfs_trans_handle *trans,
  2578. struct btrfs_root *root, struct btrfs_path *path,
  2579. struct btrfs_key *cpu_key, u32 *data_size,
  2580. u32 total_data, u32 total_size, int nr);
  2581. int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
  2582. *root, struct btrfs_key *key, void *data, u32 data_size);
  2583. int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
  2584. struct btrfs_root *root,
  2585. struct btrfs_path *path,
  2586. struct btrfs_key *cpu_key, u32 *data_size, int nr);
  2587. static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
  2588. struct btrfs_root *root,
  2589. struct btrfs_path *path,
  2590. struct btrfs_key *key,
  2591. u32 data_size)
  2592. {
  2593. return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
  2594. }
  2595. int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  2596. int btrfs_next_old_leaf(struct btrfs_root *root, struct btrfs_path *path,
  2597. u64 time_seq);
  2598. static inline int btrfs_next_old_item(struct btrfs_root *root,
  2599. struct btrfs_path *p, u64 time_seq)
  2600. {
  2601. ++p->slots[0];
  2602. if (p->slots[0] >= btrfs_header_nritems(p->nodes[0]))
  2603. return btrfs_next_old_leaf(root, p, time_seq);
  2604. return 0;
  2605. }
  2606. static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p)
  2607. {
  2608. return btrfs_next_old_item(root, p, 0);
  2609. }
  2610. int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
  2611. int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
  2612. int __must_check btrfs_drop_snapshot(struct btrfs_root *root,
  2613. struct btrfs_block_rsv *block_rsv,
  2614. int update_ref, int for_reloc);
  2615. int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
  2616. struct btrfs_root *root,
  2617. struct extent_buffer *node,
  2618. struct extent_buffer *parent);
  2619. static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
  2620. {
  2621. /*
  2622. * Get synced with close_ctree()
  2623. */
  2624. smp_mb();
  2625. return fs_info->closing;
  2626. }
  2627. static inline void free_fs_info(struct btrfs_fs_info *fs_info)
  2628. {
  2629. kfree(fs_info->balance_ctl);
  2630. kfree(fs_info->delayed_root);
  2631. kfree(fs_info->extent_root);
  2632. kfree(fs_info->tree_root);
  2633. kfree(fs_info->chunk_root);
  2634. kfree(fs_info->dev_root);
  2635. kfree(fs_info->csum_root);
  2636. kfree(fs_info->quota_root);
  2637. kfree(fs_info->super_copy);
  2638. kfree(fs_info->super_for_commit);
  2639. kfree(fs_info);
  2640. }
  2641. /* tree mod log functions from ctree.c */
  2642. u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
  2643. struct seq_list *elem);
  2644. void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
  2645. struct seq_list *elem);
  2646. static inline u64 btrfs_inc_tree_mod_seq(struct btrfs_fs_info *fs_info)
  2647. {
  2648. return atomic_inc_return(&fs_info->tree_mod_seq);
  2649. }
  2650. /* root-item.c */
  2651. int btrfs_find_root_ref(struct btrfs_root *tree_root,
  2652. struct btrfs_path *path,
  2653. u64 root_id, u64 ref_id);
  2654. int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
  2655. struct btrfs_root *tree_root,
  2656. u64 root_id, u64 ref_id, u64 dirid, u64 sequence,
  2657. const char *name, int name_len);
  2658. int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
  2659. struct btrfs_root *tree_root,
  2660. u64 root_id, u64 ref_id, u64 dirid, u64 *sequence,
  2661. const char *name, int name_len);
  2662. int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  2663. struct btrfs_key *key);
  2664. int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  2665. *root, struct btrfs_key *key, struct btrfs_root_item
  2666. *item);
  2667. int __must_check btrfs_update_root(struct btrfs_trans_handle *trans,
  2668. struct btrfs_root *root,
  2669. struct btrfs_key *key,
  2670. struct btrfs_root_item *item);
  2671. void btrfs_read_root_item(struct btrfs_root *root,
  2672. struct extent_buffer *eb, int slot,
  2673. struct btrfs_root_item *item);
  2674. int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
  2675. btrfs_root_item *item, struct btrfs_key *key);
  2676. int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid);
  2677. int btrfs_find_orphan_roots(struct btrfs_root *tree_root);
  2678. void btrfs_set_root_node(struct btrfs_root_item *item,
  2679. struct extent_buffer *node);
  2680. void btrfs_check_and_init_root_item(struct btrfs_root_item *item);
  2681. void btrfs_update_root_times(struct btrfs_trans_handle *trans,
  2682. struct btrfs_root *root);
  2683. /* dir-item.c */
  2684. int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
  2685. struct btrfs_root *root, const char *name,
  2686. int name_len, struct inode *dir,
  2687. struct btrfs_key *location, u8 type, u64 index);
  2688. struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
  2689. struct btrfs_root *root,
  2690. struct btrfs_path *path, u64 dir,
  2691. const char *name, int name_len,
  2692. int mod);
  2693. struct btrfs_dir_item *
  2694. btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
  2695. struct btrfs_root *root,
  2696. struct btrfs_path *path, u64 dir,
  2697. u64 objectid, const char *name, int name_len,
  2698. int mod);
  2699. struct btrfs_dir_item *
  2700. btrfs_search_dir_index_item(struct btrfs_root *root,
  2701. struct btrfs_path *path, u64 dirid,
  2702. const char *name, int name_len);
  2703. struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
  2704. struct btrfs_path *path,
  2705. const char *name, int name_len);
  2706. int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
  2707. struct btrfs_root *root,
  2708. struct btrfs_path *path,
  2709. struct btrfs_dir_item *di);
  2710. int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
  2711. struct btrfs_root *root,
  2712. struct btrfs_path *path, u64 objectid,
  2713. const char *name, u16 name_len,
  2714. const void *data, u16 data_len);
  2715. struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
  2716. struct btrfs_root *root,
  2717. struct btrfs_path *path, u64 dir,
  2718. const char *name, u16 name_len,
  2719. int mod);
  2720. int verify_dir_item(struct btrfs_root *root,
  2721. struct extent_buffer *leaf,
  2722. struct btrfs_dir_item *dir_item);
  2723. /* orphan.c */
  2724. int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
  2725. struct btrfs_root *root, u64 offset);
  2726. int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
  2727. struct btrfs_root *root, u64 offset);
  2728. int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset);
  2729. /* inode-item.c */
  2730. int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
  2731. struct btrfs_root *root,
  2732. const char *name, int name_len,
  2733. u64 inode_objectid, u64 ref_objectid, u64 index);
  2734. int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
  2735. struct btrfs_root *root,
  2736. const char *name, int name_len,
  2737. u64 inode_objectid, u64 ref_objectid, u64 *index);
  2738. struct btrfs_inode_ref *
  2739. btrfs_lookup_inode_ref(struct btrfs_trans_handle *trans,
  2740. struct btrfs_root *root,
  2741. struct btrfs_path *path,
  2742. const char *name, int name_len,
  2743. u64 inode_objectid, u64 ref_objectid, int mod);
  2744. int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
  2745. struct btrfs_root *root,
  2746. struct btrfs_path *path, u64 objectid);
  2747. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  2748. *root, struct btrfs_path *path,
  2749. struct btrfs_key *location, int mod);
  2750. /* file-item.c */
  2751. int btrfs_del_csums(struct btrfs_trans_handle *trans,
  2752. struct btrfs_root *root, u64 bytenr, u64 len);
  2753. int btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode,
  2754. struct bio *bio, u32 *dst);
  2755. int btrfs_lookup_bio_sums_dio(struct btrfs_root *root, struct inode *inode,
  2756. struct bio *bio, u64 logical_offset);
  2757. int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
  2758. struct btrfs_root *root,
  2759. u64 objectid, u64 pos,
  2760. u64 disk_offset, u64 disk_num_bytes,
  2761. u64 num_bytes, u64 offset, u64 ram_bytes,
  2762. u8 compression, u8 encryption, u16 other_encoding);
  2763. int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
  2764. struct btrfs_root *root,
  2765. struct btrfs_path *path, u64 objectid,
  2766. u64 bytenr, int mod);
  2767. int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
  2768. struct btrfs_root *root,
  2769. struct btrfs_ordered_sum *sums);
  2770. int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
  2771. struct bio *bio, u64 file_start, int contig);
  2772. struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
  2773. struct btrfs_root *root,
  2774. struct btrfs_path *path,
  2775. u64 bytenr, int cow);
  2776. int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
  2777. struct btrfs_root *root, struct btrfs_path *path,
  2778. u64 isize);
  2779. int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
  2780. struct list_head *list, int search_commit);
  2781. /* inode.c */
  2782. struct extent_map *btrfs_get_extent_fiemap(struct inode *inode, struct page *page,
  2783. size_t pg_offset, u64 start, u64 len,
  2784. int create);
  2785. /* RHEL and EL kernels have a patch that renames PG_checked to FsMisc */
  2786. #if defined(ClearPageFsMisc) && !defined(ClearPageChecked)
  2787. #define ClearPageChecked ClearPageFsMisc
  2788. #define SetPageChecked SetPageFsMisc
  2789. #define PageChecked PageFsMisc
  2790. #endif
  2791. /* This forces readahead on a given range of bytes in an inode */
  2792. static inline void btrfs_force_ra(struct address_space *mapping,
  2793. struct file_ra_state *ra, struct file *file,
  2794. pgoff_t offset, unsigned long req_size)
  2795. {
  2796. page_cache_sync_readahead(mapping, ra, file, offset, req_size);
  2797. }
  2798. struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);
  2799. int btrfs_set_inode_index(struct inode *dir, u64 *index);
  2800. int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
  2801. struct btrfs_root *root,
  2802. struct inode *dir, struct inode *inode,
  2803. const char *name, int name_len);
  2804. int btrfs_add_link(struct btrfs_trans_handle *trans,
  2805. struct inode *parent_inode, struct inode *inode,
  2806. const char *name, int name_len, int add_backref, u64 index);
  2807. int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
  2808. struct btrfs_root *root,
  2809. struct inode *dir, u64 objectid,
  2810. const char *name, int name_len);
  2811. int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
  2812. struct btrfs_root *root,
  2813. struct inode *inode, u64 new_size,
  2814. u32 min_type);
  2815. int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput);
  2816. int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
  2817. struct extent_state **cached_state);
  2818. int btrfs_writepages(struct address_space *mapping,
  2819. struct writeback_control *wbc);
  2820. int btrfs_create_subvol_root(struct btrfs_trans_handle *trans,
  2821. struct btrfs_root *new_root, u64 new_dirid);
  2822. int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
  2823. size_t size, struct bio *bio, unsigned long bio_flags);
  2824. int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
  2825. int btrfs_readpage(struct file *file, struct page *page);
  2826. void btrfs_evict_inode(struct inode *inode);
  2827. int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc);
  2828. int btrfs_dirty_inode(struct inode *inode);
  2829. struct inode *btrfs_alloc_inode(struct super_block *sb);
  2830. void btrfs_destroy_inode(struct inode *inode);
  2831. int btrfs_drop_inode(struct inode *inode);
  2832. int btrfs_init_cachep(void);
  2833. void btrfs_destroy_cachep(void);
  2834. long btrfs_ioctl_trans_end(struct file *file);
  2835. struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
  2836. struct btrfs_root *root, int *was_new);
  2837. struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
  2838. size_t pg_offset, u64 start, u64 end,
  2839. int create);
  2840. int btrfs_update_inode(struct btrfs_trans_handle *trans,
  2841. struct btrfs_root *root,
  2842. struct inode *inode);
  2843. int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode);
  2844. int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode);
  2845. int btrfs_orphan_cleanup(struct btrfs_root *root);
  2846. void btrfs_orphan_commit_root(struct btrfs_trans_handle *trans,
  2847. struct btrfs_root *root);
  2848. int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size);
  2849. void btrfs_invalidate_inodes(struct btrfs_root *root);
  2850. void btrfs_add_delayed_iput(struct inode *inode);
  2851. void btrfs_run_delayed_iputs(struct btrfs_root *root);
  2852. int btrfs_prealloc_file_range(struct inode *inode, int mode,
  2853. u64 start, u64 num_bytes, u64 min_size,
  2854. loff_t actual_len, u64 *alloc_hint);
  2855. int btrfs_prealloc_file_range_trans(struct inode *inode,
  2856. struct btrfs_trans_handle *trans, int mode,
  2857. u64 start, u64 num_bytes, u64 min_size,
  2858. loff_t actual_len, u64 *alloc_hint);
  2859. extern const struct dentry_operations btrfs_dentry_operations;
  2860. /* ioctl.c */
  2861. long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  2862. void btrfs_update_iflags(struct inode *inode);
  2863. void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
  2864. int btrfs_defrag_file(struct inode *inode, struct file *file,
  2865. struct btrfs_ioctl_defrag_range_args *range,
  2866. u64 newer_than, unsigned long max_pages);
  2867. /* file.c */
  2868. int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
  2869. struct inode *inode);
  2870. int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info);
  2871. int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
  2872. int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
  2873. int skip_pinned);
  2874. extern const struct file_operations btrfs_file_operations;
  2875. int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode,
  2876. u64 start, u64 end, u64 *hint_byte, int drop_cache);
  2877. int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
  2878. struct inode *inode, u64 start, u64 end);
  2879. int btrfs_release_file(struct inode *inode, struct file *file);
  2880. void btrfs_drop_pages(struct page **pages, size_t num_pages);
  2881. int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,
  2882. struct page **pages, size_t num_pages,
  2883. loff_t pos, size_t write_bytes,
  2884. struct extent_state **cached);
  2885. /* tree-defrag.c */
  2886. int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
  2887. struct btrfs_root *root, int cache_only);
  2888. /* sysfs.c */
  2889. int btrfs_init_sysfs(void);
  2890. void btrfs_exit_sysfs(void);
  2891. /* xattr.c */
  2892. ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  2893. /* super.c */
  2894. int btrfs_parse_options(struct btrfs_root *root, char *options);
  2895. int btrfs_sync_fs(struct super_block *sb, int wait);
  2896. #ifdef CONFIG_PRINTK
  2897. __printf(2, 3)
  2898. void btrfs_printk(struct btrfs_fs_info *fs_info, const char *fmt, ...);
  2899. #else
  2900. static inline __printf(2, 3)
  2901. void btrfs_printk(struct btrfs_fs_info *fs_info, const char *fmt, ...)
  2902. {
  2903. }
  2904. #endif
  2905. __printf(5, 6)
  2906. void __btrfs_std_error(struct btrfs_fs_info *fs_info, const char *function,
  2907. unsigned int line, int errno, const char *fmt, ...);
  2908. void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
  2909. struct btrfs_root *root, const char *function,
  2910. unsigned int line, int errno);
  2911. #define btrfs_set_fs_incompat(__fs_info, opt) \
  2912. __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
  2913. static inline void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info,
  2914. u64 flag)
  2915. {
  2916. struct btrfs_super_block *disk_super;
  2917. u64 features;
  2918. disk_super = fs_info->super_copy;
  2919. features = btrfs_super_incompat_flags(disk_super);
  2920. if (!(features & flag)) {
  2921. features |= flag;
  2922. btrfs_set_super_incompat_flags(disk_super, features);
  2923. }
  2924. }
  2925. #define btrfs_abort_transaction(trans, root, errno) \
  2926. do { \
  2927. __btrfs_abort_transaction(trans, root, __func__, \
  2928. __LINE__, errno); \
  2929. } while (0)
  2930. #define btrfs_std_error(fs_info, errno) \
  2931. do { \
  2932. if ((errno)) \
  2933. __btrfs_std_error((fs_info), __func__, \
  2934. __LINE__, (errno), NULL); \
  2935. } while (0)
  2936. #define btrfs_error(fs_info, errno, fmt, args...) \
  2937. do { \
  2938. __btrfs_std_error((fs_info), __func__, __LINE__, \
  2939. (errno), fmt, ##args); \
  2940. } while (0)
  2941. __printf(5, 6)
  2942. void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
  2943. unsigned int line, int errno, const char *fmt, ...);
  2944. #define btrfs_panic(fs_info, errno, fmt, args...) \
  2945. do { \
  2946. struct btrfs_fs_info *_i = (fs_info); \
  2947. __btrfs_panic(_i, __func__, __LINE__, errno, fmt, ##args); \
  2948. BUG_ON(!(_i->mount_opt & BTRFS_MOUNT_PANIC_ON_FATAL_ERROR)); \
  2949. } while (0)
  2950. /* acl.c */
  2951. #ifdef CONFIG_BTRFS_FS_POSIX_ACL
  2952. struct posix_acl *btrfs_get_acl(struct inode *inode, int type);
  2953. int btrfs_init_acl(struct btrfs_trans_handle *trans,
  2954. struct inode *inode, struct inode *dir);
  2955. int btrfs_acl_chmod(struct inode *inode);
  2956. #else
  2957. #define btrfs_get_acl NULL
  2958. static inline int btrfs_init_acl(struct btrfs_trans_handle *trans,
  2959. struct inode *inode, struct inode *dir)
  2960. {
  2961. return 0;
  2962. }
  2963. static inline int btrfs_acl_chmod(struct inode *inode)
  2964. {
  2965. return 0;
  2966. }
  2967. #endif
  2968. /* relocation.c */
  2969. int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start);
  2970. int btrfs_init_reloc_root(struct btrfs_trans_handle *trans,
  2971. struct btrfs_root *root);
  2972. int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
  2973. struct btrfs_root *root);
  2974. int btrfs_recover_relocation(struct btrfs_root *root);
  2975. int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len);
  2976. void btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
  2977. struct btrfs_root *root, struct extent_buffer *buf,
  2978. struct extent_buffer *cow);
  2979. void btrfs_reloc_pre_snapshot(struct btrfs_trans_handle *trans,
  2980. struct btrfs_pending_snapshot *pending,
  2981. u64 *bytes_to_reserve);
  2982. int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
  2983. struct btrfs_pending_snapshot *pending);
  2984. /* scrub.c */
  2985. int btrfs_scrub_dev(struct btrfs_root *root, u64 devid, u64 start, u64 end,
  2986. struct btrfs_scrub_progress *progress, int readonly);
  2987. void btrfs_scrub_pause(struct btrfs_root *root);
  2988. void btrfs_scrub_pause_super(struct btrfs_root *root);
  2989. void btrfs_scrub_continue(struct btrfs_root *root);
  2990. void btrfs_scrub_continue_super(struct btrfs_root *root);
  2991. int __btrfs_scrub_cancel(struct btrfs_fs_info *info);
  2992. int btrfs_scrub_cancel(struct btrfs_root *root);
  2993. int btrfs_scrub_cancel_dev(struct btrfs_root *root, struct btrfs_device *dev);
  2994. int btrfs_scrub_cancel_devid(struct btrfs_root *root, u64 devid);
  2995. int btrfs_scrub_progress(struct btrfs_root *root, u64 devid,
  2996. struct btrfs_scrub_progress *progress);
  2997. /* reada.c */
  2998. struct reada_control {
  2999. struct btrfs_root *root; /* tree to prefetch */
  3000. struct btrfs_key key_start;
  3001. struct btrfs_key key_end; /* exclusive */
  3002. atomic_t elems;
  3003. struct kref refcnt;
  3004. wait_queue_head_t wait;
  3005. };
  3006. struct reada_control *btrfs_reada_add(struct btrfs_root *root,
  3007. struct btrfs_key *start, struct btrfs_key *end);
  3008. int btrfs_reada_wait(void *handle);
  3009. void btrfs_reada_detach(void *handle);
  3010. int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb,
  3011. u64 start, int err);
  3012. /* qgroup.c */
  3013. struct qgroup_update {
  3014. struct list_head list;
  3015. struct btrfs_delayed_ref_node *node;
  3016. struct btrfs_delayed_extent_op *extent_op;
  3017. };
  3018. int btrfs_quota_enable(struct btrfs_trans_handle *trans,
  3019. struct btrfs_fs_info *fs_info);
  3020. int btrfs_quota_disable(struct btrfs_trans_handle *trans,
  3021. struct btrfs_fs_info *fs_info);
  3022. int btrfs_quota_rescan(struct btrfs_fs_info *fs_info);
  3023. int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
  3024. struct btrfs_fs_info *fs_info, u64 src, u64 dst);
  3025. int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
  3026. struct btrfs_fs_info *fs_info, u64 src, u64 dst);
  3027. int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
  3028. struct btrfs_fs_info *fs_info, u64 qgroupid,
  3029. char *name);
  3030. int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
  3031. struct btrfs_fs_info *fs_info, u64 qgroupid);
  3032. int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
  3033. struct btrfs_fs_info *fs_info, u64 qgroupid,
  3034. struct btrfs_qgroup_limit *limit);
  3035. int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info);
  3036. void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
  3037. struct btrfs_delayed_extent_op;
  3038. int btrfs_qgroup_record_ref(struct btrfs_trans_handle *trans,
  3039. struct btrfs_delayed_ref_node *node,
  3040. struct btrfs_delayed_extent_op *extent_op);
  3041. int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans,
  3042. struct btrfs_fs_info *fs_info,
  3043. struct btrfs_delayed_ref_node *node,
  3044. struct btrfs_delayed_extent_op *extent_op);
  3045. int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
  3046. struct btrfs_fs_info *fs_info);
  3047. int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans,
  3048. struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid,
  3049. struct btrfs_qgroup_inherit *inherit);
  3050. int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes);
  3051. void btrfs_qgroup_free(struct btrfs_root *root, u64 num_bytes);
  3052. void assert_qgroups_uptodate(struct btrfs_trans_handle *trans);
  3053. static inline int is_fstree(u64 rootid)
  3054. {
  3055. if (rootid == BTRFS_FS_TREE_OBJECTID ||
  3056. (s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID)
  3057. return 1;
  3058. return 0;
  3059. }
  3060. #endif