ctree.h 53 KB

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