ctree.h 60 KB

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