ctree.h 55 KB

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