ctree.h 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914
  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/version.h>
  21. #include <linux/mm.h>
  22. #include <linux/highmem.h>
  23. #include <linux/fs.h>
  24. #include <linux/completion.h>
  25. #include <linux/backing-dev.h>
  26. #include <linux/wait.h>
  27. #include <asm/kmap_types.h>
  28. #include "extent_io.h"
  29. #include "extent_map.h"
  30. #include "async-thread.h"
  31. struct btrfs_trans_handle;
  32. struct btrfs_transaction;
  33. extern struct kmem_cache *btrfs_trans_handle_cachep;
  34. extern struct kmem_cache *btrfs_transaction_cachep;
  35. extern struct kmem_cache *btrfs_bit_radix_cachep;
  36. extern struct kmem_cache *btrfs_path_cachep;
  37. struct btrfs_ordered_sum;
  38. #define BTRFS_MAGIC "_B9RfS_M"
  39. #define BTRFS_ACL_NOT_CACHED ((void *)-1)
  40. #ifdef CONFIG_LOCKDEP
  41. # define BTRFS_MAX_LEVEL 7
  42. #else
  43. # define BTRFS_MAX_LEVEL 8
  44. #endif
  45. /* holds pointers to all of the tree roots */
  46. #define BTRFS_ROOT_TREE_OBJECTID 1ULL
  47. /* stores information about which extents are in use, and reference counts */
  48. #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
  49. /*
  50. * chunk tree stores translations from logical -> physical block numbering
  51. * the super block points to the chunk tree
  52. */
  53. #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
  54. /*
  55. * stores information about which areas of a given device are in use.
  56. * one per device. The tree of tree roots points to the device tree
  57. */
  58. #define BTRFS_DEV_TREE_OBJECTID 4ULL
  59. /* one per subvolume, storing files and directories */
  60. #define BTRFS_FS_TREE_OBJECTID 5ULL
  61. /* directory objectid inside the root tree */
  62. #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
  63. /* orhpan objectid for tracking unlinked/truncated files */
  64. #define BTRFS_ORPHAN_OBJECTID -5ULL
  65. /* does write ahead logging to speed up fsyncs */
  66. #define BTRFS_TREE_LOG_OBJECTID -6ULL
  67. #define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
  68. /* for space balancing */
  69. #define BTRFS_TREE_RELOC_OBJECTID -8ULL
  70. #define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
  71. /* dummy objectid represents multiple objectids */
  72. #define BTRFS_MULTIPLE_OBJECTIDS -255ULL
  73. /*
  74. * All files have objectids in this range.
  75. */
  76. #define BTRFS_FIRST_FREE_OBJECTID 256ULL
  77. #define BTRFS_LAST_FREE_OBJECTID -256ULL
  78. #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
  79. /*
  80. * the device items go into the chunk tree. The key is in the form
  81. * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
  82. */
  83. #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
  84. /*
  85. * we can actually store much bigger names, but lets not confuse the rest
  86. * of linux
  87. */
  88. #define BTRFS_NAME_LEN 255
  89. /* 32 bytes in various csum fields */
  90. #define BTRFS_CSUM_SIZE 32
  91. /* four bytes for CRC32 */
  92. #define BTRFS_CRC32_SIZE 4
  93. #define BTRFS_EMPTY_DIR_SIZE 0
  94. #define BTRFS_FT_UNKNOWN 0
  95. #define BTRFS_FT_REG_FILE 1
  96. #define BTRFS_FT_DIR 2
  97. #define BTRFS_FT_CHRDEV 3
  98. #define BTRFS_FT_BLKDEV 4
  99. #define BTRFS_FT_FIFO 5
  100. #define BTRFS_FT_SOCK 6
  101. #define BTRFS_FT_SYMLINK 7
  102. #define BTRFS_FT_XATTR 8
  103. #define BTRFS_FT_MAX 9
  104. /*
  105. * the key defines the order in the tree, and so it also defines (optimal)
  106. * block layout. objectid corresonds to the inode number. The flags
  107. * tells us things about the object, and is a kind of stream selector.
  108. * so for a given inode, keys with flags of 1 might refer to the inode
  109. * data, flags of 2 may point to file data in the btree and flags == 3
  110. * may point to extents.
  111. *
  112. * offset is the starting byte offset for this key in the stream.
  113. *
  114. * btrfs_disk_key is in disk byte order. struct btrfs_key is always
  115. * in cpu native order. Otherwise they are identical and their sizes
  116. * should be the same (ie both packed)
  117. */
  118. struct btrfs_disk_key {
  119. __le64 objectid;
  120. u8 type;
  121. __le64 offset;
  122. } __attribute__ ((__packed__));
  123. struct btrfs_key {
  124. u64 objectid;
  125. u8 type;
  126. u64 offset;
  127. } __attribute__ ((__packed__));
  128. struct btrfs_mapping_tree {
  129. struct extent_map_tree map_tree;
  130. };
  131. #define BTRFS_UUID_SIZE 16
  132. struct btrfs_dev_item {
  133. /* the internal btrfs device id */
  134. __le64 devid;
  135. /* size of the device */
  136. __le64 total_bytes;
  137. /* bytes used */
  138. __le64 bytes_used;
  139. /* optimal io alignment for this device */
  140. __le32 io_align;
  141. /* optimal io width for this device */
  142. __le32 io_width;
  143. /* minimal io size for this device */
  144. __le32 sector_size;
  145. /* type and info about this device */
  146. __le64 type;
  147. /* grouping information for allocation decisions */
  148. __le32 dev_group;
  149. /* seek speed 0-100 where 100 is fastest */
  150. u8 seek_speed;
  151. /* bandwidth 0-100 where 100 is fastest */
  152. u8 bandwidth;
  153. /* btrfs generated uuid for this device */
  154. u8 uuid[BTRFS_UUID_SIZE];
  155. } __attribute__ ((__packed__));
  156. struct btrfs_stripe {
  157. __le64 devid;
  158. __le64 offset;
  159. u8 dev_uuid[BTRFS_UUID_SIZE];
  160. } __attribute__ ((__packed__));
  161. struct btrfs_chunk {
  162. /* size of this chunk in bytes */
  163. __le64 length;
  164. /* objectid of the root referencing this chunk */
  165. __le64 owner;
  166. __le64 stripe_len;
  167. __le64 type;
  168. /* optimal io alignment for this chunk */
  169. __le32 io_align;
  170. /* optimal io width for this chunk */
  171. __le32 io_width;
  172. /* minimal io size for this chunk */
  173. __le32 sector_size;
  174. /* 2^16 stripes is quite a lot, a second limit is the size of a single
  175. * item in the btree
  176. */
  177. __le16 num_stripes;
  178. /* sub stripes only matter for raid10 */
  179. __le16 sub_stripes;
  180. struct btrfs_stripe stripe;
  181. /* additional stripes go here */
  182. } __attribute__ ((__packed__));
  183. static inline unsigned long btrfs_chunk_item_size(int num_stripes)
  184. {
  185. BUG_ON(num_stripes == 0);
  186. return sizeof(struct btrfs_chunk) +
  187. sizeof(struct btrfs_stripe) * (num_stripes - 1);
  188. }
  189. #define BTRFS_FSID_SIZE 16
  190. #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
  191. /*
  192. * every tree block (leaf or node) starts with this header.
  193. */
  194. struct btrfs_header {
  195. /* these first four must match the super block */
  196. u8 csum[BTRFS_CSUM_SIZE];
  197. u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
  198. __le64 bytenr; /* which block this node is supposed to live in */
  199. __le64 flags;
  200. /* allowed to be different from the super from here on down */
  201. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  202. __le64 generation;
  203. __le64 owner;
  204. __le32 nritems;
  205. u8 level;
  206. } __attribute__ ((__packed__));
  207. #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
  208. sizeof(struct btrfs_header)) / \
  209. sizeof(struct btrfs_key_ptr))
  210. #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
  211. #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
  212. #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
  213. sizeof(struct btrfs_item) - \
  214. sizeof(struct btrfs_file_extent_item))
  215. /*
  216. * this is a very generous portion of the super block, giving us
  217. * room to translate 14 chunks with 3 stripes each.
  218. */
  219. #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
  220. #define BTRFS_LABEL_SIZE 256
  221. /*
  222. * the super block basically lists the main trees of the FS
  223. * it currently lacks any block count etc etc
  224. */
  225. struct btrfs_super_block {
  226. u8 csum[BTRFS_CSUM_SIZE];
  227. /* the first 4 fields must match struct btrfs_header */
  228. u8 fsid[16]; /* FS specific uuid */
  229. __le64 bytenr; /* this block number */
  230. __le64 flags;
  231. /* allowed to be different from the btrfs_header from here own down */
  232. __le64 magic;
  233. __le64 generation;
  234. __le64 root;
  235. __le64 chunk_root;
  236. __le64 log_root;
  237. __le64 total_bytes;
  238. __le64 bytes_used;
  239. __le64 root_dir_objectid;
  240. __le64 num_devices;
  241. __le32 sectorsize;
  242. __le32 nodesize;
  243. __le32 leafsize;
  244. __le32 stripesize;
  245. __le32 sys_chunk_array_size;
  246. u8 root_level;
  247. u8 chunk_root_level;
  248. u8 log_root_level;
  249. struct btrfs_dev_item dev_item;
  250. char label[BTRFS_LABEL_SIZE];
  251. u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
  252. } __attribute__ ((__packed__));
  253. /*
  254. * A leaf is full of items. offset and size tell us where to find
  255. * the item in the leaf (relative to the start of the data area)
  256. */
  257. struct btrfs_item {
  258. struct btrfs_disk_key key;
  259. __le32 offset;
  260. __le32 size;
  261. } __attribute__ ((__packed__));
  262. /*
  263. * leaves have an item area and a data area:
  264. * [item0, item1....itemN] [free space] [dataN...data1, data0]
  265. *
  266. * The data is separate from the items to get the keys closer together
  267. * during searches.
  268. */
  269. struct btrfs_leaf {
  270. struct btrfs_header header;
  271. struct btrfs_item items[];
  272. } __attribute__ ((__packed__));
  273. /*
  274. * all non-leaf blocks are nodes, they hold only keys and pointers to
  275. * other blocks
  276. */
  277. struct btrfs_key_ptr {
  278. struct btrfs_disk_key key;
  279. __le64 blockptr;
  280. __le64 generation;
  281. } __attribute__ ((__packed__));
  282. struct btrfs_node {
  283. struct btrfs_header header;
  284. struct btrfs_key_ptr ptrs[];
  285. } __attribute__ ((__packed__));
  286. /*
  287. * btrfs_paths remember the path taken from the root down to the leaf.
  288. * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
  289. * to any other levels that are present.
  290. *
  291. * The slots array records the index of the item or block pointer
  292. * used while walking the tree.
  293. */
  294. struct btrfs_path {
  295. struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
  296. int slots[BTRFS_MAX_LEVEL];
  297. /* if there is real range locking, this locks field will change */
  298. int locks[BTRFS_MAX_LEVEL];
  299. int reada;
  300. /* keep some upper locks as we walk down */
  301. int keep_locks;
  302. int skip_locking;
  303. int lowest_level;
  304. };
  305. /*
  306. * items in the extent btree are used to record the objectid of the
  307. * owner of the block and the number of references
  308. */
  309. struct btrfs_extent_item {
  310. __le32 refs;
  311. } __attribute__ ((__packed__));
  312. struct btrfs_extent_ref {
  313. __le64 root;
  314. __le64 generation;
  315. __le64 objectid;
  316. __le64 offset;
  317. __le32 num_refs;
  318. } __attribute__ ((__packed__));
  319. /* dev extents record free space on individual devices. The owner
  320. * field points back to the chunk allocation mapping tree that allocated
  321. * the extent. The chunk tree uuid field is a way to double check the owner
  322. */
  323. struct btrfs_dev_extent {
  324. __le64 chunk_tree;
  325. __le64 chunk_objectid;
  326. __le64 chunk_offset;
  327. __le64 length;
  328. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  329. } __attribute__ ((__packed__));
  330. struct btrfs_inode_ref {
  331. __le64 index;
  332. __le16 name_len;
  333. /* name goes here */
  334. } __attribute__ ((__packed__));
  335. struct btrfs_timespec {
  336. __le64 sec;
  337. __le32 nsec;
  338. } __attribute__ ((__packed__));
  339. /*
  340. * there is no padding here on purpose. If you want to extent the inode,
  341. * make a new item type
  342. */
  343. struct btrfs_inode_item {
  344. /* nfs style generation number */
  345. __le64 generation;
  346. /* transid that last touched this inode */
  347. __le64 transid;
  348. __le64 size;
  349. __le64 nblocks;
  350. __le64 block_group;
  351. __le32 nlink;
  352. __le32 uid;
  353. __le32 gid;
  354. __le32 mode;
  355. __le64 rdev;
  356. __le16 flags;
  357. __le16 compat_flags;
  358. struct btrfs_timespec atime;
  359. struct btrfs_timespec ctime;
  360. struct btrfs_timespec mtime;
  361. struct btrfs_timespec otime;
  362. } __attribute__ ((__packed__));
  363. struct btrfs_dir_log_item {
  364. __le64 end;
  365. } __attribute__ ((__packed__));
  366. struct btrfs_dir_item {
  367. struct btrfs_disk_key location;
  368. __le64 transid;
  369. __le16 data_len;
  370. __le16 name_len;
  371. u8 type;
  372. } __attribute__ ((__packed__));
  373. struct btrfs_root_item {
  374. struct btrfs_inode_item inode;
  375. __le64 root_dirid;
  376. __le64 bytenr;
  377. __le64 byte_limit;
  378. __le64 bytes_used;
  379. __le32 flags;
  380. __le32 refs;
  381. struct btrfs_disk_key drop_progress;
  382. u8 drop_level;
  383. u8 level;
  384. } __attribute__ ((__packed__));
  385. #define BTRFS_FILE_EXTENT_REG 0
  386. #define BTRFS_FILE_EXTENT_INLINE 1
  387. struct btrfs_file_extent_item {
  388. __le64 generation;
  389. u8 type;
  390. /*
  391. * disk space consumed by the extent, checksum blocks are included
  392. * in these numbers
  393. */
  394. __le64 disk_bytenr;
  395. __le64 disk_num_bytes;
  396. /*
  397. * the logical offset in file blocks (no csums)
  398. * this extent record is for. This allows a file extent to point
  399. * into the middle of an existing extent on disk, sharing it
  400. * between two snapshots (useful if some bytes in the middle of the
  401. * extent have changed
  402. */
  403. __le64 offset;
  404. /*
  405. * the logical number of file blocks (no csums included)
  406. */
  407. __le64 num_bytes;
  408. } __attribute__ ((__packed__));
  409. struct btrfs_csum_item {
  410. u8 csum;
  411. } __attribute__ ((__packed__));
  412. /* different types of block groups (and chunks) */
  413. #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
  414. #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
  415. #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
  416. #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
  417. #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
  418. #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
  419. #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
  420. struct btrfs_block_group_item {
  421. __le64 used;
  422. __le64 chunk_objectid;
  423. __le64 flags;
  424. } __attribute__ ((__packed__));
  425. struct btrfs_space_info {
  426. u64 flags;
  427. u64 total_bytes;
  428. u64 bytes_used;
  429. u64 bytes_pinned;
  430. u64 bytes_reserved;
  431. int full;
  432. int force_alloc;
  433. struct list_head list;
  434. /* for block groups in our same type */
  435. struct list_head block_groups;
  436. spinlock_t lock;
  437. };
  438. struct btrfs_free_space {
  439. struct rb_node bytes_index;
  440. struct rb_node offset_index;
  441. u64 offset;
  442. u64 bytes;
  443. };
  444. struct btrfs_block_group_cache {
  445. struct btrfs_key key;
  446. struct btrfs_block_group_item item;
  447. spinlock_t lock;
  448. u64 pinned;
  449. u64 reserved;
  450. u64 flags;
  451. int cached;
  452. int ro;
  453. int dirty;
  454. struct btrfs_space_info *space_info;
  455. /* free space cache stuff */
  456. struct rb_root free_space_bytes;
  457. struct rb_root free_space_offset;
  458. /* block group cache stuff */
  459. struct rb_node cache_node;
  460. /* for block groups in the same raid type */
  461. struct list_head list;
  462. };
  463. struct btrfs_leaf_ref_tree {
  464. struct rb_root root;
  465. struct list_head list;
  466. spinlock_t lock;
  467. };
  468. struct btrfs_device;
  469. struct btrfs_fs_devices;
  470. struct btrfs_fs_info {
  471. u8 fsid[BTRFS_FSID_SIZE];
  472. u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
  473. struct btrfs_root *extent_root;
  474. struct btrfs_root *tree_root;
  475. struct btrfs_root *chunk_root;
  476. struct btrfs_root *dev_root;
  477. /* the log root tree is a directory of all the other log roots */
  478. struct btrfs_root *log_root_tree;
  479. struct radix_tree_root fs_roots_radix;
  480. /* block group cache stuff */
  481. spinlock_t block_group_cache_lock;
  482. struct rb_root block_group_cache_tree;
  483. struct extent_io_tree pinned_extents;
  484. struct extent_io_tree pending_del;
  485. struct extent_io_tree extent_ins;
  486. /* logical->physical extent mapping */
  487. struct btrfs_mapping_tree mapping_tree;
  488. u64 generation;
  489. u64 last_trans_committed;
  490. u64 last_trans_new_blockgroup;
  491. u64 open_ioctl_trans;
  492. unsigned long mount_opt;
  493. u64 max_extent;
  494. u64 max_inline;
  495. u64 alloc_start;
  496. struct btrfs_transaction *running_transaction;
  497. wait_queue_head_t transaction_throttle;
  498. wait_queue_head_t transaction_wait;
  499. wait_queue_head_t async_submit_wait;
  500. wait_queue_head_t tree_log_wait;
  501. struct btrfs_super_block super_copy;
  502. struct btrfs_super_block super_for_commit;
  503. struct block_device *__bdev;
  504. struct super_block *sb;
  505. struct inode *btree_inode;
  506. struct backing_dev_info bdi;
  507. spinlock_t hash_lock;
  508. struct mutex trans_mutex;
  509. struct mutex tree_log_mutex;
  510. struct mutex transaction_kthread_mutex;
  511. struct mutex cleaner_mutex;
  512. struct mutex alloc_mutex;
  513. struct mutex chunk_mutex;
  514. struct mutex drop_mutex;
  515. struct mutex volume_mutex;
  516. struct mutex tree_reloc_mutex;
  517. struct list_head trans_list;
  518. struct list_head hashers;
  519. struct list_head dead_roots;
  520. atomic_t nr_async_submits;
  521. atomic_t async_submit_draining;
  522. atomic_t nr_async_bios;
  523. atomic_t tree_log_writers;
  524. atomic_t tree_log_commit;
  525. unsigned long tree_log_batch;
  526. u64 tree_log_transid;
  527. /*
  528. * this is used by the balancing code to wait for all the pending
  529. * ordered extents
  530. */
  531. spinlock_t ordered_extent_lock;
  532. struct list_head ordered_extents;
  533. struct list_head delalloc_inodes;
  534. /*
  535. * there is a pool of worker threads for checksumming during writes
  536. * and a pool for checksumming after reads. This is because readers
  537. * can run with FS locks held, and the writers may be waiting for
  538. * those locks. We don't want ordering in the pending list to cause
  539. * deadlocks, and so the two are serviced separately.
  540. *
  541. * A third pool does submit_bio to avoid deadlocking with the other
  542. * two
  543. */
  544. struct btrfs_workers workers;
  545. struct btrfs_workers endio_workers;
  546. struct btrfs_workers endio_write_workers;
  547. struct btrfs_workers submit_workers;
  548. /*
  549. * fixup workers take dirty pages that didn't properly go through
  550. * the cow mechanism and make them safe to write. It happens
  551. * for the sys_munmap function call path
  552. */
  553. struct btrfs_workers fixup_workers;
  554. struct task_struct *transaction_kthread;
  555. struct task_struct *cleaner_kthread;
  556. int thread_pool_size;
  557. /* tree relocation relocated fields */
  558. struct extent_io_tree reloc_mapping_tree;
  559. struct list_head dead_reloc_roots;
  560. struct btrfs_leaf_ref_tree reloc_ref_tree;
  561. struct btrfs_leaf_ref_tree shared_ref_tree;
  562. struct kobject super_kobj;
  563. struct completion kobj_unregister;
  564. int do_barriers;
  565. int closing;
  566. int log_root_recovering;
  567. atomic_t throttles;
  568. atomic_t throttle_gen;
  569. u64 total_pinned;
  570. struct list_head dirty_cowonly_roots;
  571. struct btrfs_fs_devices *fs_devices;
  572. struct list_head space_info;
  573. spinlock_t delalloc_lock;
  574. spinlock_t new_trans_lock;
  575. u64 delalloc_bytes;
  576. u64 last_alloc;
  577. u64 last_data_alloc;
  578. u64 last_log_alloc;
  579. spinlock_t ref_cache_lock;
  580. u64 total_ref_cache_size;
  581. u64 avail_data_alloc_bits;
  582. u64 avail_metadata_alloc_bits;
  583. u64 avail_system_alloc_bits;
  584. u64 data_alloc_profile;
  585. u64 metadata_alloc_profile;
  586. u64 system_alloc_profile;
  587. void *bdev_holder;
  588. };
  589. /*
  590. * in ram representation of the tree. extent_root is used for all allocations
  591. * and for the extent tree extent_root root.
  592. */
  593. struct btrfs_dirty_root;
  594. struct btrfs_root {
  595. struct extent_buffer *node;
  596. /* the node lock is held while changing the node pointer */
  597. spinlock_t node_lock;
  598. struct extent_buffer *commit_root;
  599. struct btrfs_leaf_ref_tree *ref_tree;
  600. struct btrfs_leaf_ref_tree ref_tree_struct;
  601. struct btrfs_dirty_root *dirty_root;
  602. struct btrfs_root *log_root;
  603. struct btrfs_root *reloc_root;
  604. struct btrfs_root_item root_item;
  605. struct btrfs_key root_key;
  606. struct btrfs_fs_info *fs_info;
  607. struct inode *inode;
  608. struct extent_io_tree dirty_log_pages;
  609. struct kobject root_kobj;
  610. struct completion kobj_unregister;
  611. struct mutex objectid_mutex;
  612. struct mutex log_mutex;
  613. u64 objectid;
  614. u64 last_trans;
  615. /* data allocations are done in sectorsize units */
  616. u32 sectorsize;
  617. /* node allocations are done in nodesize units */
  618. u32 nodesize;
  619. /* leaf allocations are done in leafsize units */
  620. u32 leafsize;
  621. u32 stripesize;
  622. u32 type;
  623. u64 highest_inode;
  624. u64 last_inode_alloc;
  625. int ref_cows;
  626. int track_dirty;
  627. u64 defrag_trans_start;
  628. struct btrfs_key defrag_progress;
  629. struct btrfs_key defrag_max;
  630. int defrag_running;
  631. int defrag_level;
  632. char *name;
  633. int in_sysfs;
  634. /* the dirty list is only used by non-reference counted roots */
  635. struct list_head dirty_list;
  636. spinlock_t list_lock;
  637. struct list_head dead_list;
  638. struct list_head orphan_list;
  639. };
  640. /*
  641. * inode items have the data typically returned from stat and store other
  642. * info about object characteristics. There is one for every file and dir in
  643. * the FS
  644. */
  645. #define BTRFS_INODE_ITEM_KEY 1
  646. #define BTRFS_INODE_REF_KEY 2
  647. #define BTRFS_XATTR_ITEM_KEY 8
  648. #define BTRFS_ORPHAN_ITEM_KEY 9
  649. /* reserve 2-15 close to the inode for later flexibility */
  650. /*
  651. * dir items are the name -> inode pointers in a directory. There is one
  652. * for every name in a directory.
  653. */
  654. #define BTRFS_DIR_LOG_ITEM_KEY 14
  655. #define BTRFS_DIR_LOG_INDEX_KEY 15
  656. #define BTRFS_DIR_ITEM_KEY 16
  657. #define BTRFS_DIR_INDEX_KEY 17
  658. /*
  659. * extent data is for file data
  660. */
  661. #define BTRFS_EXTENT_DATA_KEY 18
  662. /*
  663. * csum items have the checksums for data in the extents
  664. */
  665. #define BTRFS_CSUM_ITEM_KEY 19
  666. /* reserve 21-31 for other file/dir stuff */
  667. /*
  668. * root items point to tree roots. There are typically in the root
  669. * tree used by the super block to find all the other trees
  670. */
  671. #define BTRFS_ROOT_ITEM_KEY 32
  672. /*
  673. * extent items are in the extent map tree. These record which blocks
  674. * are used, and how many references there are to each block
  675. */
  676. #define BTRFS_EXTENT_ITEM_KEY 33
  677. #define BTRFS_EXTENT_REF_KEY 34
  678. /*
  679. * block groups give us hints into the extent allocation trees. Which
  680. * blocks are free etc etc
  681. */
  682. #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
  683. #define BTRFS_DEV_EXTENT_KEY 75
  684. #define BTRFS_DEV_ITEM_KEY 76
  685. #define BTRFS_CHUNK_ITEM_KEY 77
  686. /*
  687. * string items are for debugging. They just store a short string of
  688. * data in the FS
  689. */
  690. #define BTRFS_STRING_ITEM_KEY 253
  691. #define BTRFS_MOUNT_NODATASUM (1 << 0)
  692. #define BTRFS_MOUNT_NODATACOW (1 << 1)
  693. #define BTRFS_MOUNT_NOBARRIER (1 << 2)
  694. #define BTRFS_MOUNT_SSD (1 << 3)
  695. #define BTRFS_MOUNT_DEGRADED (1 << 4)
  696. #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
  697. #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
  698. #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
  699. BTRFS_MOUNT_##opt)
  700. /*
  701. * Inode flags
  702. */
  703. #define BTRFS_INODE_NODATASUM (1 << 0)
  704. #define BTRFS_INODE_NODATACOW (1 << 1)
  705. #define BTRFS_INODE_READONLY (1 << 2)
  706. #define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \
  707. ~BTRFS_INODE_##flag)
  708. #define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \
  709. BTRFS_INODE_##flag)
  710. #define btrfs_test_flag(inode, flag) (BTRFS_I(inode)->flags & \
  711. BTRFS_INODE_##flag)
  712. /* some macros to generate set/get funcs for the struct fields. This
  713. * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  714. * one for u8:
  715. */
  716. #define le8_to_cpu(v) (v)
  717. #define cpu_to_le8(v) (v)
  718. #define __le8 u8
  719. #define read_eb_member(eb, ptr, type, member, result) ( \
  720. read_extent_buffer(eb, (char *)(result), \
  721. ((unsigned long)(ptr)) + \
  722. offsetof(type, member), \
  723. sizeof(((type *)0)->member)))
  724. #define write_eb_member(eb, ptr, type, member, result) ( \
  725. write_extent_buffer(eb, (char *)(result), \
  726. ((unsigned long)(ptr)) + \
  727. offsetof(type, member), \
  728. sizeof(((type *)0)->member)))
  729. #ifndef BTRFS_SETGET_FUNCS
  730. #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
  731. u##bits btrfs_##name(struct extent_buffer *eb, type *s); \
  732. void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val);
  733. #endif
  734. #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
  735. static inline u##bits btrfs_##name(struct extent_buffer *eb) \
  736. { \
  737. type *p = kmap_atomic(eb->first_page, KM_USER0); \
  738. u##bits res = le##bits##_to_cpu(p->member); \
  739. kunmap_atomic(p, KM_USER0); \
  740. return res; \
  741. } \
  742. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  743. u##bits val) \
  744. { \
  745. type *p = kmap_atomic(eb->first_page, KM_USER0); \
  746. p->member = cpu_to_le##bits(val); \
  747. kunmap_atomic(p, KM_USER0); \
  748. }
  749. #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
  750. static inline u##bits btrfs_##name(type *s) \
  751. { \
  752. return le##bits##_to_cpu(s->member); \
  753. } \
  754. static inline void btrfs_set_##name(type *s, u##bits val) \
  755. { \
  756. s->member = cpu_to_le##bits(val); \
  757. }
  758. BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
  759. BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
  760. BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
  761. BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
  762. BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
  763. BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
  764. BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
  765. BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
  766. BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
  767. BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
  768. BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
  769. BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
  770. total_bytes, 64);
  771. BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
  772. bytes_used, 64);
  773. BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
  774. io_align, 32);
  775. BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
  776. io_width, 32);
  777. BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
  778. sector_size, 32);
  779. BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
  780. BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
  781. dev_group, 32);
  782. BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
  783. seek_speed, 8);
  784. BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
  785. bandwidth, 8);
  786. static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
  787. {
  788. return (char *)d + offsetof(struct btrfs_dev_item, uuid);
  789. }
  790. BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
  791. BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
  792. BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
  793. BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
  794. BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
  795. BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
  796. BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
  797. BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
  798. BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
  799. BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
  800. BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
  801. static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
  802. {
  803. return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
  804. }
  805. BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
  806. BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
  807. BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
  808. stripe_len, 64);
  809. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
  810. io_align, 32);
  811. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
  812. io_width, 32);
  813. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
  814. sector_size, 32);
  815. BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
  816. BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
  817. num_stripes, 16);
  818. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
  819. sub_stripes, 16);
  820. BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
  821. BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
  822. static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
  823. int nr)
  824. {
  825. unsigned long offset = (unsigned long)c;
  826. offset += offsetof(struct btrfs_chunk, stripe);
  827. offset += nr * sizeof(struct btrfs_stripe);
  828. return (struct btrfs_stripe *)offset;
  829. }
  830. static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
  831. {
  832. return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
  833. }
  834. static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
  835. struct btrfs_chunk *c, int nr)
  836. {
  837. return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
  838. }
  839. static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
  840. struct btrfs_chunk *c, int nr,
  841. u64 val)
  842. {
  843. btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
  844. }
  845. static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
  846. struct btrfs_chunk *c, int nr)
  847. {
  848. return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
  849. }
  850. static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
  851. struct btrfs_chunk *c, int nr,
  852. u64 val)
  853. {
  854. btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
  855. }
  856. /* struct btrfs_block_group_item */
  857. BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
  858. used, 64);
  859. BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
  860. used, 64);
  861. BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
  862. struct btrfs_block_group_item, chunk_objectid, 64);
  863. BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
  864. struct btrfs_block_group_item, chunk_objectid, 64);
  865. BTRFS_SETGET_FUNCS(disk_block_group_flags,
  866. struct btrfs_block_group_item, flags, 64);
  867. BTRFS_SETGET_STACK_FUNCS(block_group_flags,
  868. struct btrfs_block_group_item, flags, 64);
  869. /* struct btrfs_inode_ref */
  870. BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
  871. BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
  872. /* struct btrfs_inode_item */
  873. BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
  874. BTRFS_SETGET_FUNCS(inode_transid, struct btrfs_inode_item, transid, 64);
  875. BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
  876. BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
  877. BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
  878. BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
  879. BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
  880. BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
  881. BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
  882. BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
  883. BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
  884. BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
  885. compat_flags, 16);
  886. static inline struct btrfs_timespec *
  887. btrfs_inode_atime(struct btrfs_inode_item *inode_item)
  888. {
  889. unsigned long ptr = (unsigned long)inode_item;
  890. ptr += offsetof(struct btrfs_inode_item, atime);
  891. return (struct btrfs_timespec *)ptr;
  892. }
  893. static inline struct btrfs_timespec *
  894. btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
  895. {
  896. unsigned long ptr = (unsigned long)inode_item;
  897. ptr += offsetof(struct btrfs_inode_item, mtime);
  898. return (struct btrfs_timespec *)ptr;
  899. }
  900. static inline struct btrfs_timespec *
  901. btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
  902. {
  903. unsigned long ptr = (unsigned long)inode_item;
  904. ptr += offsetof(struct btrfs_inode_item, ctime);
  905. return (struct btrfs_timespec *)ptr;
  906. }
  907. static inline struct btrfs_timespec *
  908. btrfs_inode_otime(struct btrfs_inode_item *inode_item)
  909. {
  910. unsigned long ptr = (unsigned long)inode_item;
  911. ptr += offsetof(struct btrfs_inode_item, otime);
  912. return (struct btrfs_timespec *)ptr;
  913. }
  914. BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
  915. BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
  916. /* struct btrfs_dev_extent */
  917. BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
  918. chunk_tree, 64);
  919. BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
  920. chunk_objectid, 64);
  921. BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
  922. chunk_offset, 64);
  923. BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
  924. static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
  925. {
  926. unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
  927. return (u8 *)((unsigned long)dev + ptr);
  928. }
  929. /* struct btrfs_extent_ref */
  930. BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
  931. BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
  932. BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
  933. BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
  934. BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
  935. BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
  936. BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
  937. generation, 64);
  938. BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
  939. objectid, 64);
  940. BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref,
  941. offset, 64);
  942. BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
  943. num_refs, 32);
  944. /* struct btrfs_extent_item */
  945. BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
  946. BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
  947. refs, 32);
  948. /* struct btrfs_node */
  949. BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
  950. BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
  951. static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
  952. {
  953. unsigned long ptr;
  954. ptr = offsetof(struct btrfs_node, ptrs) +
  955. sizeof(struct btrfs_key_ptr) * nr;
  956. return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
  957. }
  958. static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
  959. int nr, u64 val)
  960. {
  961. unsigned long ptr;
  962. ptr = offsetof(struct btrfs_node, ptrs) +
  963. sizeof(struct btrfs_key_ptr) * nr;
  964. btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
  965. }
  966. static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
  967. {
  968. unsigned long ptr;
  969. ptr = offsetof(struct btrfs_node, ptrs) +
  970. sizeof(struct btrfs_key_ptr) * nr;
  971. return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
  972. }
  973. static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
  974. int nr, u64 val)
  975. {
  976. unsigned long ptr;
  977. ptr = offsetof(struct btrfs_node, ptrs) +
  978. sizeof(struct btrfs_key_ptr) * nr;
  979. btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
  980. }
  981. static inline unsigned long btrfs_node_key_ptr_offset(int nr)
  982. {
  983. return offsetof(struct btrfs_node, ptrs) +
  984. sizeof(struct btrfs_key_ptr) * nr;
  985. }
  986. void btrfs_node_key(struct extent_buffer *eb,
  987. struct btrfs_disk_key *disk_key, int nr);
  988. static inline void btrfs_set_node_key(struct extent_buffer *eb,
  989. struct btrfs_disk_key *disk_key, int nr)
  990. {
  991. unsigned long ptr;
  992. ptr = btrfs_node_key_ptr_offset(nr);
  993. write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  994. struct btrfs_key_ptr, key, disk_key);
  995. }
  996. /* struct btrfs_item */
  997. BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
  998. BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
  999. static inline unsigned long btrfs_item_nr_offset(int nr)
  1000. {
  1001. return offsetof(struct btrfs_leaf, items) +
  1002. sizeof(struct btrfs_item) * nr;
  1003. }
  1004. static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
  1005. int nr)
  1006. {
  1007. return (struct btrfs_item *)btrfs_item_nr_offset(nr);
  1008. }
  1009. static inline u32 btrfs_item_end(struct extent_buffer *eb,
  1010. struct btrfs_item *item)
  1011. {
  1012. return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
  1013. }
  1014. static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
  1015. {
  1016. return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
  1017. }
  1018. static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
  1019. {
  1020. return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
  1021. }
  1022. static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
  1023. {
  1024. return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
  1025. }
  1026. static inline void btrfs_item_key(struct extent_buffer *eb,
  1027. struct btrfs_disk_key *disk_key, int nr)
  1028. {
  1029. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  1030. read_eb_member(eb, item, struct btrfs_item, key, disk_key);
  1031. }
  1032. static inline void btrfs_set_item_key(struct extent_buffer *eb,
  1033. struct btrfs_disk_key *disk_key, int nr)
  1034. {
  1035. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  1036. write_eb_member(eb, item, struct btrfs_item, key, disk_key);
  1037. }
  1038. BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
  1039. /* struct btrfs_dir_item */
  1040. BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
  1041. BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
  1042. BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
  1043. BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
  1044. static inline void btrfs_dir_item_key(struct extent_buffer *eb,
  1045. struct btrfs_dir_item *item,
  1046. struct btrfs_disk_key *key)
  1047. {
  1048. read_eb_member(eb, item, struct btrfs_dir_item, location, key);
  1049. }
  1050. static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
  1051. struct btrfs_dir_item *item,
  1052. struct btrfs_disk_key *key)
  1053. {
  1054. write_eb_member(eb, item, struct btrfs_dir_item, location, key);
  1055. }
  1056. /* struct btrfs_disk_key */
  1057. BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
  1058. objectid, 64);
  1059. BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
  1060. BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
  1061. static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
  1062. struct btrfs_disk_key *disk)
  1063. {
  1064. cpu->offset = le64_to_cpu(disk->offset);
  1065. cpu->type = disk->type;
  1066. cpu->objectid = le64_to_cpu(disk->objectid);
  1067. }
  1068. static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
  1069. struct btrfs_key *cpu)
  1070. {
  1071. disk->offset = cpu_to_le64(cpu->offset);
  1072. disk->type = cpu->type;
  1073. disk->objectid = cpu_to_le64(cpu->objectid);
  1074. }
  1075. static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
  1076. struct btrfs_key *key, int nr)
  1077. {
  1078. struct btrfs_disk_key disk_key;
  1079. btrfs_node_key(eb, &disk_key, nr);
  1080. btrfs_disk_key_to_cpu(key, &disk_key);
  1081. }
  1082. static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
  1083. struct btrfs_key *key, int nr)
  1084. {
  1085. struct btrfs_disk_key disk_key;
  1086. btrfs_item_key(eb, &disk_key, nr);
  1087. btrfs_disk_key_to_cpu(key, &disk_key);
  1088. }
  1089. static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
  1090. struct btrfs_dir_item *item,
  1091. struct btrfs_key *key)
  1092. {
  1093. struct btrfs_disk_key disk_key;
  1094. btrfs_dir_item_key(eb, item, &disk_key);
  1095. btrfs_disk_key_to_cpu(key, &disk_key);
  1096. }
  1097. static inline u8 btrfs_key_type(struct btrfs_key *key)
  1098. {
  1099. return key->type;
  1100. }
  1101. static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
  1102. {
  1103. key->type = val;
  1104. }
  1105. /* struct btrfs_header */
  1106. BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
  1107. BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
  1108. generation, 64);
  1109. BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
  1110. BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
  1111. BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
  1112. BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
  1113. static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
  1114. {
  1115. return (btrfs_header_flags(eb) & flag) == flag;
  1116. }
  1117. static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
  1118. {
  1119. u64 flags = btrfs_header_flags(eb);
  1120. btrfs_set_header_flags(eb, flags | flag);
  1121. return (flags & flag) == flag;
  1122. }
  1123. static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
  1124. {
  1125. u64 flags = btrfs_header_flags(eb);
  1126. btrfs_set_header_flags(eb, flags & ~flag);
  1127. return (flags & flag) == flag;
  1128. }
  1129. static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
  1130. {
  1131. unsigned long ptr = offsetof(struct btrfs_header, fsid);
  1132. return (u8 *)ptr;
  1133. }
  1134. static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
  1135. {
  1136. unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
  1137. return (u8 *)ptr;
  1138. }
  1139. static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
  1140. {
  1141. unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
  1142. return (u8 *)ptr;
  1143. }
  1144. static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
  1145. {
  1146. unsigned long ptr = offsetof(struct btrfs_header, csum);
  1147. return (u8 *)ptr;
  1148. }
  1149. static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
  1150. {
  1151. return NULL;
  1152. }
  1153. static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
  1154. {
  1155. return NULL;
  1156. }
  1157. static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
  1158. {
  1159. return NULL;
  1160. }
  1161. static inline int btrfs_is_leaf(struct extent_buffer *eb)
  1162. {
  1163. return (btrfs_header_level(eb) == 0);
  1164. }
  1165. /* struct btrfs_root_item */
  1166. BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
  1167. BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
  1168. BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
  1169. BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
  1170. BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
  1171. BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
  1172. BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
  1173. BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
  1174. BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
  1175. BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
  1176. /* struct btrfs_super_block */
  1177. BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
  1178. BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
  1179. BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
  1180. generation, 64);
  1181. BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
  1182. BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
  1183. struct btrfs_super_block, sys_chunk_array_size, 32);
  1184. BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
  1185. root_level, 8);
  1186. BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
  1187. chunk_root, 64);
  1188. BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
  1189. chunk_root_level, 8);
  1190. BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
  1191. log_root, 64);
  1192. BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
  1193. log_root_level, 8);
  1194. BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
  1195. total_bytes, 64);
  1196. BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
  1197. bytes_used, 64);
  1198. BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
  1199. sectorsize, 32);
  1200. BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
  1201. nodesize, 32);
  1202. BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
  1203. leafsize, 32);
  1204. BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
  1205. stripesize, 32);
  1206. BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
  1207. root_dir_objectid, 64);
  1208. BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
  1209. num_devices, 64);
  1210. static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
  1211. {
  1212. return offsetof(struct btrfs_leaf, items);
  1213. }
  1214. /* struct btrfs_file_extent_item */
  1215. BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
  1216. static inline unsigned long btrfs_file_extent_inline_start(struct
  1217. btrfs_file_extent_item *e)
  1218. {
  1219. unsigned long offset = (unsigned long)e;
  1220. offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
  1221. return offset;
  1222. }
  1223. static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
  1224. {
  1225. return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
  1226. }
  1227. static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
  1228. struct btrfs_item *e)
  1229. {
  1230. unsigned long offset;
  1231. offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
  1232. return btrfs_item_size(eb, e) - offset;
  1233. }
  1234. BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
  1235. disk_bytenr, 64);
  1236. BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
  1237. generation, 64);
  1238. BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
  1239. disk_num_bytes, 64);
  1240. BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
  1241. offset, 64);
  1242. BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
  1243. num_bytes, 64);
  1244. static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
  1245. {
  1246. return sb->s_fs_info;
  1247. }
  1248. static inline int btrfs_set_root_name(struct btrfs_root *root,
  1249. const char *name, int len)
  1250. {
  1251. /* if we already have a name just free it */
  1252. if (root->name)
  1253. kfree(root->name);
  1254. root->name = kmalloc(len+1, GFP_KERNEL);
  1255. if (!root->name)
  1256. return -ENOMEM;
  1257. memcpy(root->name, name, len);
  1258. root->name[len] ='\0';
  1259. return 0;
  1260. }
  1261. static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
  1262. if (level == 0)
  1263. return root->leafsize;
  1264. return root->nodesize;
  1265. }
  1266. /* helper function to cast into the data area of the leaf. */
  1267. #define btrfs_item_ptr(leaf, slot, type) \
  1268. ((type *)(btrfs_leaf_data(leaf) + \
  1269. btrfs_item_offset_nr(leaf, slot)))
  1270. #define btrfs_item_ptr_offset(leaf, slot) \
  1271. ((unsigned long)(btrfs_leaf_data(leaf) + \
  1272. btrfs_item_offset_nr(leaf, slot)))
  1273. static inline struct dentry *fdentry(struct file *file)
  1274. {
  1275. return file->f_path.dentry;
  1276. }
  1277. /* extent-tree.c */
  1278. int btrfs_lookup_extent(struct btrfs_root *root, u64 start, u64 len);
  1279. int btrfs_lookup_extent_ref(struct btrfs_trans_handle *trans,
  1280. struct btrfs_root *root, u64 bytenr,
  1281. u64 num_bytes, u32 *refs);
  1282. int btrfs_update_pinned_extents(struct btrfs_root *root,
  1283. u64 bytenr, u64 num, int pin);
  1284. int btrfs_drop_leaf_ref(struct btrfs_trans_handle *trans,
  1285. struct btrfs_root *root, struct extent_buffer *leaf);
  1286. int btrfs_cross_ref_exists(struct btrfs_trans_handle *trans,
  1287. struct btrfs_root *root,
  1288. struct btrfs_key *key, u64 bytenr);
  1289. int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
  1290. struct btrfs_root *root);
  1291. int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
  1292. struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
  1293. btrfs_fs_info *info,
  1294. u64 bytenr);
  1295. struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
  1296. struct btrfs_block_group_cache
  1297. *hint, u64 search_start,
  1298. int data, int owner);
  1299. struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
  1300. struct btrfs_root *root,
  1301. u32 blocksize, u64 parent,
  1302. u64 root_objectid,
  1303. u64 ref_generation,
  1304. int level,
  1305. u64 hint,
  1306. u64 empty_size);
  1307. struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans,
  1308. struct btrfs_root *root,
  1309. u64 bytenr, u32 blocksize);
  1310. int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
  1311. struct btrfs_root *root,
  1312. struct btrfs_path *path,
  1313. u64 bytenr, u64 parent,
  1314. u64 root_objectid, u64 ref_generation,
  1315. u64 owner, u64 owner_offset);
  1316. int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
  1317. struct btrfs_root *root,
  1318. u64 num_bytes, u64 parent, u64 min_bytes,
  1319. u64 root_objectid, u64 ref_generation,
  1320. u64 owner, u64 owner_offset,
  1321. u64 empty_size, u64 hint_byte,
  1322. u64 search_end, struct btrfs_key *ins, u64 data);
  1323. int btrfs_alloc_reserved_extent(struct btrfs_trans_handle *trans,
  1324. struct btrfs_root *root, u64 parent,
  1325. u64 root_objectid, u64 ref_generation,
  1326. u64 owner, u64 owner_offset,
  1327. struct btrfs_key *ins);
  1328. int btrfs_alloc_logged_extent(struct btrfs_trans_handle *trans,
  1329. struct btrfs_root *root, u64 parent,
  1330. u64 root_objectid, u64 ref_generation,
  1331. u64 owner, u64 owner_offset,
  1332. struct btrfs_key *ins);
  1333. int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
  1334. struct btrfs_root *root,
  1335. u64 num_bytes, u64 min_alloc_size,
  1336. u64 empty_size, u64 hint_byte,
  1337. u64 search_end, struct btrfs_key *ins,
  1338. u64 data);
  1339. int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1340. struct extent_buffer *orig_buf, struct extent_buffer *buf,
  1341. u32 *nr_extents);
  1342. int btrfs_cache_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1343. struct extent_buffer *buf, u32 nr_extents);
  1344. int btrfs_update_ref(struct btrfs_trans_handle *trans,
  1345. struct btrfs_root *root, struct extent_buffer *orig_buf,
  1346. struct extent_buffer *buf, int start_slot, int nr);
  1347. int btrfs_free_extent(struct btrfs_trans_handle *trans,
  1348. struct btrfs_root *root,
  1349. u64 bytenr, u64 num_bytes, u64 parent,
  1350. u64 root_objectid, u64 ref_generation,
  1351. u64 owner_objectid, u64 owner_offset, int pin);
  1352. int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len);
  1353. int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
  1354. struct btrfs_root *root,
  1355. struct extent_io_tree *unpin);
  1356. int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
  1357. struct btrfs_root *root,
  1358. u64 bytenr, u64 num_bytes, u64 parent,
  1359. u64 root_objectid, u64 ref_generation,
  1360. u64 owner, u64 owner_offset);
  1361. int btrfs_update_extent_ref(struct btrfs_trans_handle *trans,
  1362. struct btrfs_root *root, u64 bytenr,
  1363. u64 orig_parent, u64 parent,
  1364. u64 root_objectid, u64 ref_generation,
  1365. u64 owner, u64 owner_offset);
  1366. int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
  1367. struct btrfs_root *root);
  1368. int btrfs_free_block_groups(struct btrfs_fs_info *info);
  1369. int btrfs_read_block_groups(struct btrfs_root *root);
  1370. int btrfs_make_block_group(struct btrfs_trans_handle *trans,
  1371. struct btrfs_root *root, u64 bytes_used,
  1372. u64 type, u64 chunk_objectid, u64 chunk_offset,
  1373. u64 size);
  1374. int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
  1375. struct btrfs_root *root, u64 group_start);
  1376. int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start);
  1377. int btrfs_free_reloc_root(struct btrfs_root *root);
  1378. int btrfs_drop_dead_reloc_roots(struct btrfs_root *root);
  1379. int btrfs_add_reloc_mapping(struct btrfs_root *root, u64 orig_bytenr,
  1380. u64 num_bytes, u64 new_bytenr);
  1381. int btrfs_get_reloc_mapping(struct btrfs_root *root, u64 orig_bytenr,
  1382. u64 num_bytes, u64 *new_bytenr);
  1383. void btrfs_free_reloc_mappings(struct btrfs_root *root);
  1384. int btrfs_reloc_tree_cache_ref(struct btrfs_trans_handle *trans,
  1385. struct btrfs_root *root,
  1386. struct extent_buffer *buf, u64 orig_start);
  1387. int btrfs_add_dead_reloc_root(struct btrfs_root *root);
  1388. int btrfs_cleanup_reloc_trees(struct btrfs_root *root);
  1389. /* ctree.c */
  1390. int btrfs_previous_item(struct btrfs_root *root,
  1391. struct btrfs_path *path, u64 min_objectid,
  1392. int type);
  1393. int btrfs_merge_path(struct btrfs_trans_handle *trans,
  1394. struct btrfs_root *root,
  1395. struct btrfs_key *node_keys,
  1396. u64 *nodes, int lowest_level);
  1397. int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
  1398. struct btrfs_root *root, struct btrfs_path *path,
  1399. struct btrfs_key *new_key);
  1400. struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
  1401. struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
  1402. int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
  1403. struct btrfs_key *key, int lowest_level,
  1404. int cache_only, u64 min_trans);
  1405. int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
  1406. struct btrfs_key *max_key,
  1407. struct btrfs_path *path, int cache_only,
  1408. u64 min_trans);
  1409. int btrfs_cow_block(struct btrfs_trans_handle *trans,
  1410. struct btrfs_root *root, struct extent_buffer *buf,
  1411. struct extent_buffer *parent, int parent_slot,
  1412. struct extent_buffer **cow_ret, u64 prealloc_dest);
  1413. int btrfs_copy_root(struct btrfs_trans_handle *trans,
  1414. struct btrfs_root *root,
  1415. struct extent_buffer *buf,
  1416. struct extent_buffer **cow_ret, u64 new_root_objectid);
  1417. int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1418. *root, struct btrfs_path *path, u32 data_size);
  1419. int btrfs_truncate_item(struct btrfs_trans_handle *trans,
  1420. struct btrfs_root *root,
  1421. struct btrfs_path *path,
  1422. u32 new_size, int from_end);
  1423. int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
  1424. *root, struct btrfs_key *key, struct btrfs_path *p, int
  1425. ins_len, int cow);
  1426. int btrfs_realloc_node(struct btrfs_trans_handle *trans,
  1427. struct btrfs_root *root, struct extent_buffer *parent,
  1428. int start_slot, int cache_only, u64 *last_ret,
  1429. struct btrfs_key *progress);
  1430. void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
  1431. struct btrfs_path *btrfs_alloc_path(void);
  1432. void btrfs_free_path(struct btrfs_path *p);
  1433. void btrfs_init_path(struct btrfs_path *p);
  1434. int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1435. struct btrfs_path *path, int slot, int nr);
  1436. int btrfs_del_leaf(struct btrfs_trans_handle *trans,
  1437. struct btrfs_root *root,
  1438. struct btrfs_path *path, u64 bytenr);
  1439. static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
  1440. struct btrfs_root *root,
  1441. struct btrfs_path *path)
  1442. {
  1443. return btrfs_del_items(trans, root, path, path->slots[0], 1);
  1444. }
  1445. int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1446. *root, struct btrfs_key *key, void *data, u32 data_size);
  1447. int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
  1448. struct btrfs_root *root,
  1449. struct btrfs_path *path,
  1450. struct btrfs_key *cpu_key, u32 *data_size, int nr);
  1451. static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
  1452. struct btrfs_root *root,
  1453. struct btrfs_path *path,
  1454. struct btrfs_key *key,
  1455. u32 data_size)
  1456. {
  1457. return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
  1458. }
  1459. int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  1460. int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
  1461. int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
  1462. int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
  1463. *root);
  1464. /* root-item.c */
  1465. int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1466. struct btrfs_key *key);
  1467. int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  1468. *root, struct btrfs_key *key, struct btrfs_root_item
  1469. *item);
  1470. int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
  1471. *root, struct btrfs_key *key, struct btrfs_root_item
  1472. *item);
  1473. int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
  1474. btrfs_root_item *item, struct btrfs_key *key);
  1475. int btrfs_search_root(struct btrfs_root *root, u64 search_start,
  1476. u64 *found_objectid);
  1477. int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
  1478. struct btrfs_root *latest_root);
  1479. /* dir-item.c */
  1480. int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1481. *root, const char *name, int name_len, u64 dir,
  1482. struct btrfs_key *location, u8 type, u64 index);
  1483. struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
  1484. struct btrfs_root *root,
  1485. struct btrfs_path *path, u64 dir,
  1486. const char *name, int name_len,
  1487. int mod);
  1488. struct btrfs_dir_item *
  1489. btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
  1490. struct btrfs_root *root,
  1491. struct btrfs_path *path, u64 dir,
  1492. u64 objectid, const char *name, int name_len,
  1493. int mod);
  1494. struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
  1495. struct btrfs_path *path,
  1496. const char *name, int name_len);
  1497. int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
  1498. struct btrfs_root *root,
  1499. struct btrfs_path *path,
  1500. struct btrfs_dir_item *di);
  1501. int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
  1502. struct btrfs_root *root, const char *name,
  1503. u16 name_len, const void *data, u16 data_len,
  1504. u64 dir);
  1505. struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
  1506. struct btrfs_root *root,
  1507. struct btrfs_path *path, u64 dir,
  1508. const char *name, u16 name_len,
  1509. int mod);
  1510. /* orphan.c */
  1511. int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
  1512. struct btrfs_root *root, u64 offset);
  1513. int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
  1514. struct btrfs_root *root, u64 offset);
  1515. /* inode-map.c */
  1516. int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
  1517. struct btrfs_root *fs_root,
  1518. u64 dirid, u64 *objectid);
  1519. int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
  1520. /* inode-item.c */
  1521. int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
  1522. struct btrfs_root *root,
  1523. const char *name, int name_len,
  1524. u64 inode_objectid, u64 ref_objectid, u64 index);
  1525. int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
  1526. struct btrfs_root *root,
  1527. const char *name, int name_len,
  1528. u64 inode_objectid, u64 ref_objectid, u64 *index);
  1529. int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
  1530. struct btrfs_root *root,
  1531. struct btrfs_path *path, u64 objectid);
  1532. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  1533. *root, struct btrfs_path *path,
  1534. struct btrfs_key *location, int mod);
  1535. /* file-item.c */
  1536. int btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode,
  1537. struct bio *bio);
  1538. int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
  1539. struct btrfs_root *root,
  1540. u64 objectid, u64 pos, u64 disk_offset,
  1541. u64 disk_num_bytes,
  1542. u64 num_bytes, u64 offset);
  1543. int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
  1544. struct btrfs_root *root,
  1545. struct btrfs_path *path, u64 objectid,
  1546. u64 bytenr, int mod);
  1547. int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
  1548. struct btrfs_root *root, struct inode *inode,
  1549. struct btrfs_ordered_sum *sums);
  1550. int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
  1551. struct bio *bio);
  1552. struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
  1553. struct btrfs_root *root,
  1554. struct btrfs_path *path,
  1555. u64 objectid, u64 offset,
  1556. int cow);
  1557. int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
  1558. struct btrfs_root *root, struct btrfs_path *path,
  1559. u64 isize);
  1560. /* inode.c */
  1561. /* RHEL and EL kernels have a patch that renames PG_checked to FsMisc */
  1562. #if defined(ClearPageFsMisc) && !defined(ClearPageChecked)
  1563. #define ClearPageChecked ClearPageFsMisc
  1564. #define SetPageChecked SetPageFsMisc
  1565. #define PageChecked PageFsMisc
  1566. #endif
  1567. int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
  1568. struct btrfs_root *root,
  1569. struct inode *dir, struct inode *inode,
  1570. const char *name, int name_len);
  1571. int btrfs_add_link(struct btrfs_trans_handle *trans,
  1572. struct inode *parent_inode, struct inode *inode,
  1573. const char *name, int name_len, int add_backref, u64 index);
  1574. int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
  1575. struct btrfs_root *root,
  1576. struct inode *inode, u64 new_size,
  1577. u32 min_type);
  1578. int btrfs_start_delalloc_inodes(struct btrfs_root *root);
  1579. int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end);
  1580. int btrfs_writepages(struct address_space *mapping,
  1581. struct writeback_control *wbc);
  1582. int btrfs_create_subvol_root(struct btrfs_root *new_root,
  1583. struct btrfs_trans_handle *trans, u64 new_dirid,
  1584. struct btrfs_block_group_cache *block_group);
  1585. void btrfs_invalidate_dcache_root(struct btrfs_root *root, char *name,
  1586. int namelen);
  1587. int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
  1588. size_t size, struct bio *bio);
  1589. static inline void dec_i_blocks(struct inode *inode, u64 dec)
  1590. {
  1591. dec = dec >> 9;
  1592. if (dec <= inode->i_blocks)
  1593. inode->i_blocks -= dec;
  1594. else
  1595. inode->i_blocks = 0;
  1596. }
  1597. unsigned long btrfs_force_ra(struct address_space *mapping,
  1598. struct file_ra_state *ra, struct file *file,
  1599. pgoff_t offset, pgoff_t last_index);
  1600. int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
  1601. int for_del);
  1602. int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
  1603. int btrfs_readpage(struct file *file, struct page *page);
  1604. void btrfs_delete_inode(struct inode *inode);
  1605. void btrfs_put_inode(struct inode *inode);
  1606. void btrfs_read_locked_inode(struct inode *inode);
  1607. int btrfs_write_inode(struct inode *inode, int wait);
  1608. void btrfs_dirty_inode(struct inode *inode);
  1609. struct inode *btrfs_alloc_inode(struct super_block *sb);
  1610. void btrfs_destroy_inode(struct inode *inode);
  1611. int btrfs_init_cachep(void);
  1612. void btrfs_destroy_cachep(void);
  1613. long btrfs_ioctl_trans_end(struct file *file);
  1614. struct inode *btrfs_ilookup(struct super_block *s, u64 objectid,
  1615. struct btrfs_root *root, int wait);
  1616. struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
  1617. struct btrfs_root *root);
  1618. struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
  1619. struct btrfs_root *root, int *is_new);
  1620. int btrfs_commit_write(struct file *file, struct page *page,
  1621. unsigned from, unsigned to);
  1622. struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
  1623. size_t page_offset, u64 start, u64 end,
  1624. int create);
  1625. int btrfs_update_inode(struct btrfs_trans_handle *trans,
  1626. struct btrfs_root *root,
  1627. struct inode *inode);
  1628. int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode);
  1629. int btrfs_orphan_del(struct btrfs_trans_handle *trans, struct inode *inode);
  1630. void btrfs_orphan_cleanup(struct btrfs_root *root);
  1631. /* ioctl.c */
  1632. long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1633. /* file.c */
  1634. int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
  1635. int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
  1636. int skip_pinned);
  1637. int btrfs_check_file(struct btrfs_root *root, struct inode *inode);
  1638. extern struct file_operations btrfs_file_operations;
  1639. int btrfs_drop_extents(struct btrfs_trans_handle *trans,
  1640. struct btrfs_root *root, struct inode *inode,
  1641. u64 start, u64 end, u64 inline_limit, u64 *hint_block);
  1642. int btrfs_release_file(struct inode *inode, struct file *file);
  1643. /* tree-defrag.c */
  1644. int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
  1645. struct btrfs_root *root, int cache_only);
  1646. /* sysfs.c */
  1647. int btrfs_init_sysfs(void);
  1648. void btrfs_exit_sysfs(void);
  1649. int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
  1650. int btrfs_sysfs_add_root(struct btrfs_root *root);
  1651. void btrfs_sysfs_del_root(struct btrfs_root *root);
  1652. void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
  1653. /* xattr.c */
  1654. ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  1655. /* super.c */
  1656. u64 btrfs_parse_size(char *str);
  1657. int btrfs_parse_options(struct btrfs_root *root, char *options);
  1658. int btrfs_sync_fs(struct super_block *sb, int wait);
  1659. /* acl.c */
  1660. int btrfs_check_acl(struct inode *inode, int mask);
  1661. int btrfs_init_acl(struct inode *inode, struct inode *dir);
  1662. int btrfs_acl_chmod(struct inode *inode);
  1663. /* free-space-cache.c */
  1664. int btrfs_add_free_space(struct btrfs_block_group_cache *block_group,
  1665. u64 bytenr, u64 size);
  1666. int btrfs_remove_free_space(struct btrfs_block_group_cache *block_group,
  1667. u64 bytenr, u64 size);
  1668. void btrfs_remove_free_space_cache(struct btrfs_block_group_cache
  1669. *block_group);
  1670. struct btrfs_free_space *btrfs_find_free_space(struct btrfs_block_group_cache
  1671. *block_group, u64 offset,
  1672. u64 bytes);
  1673. void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
  1674. u64 bytes);
  1675. u64 btrfs_block_group_free_space(struct btrfs_block_group_cache *block_group);
  1676. #endif