ctree.h 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  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. u64 open_ioctl_trans;
  446. unsigned long mount_opt;
  447. u64 max_extent;
  448. u64 max_inline;
  449. u64 alloc_start;
  450. struct btrfs_transaction *running_transaction;
  451. wait_queue_head_t transaction_throttle;
  452. wait_queue_head_t transaction_wait;
  453. struct btrfs_super_block super_copy;
  454. struct btrfs_super_block super_for_commit;
  455. struct block_device *__bdev;
  456. struct super_block *sb;
  457. struct inode *btree_inode;
  458. struct backing_dev_info bdi;
  459. spinlock_t hash_lock;
  460. struct mutex trans_mutex;
  461. struct mutex transaction_kthread_mutex;
  462. struct mutex cleaner_mutex;
  463. struct mutex alloc_mutex;
  464. struct mutex chunk_mutex;
  465. struct mutex drop_mutex;
  466. struct mutex volume_mutex;
  467. struct list_head trans_list;
  468. struct list_head hashers;
  469. struct list_head dead_roots;
  470. atomic_t nr_async_submits;
  471. /*
  472. * this is used by the balancing code to wait for all the pending
  473. * ordered extents
  474. */
  475. spinlock_t ordered_extent_lock;
  476. struct list_head ordered_extents;
  477. struct list_head delalloc_inodes;
  478. /*
  479. * there is a pool of worker threads for checksumming during writes
  480. * and a pool for checksumming after reads. This is because readers
  481. * can run with FS locks held, and the writers may be waiting for
  482. * those locks. We don't want ordering in the pending list to cause
  483. * deadlocks, and so the two are serviced separately.
  484. *
  485. * A third pool does submit_bio to avoid deadlocking with the other
  486. * two
  487. */
  488. struct btrfs_workers workers;
  489. struct btrfs_workers endio_workers;
  490. struct btrfs_workers endio_write_workers;
  491. struct btrfs_workers submit_workers;
  492. /*
  493. * fixup workers take dirty pages that didn't properly go through
  494. * the cow mechanism and make them safe to write. It happens
  495. * for the sys_munmap function call path
  496. */
  497. struct btrfs_workers fixup_workers;
  498. struct task_struct *transaction_kthread;
  499. struct task_struct *cleaner_kthread;
  500. int thread_pool_size;
  501. struct kobject super_kobj;
  502. struct completion kobj_unregister;
  503. int do_barriers;
  504. int closing;
  505. atomic_t throttles;
  506. atomic_t throttle_gen;
  507. u64 total_pinned;
  508. struct list_head dirty_cowonly_roots;
  509. struct btrfs_fs_devices *fs_devices;
  510. struct list_head space_info;
  511. spinlock_t delalloc_lock;
  512. spinlock_t new_trans_lock;
  513. u64 delalloc_bytes;
  514. u64 last_alloc;
  515. u64 last_data_alloc;
  516. spinlock_t ref_cache_lock;
  517. u64 total_ref_cache_size;
  518. u64 avail_data_alloc_bits;
  519. u64 avail_metadata_alloc_bits;
  520. u64 avail_system_alloc_bits;
  521. u64 data_alloc_profile;
  522. u64 metadata_alloc_profile;
  523. u64 system_alloc_profile;
  524. void *bdev_holder;
  525. };
  526. struct btrfs_leaf_ref_tree {
  527. struct rb_root root;
  528. struct btrfs_leaf_ref *last;
  529. struct list_head list;
  530. spinlock_t lock;
  531. };
  532. /*
  533. * in ram representation of the tree. extent_root is used for all allocations
  534. * and for the extent tree extent_root root.
  535. */
  536. struct btrfs_dirty_root;
  537. struct btrfs_root {
  538. struct extent_buffer *node;
  539. /* the node lock is held while changing the node pointer */
  540. spinlock_t node_lock;
  541. struct extent_buffer *commit_root;
  542. struct btrfs_leaf_ref_tree *ref_tree;
  543. struct btrfs_leaf_ref_tree ref_tree_struct;
  544. struct btrfs_dirty_root *dirty_root;
  545. struct btrfs_root_item root_item;
  546. struct btrfs_key root_key;
  547. struct btrfs_fs_info *fs_info;
  548. struct inode *inode;
  549. struct kobject root_kobj;
  550. struct completion kobj_unregister;
  551. struct mutex objectid_mutex;
  552. u64 objectid;
  553. u64 last_trans;
  554. /* data allocations are done in sectorsize units */
  555. u32 sectorsize;
  556. /* node allocations are done in nodesize units */
  557. u32 nodesize;
  558. /* leaf allocations are done in leafsize units */
  559. u32 leafsize;
  560. u32 stripesize;
  561. u32 type;
  562. u64 highest_inode;
  563. u64 last_inode_alloc;
  564. int ref_cows;
  565. int track_dirty;
  566. u64 defrag_trans_start;
  567. struct btrfs_key defrag_progress;
  568. struct btrfs_key defrag_max;
  569. int defrag_running;
  570. int defrag_level;
  571. char *name;
  572. int in_sysfs;
  573. /* the dirty list is only used by non-reference counted roots */
  574. struct list_head dirty_list;
  575. spinlock_t list_lock;
  576. struct list_head dead_list;
  577. struct list_head orphan_list;
  578. };
  579. /*
  580. * inode items have the data typically returned from stat and store other
  581. * info about object characteristics. There is one for every file and dir in
  582. * the FS
  583. */
  584. #define BTRFS_INODE_ITEM_KEY 1
  585. #define BTRFS_INODE_REF_KEY 2
  586. #define BTRFS_XATTR_ITEM_KEY 8
  587. #define BTRFS_ORPHAN_ITEM_KEY 9
  588. /* reserve 2-15 close to the inode for later flexibility */
  589. /*
  590. * dir items are the name -> inode pointers in a directory. There is one
  591. * for every name in a directory.
  592. */
  593. #define BTRFS_DIR_ITEM_KEY 16
  594. #define BTRFS_DIR_INDEX_KEY 17
  595. /*
  596. * extent data is for file data
  597. */
  598. #define BTRFS_EXTENT_DATA_KEY 18
  599. /*
  600. * csum items have the checksums for data in the extents
  601. */
  602. #define BTRFS_CSUM_ITEM_KEY 19
  603. /* reserve 20-31 for other file stuff */
  604. /*
  605. * root items point to tree roots. There are typically in the root
  606. * tree used by the super block to find all the other trees
  607. */
  608. #define BTRFS_ROOT_ITEM_KEY 32
  609. /*
  610. * extent items are in the extent map tree. These record which blocks
  611. * are used, and how many references there are to each block
  612. */
  613. #define BTRFS_EXTENT_ITEM_KEY 33
  614. #define BTRFS_EXTENT_REF_KEY 34
  615. /*
  616. * block groups give us hints into the extent allocation trees. Which
  617. * blocks are free etc etc
  618. */
  619. #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
  620. #define BTRFS_DEV_EXTENT_KEY 75
  621. #define BTRFS_DEV_ITEM_KEY 76
  622. #define BTRFS_CHUNK_ITEM_KEY 77
  623. /*
  624. * string items are for debugging. They just store a short string of
  625. * data in the FS
  626. */
  627. #define BTRFS_STRING_ITEM_KEY 253
  628. #define BTRFS_MOUNT_NODATASUM (1 << 0)
  629. #define BTRFS_MOUNT_NODATACOW (1 << 1)
  630. #define BTRFS_MOUNT_NOBARRIER (1 << 2)
  631. #define BTRFS_MOUNT_SSD (1 << 3)
  632. #define BTRFS_MOUNT_DEGRADED (1 << 4)
  633. #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
  634. #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
  635. #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \
  636. BTRFS_MOUNT_##opt)
  637. /*
  638. * Inode flags
  639. */
  640. #define BTRFS_INODE_NODATASUM (1 << 0)
  641. #define BTRFS_INODE_NODATACOW (1 << 1)
  642. #define BTRFS_INODE_READONLY (1 << 2)
  643. #define btrfs_clear_flag(inode, flag) (BTRFS_I(inode)->flags &= \
  644. ~BTRFS_INODE_##flag)
  645. #define btrfs_set_flag(inode, flag) (BTRFS_I(inode)->flags |= \
  646. BTRFS_INODE_##flag)
  647. #define btrfs_test_flag(inode, flag) (BTRFS_I(inode)->flags & \
  648. BTRFS_INODE_##flag)
  649. /* some macros to generate set/get funcs for the struct fields. This
  650. * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  651. * one for u8:
  652. */
  653. #define le8_to_cpu(v) (v)
  654. #define cpu_to_le8(v) (v)
  655. #define __le8 u8
  656. #define read_eb_member(eb, ptr, type, member, result) ( \
  657. read_extent_buffer(eb, (char *)(result), \
  658. ((unsigned long)(ptr)) + \
  659. offsetof(type, member), \
  660. sizeof(((type *)0)->member)))
  661. #define write_eb_member(eb, ptr, type, member, result) ( \
  662. write_extent_buffer(eb, (char *)(result), \
  663. ((unsigned long)(ptr)) + \
  664. offsetof(type, member), \
  665. sizeof(((type *)0)->member)))
  666. #ifndef BTRFS_SETGET_FUNCS
  667. #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
  668. u##bits btrfs_##name(struct extent_buffer *eb, type *s); \
  669. void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val);
  670. #endif
  671. #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
  672. static inline u##bits btrfs_##name(struct extent_buffer *eb) \
  673. { \
  674. type *p = kmap_atomic(eb->first_page, KM_USER0); \
  675. u##bits res = le##bits##_to_cpu(p->member); \
  676. kunmap_atomic(p, KM_USER0); \
  677. return res; \
  678. } \
  679. static inline void btrfs_set_##name(struct extent_buffer *eb, \
  680. u##bits val) \
  681. { \
  682. type *p = kmap_atomic(eb->first_page, KM_USER0); \
  683. p->member = cpu_to_le##bits(val); \
  684. kunmap_atomic(p, KM_USER0); \
  685. }
  686. #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
  687. static inline u##bits btrfs_##name(type *s) \
  688. { \
  689. return le##bits##_to_cpu(s->member); \
  690. } \
  691. static inline void btrfs_set_##name(type *s, u##bits val) \
  692. { \
  693. s->member = cpu_to_le##bits(val); \
  694. }
  695. BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
  696. BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
  697. BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
  698. BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
  699. BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
  700. BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
  701. BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
  702. BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
  703. BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
  704. BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
  705. BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
  706. BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
  707. total_bytes, 64);
  708. BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
  709. bytes_used, 64);
  710. BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
  711. io_align, 32);
  712. BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
  713. io_width, 32);
  714. BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
  715. sector_size, 32);
  716. BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
  717. BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
  718. dev_group, 32);
  719. BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
  720. seek_speed, 8);
  721. BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
  722. bandwidth, 8);
  723. static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
  724. {
  725. return (char *)d + offsetof(struct btrfs_dev_item, uuid);
  726. }
  727. BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
  728. BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
  729. BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
  730. BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
  731. BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
  732. BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
  733. BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
  734. BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
  735. BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
  736. BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
  737. BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
  738. static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
  739. {
  740. return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
  741. }
  742. BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
  743. BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
  744. BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
  745. stripe_len, 64);
  746. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
  747. io_align, 32);
  748. BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
  749. io_width, 32);
  750. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
  751. sector_size, 32);
  752. BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
  753. BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
  754. num_stripes, 16);
  755. BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
  756. sub_stripes, 16);
  757. BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
  758. BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
  759. static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
  760. int nr)
  761. {
  762. unsigned long offset = (unsigned long)c;
  763. offset += offsetof(struct btrfs_chunk, stripe);
  764. offset += nr * sizeof(struct btrfs_stripe);
  765. return (struct btrfs_stripe *)offset;
  766. }
  767. static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
  768. {
  769. return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
  770. }
  771. static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
  772. struct btrfs_chunk *c, int nr)
  773. {
  774. return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
  775. }
  776. static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
  777. struct btrfs_chunk *c, int nr,
  778. u64 val)
  779. {
  780. btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
  781. }
  782. static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
  783. struct btrfs_chunk *c, int nr)
  784. {
  785. return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
  786. }
  787. static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
  788. struct btrfs_chunk *c, int nr,
  789. u64 val)
  790. {
  791. btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
  792. }
  793. /* struct btrfs_block_group_item */
  794. BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
  795. used, 64);
  796. BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
  797. used, 64);
  798. BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
  799. struct btrfs_block_group_item, chunk_objectid, 64);
  800. BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
  801. struct btrfs_block_group_item, chunk_objectid, 64);
  802. BTRFS_SETGET_FUNCS(disk_block_group_flags,
  803. struct btrfs_block_group_item, flags, 64);
  804. BTRFS_SETGET_STACK_FUNCS(block_group_flags,
  805. struct btrfs_block_group_item, flags, 64);
  806. /* struct btrfs_inode_ref */
  807. BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
  808. BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64);
  809. /* struct btrfs_inode_item */
  810. BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
  811. BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
  812. BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
  813. BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
  814. BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
  815. BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
  816. BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
  817. BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
  818. BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
  819. BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
  820. BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
  821. compat_flags, 16);
  822. static inline struct btrfs_timespec *
  823. btrfs_inode_atime(struct btrfs_inode_item *inode_item)
  824. {
  825. unsigned long ptr = (unsigned long)inode_item;
  826. ptr += offsetof(struct btrfs_inode_item, atime);
  827. return (struct btrfs_timespec *)ptr;
  828. }
  829. static inline struct btrfs_timespec *
  830. btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
  831. {
  832. unsigned long ptr = (unsigned long)inode_item;
  833. ptr += offsetof(struct btrfs_inode_item, mtime);
  834. return (struct btrfs_timespec *)ptr;
  835. }
  836. static inline struct btrfs_timespec *
  837. btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
  838. {
  839. unsigned long ptr = (unsigned long)inode_item;
  840. ptr += offsetof(struct btrfs_inode_item, ctime);
  841. return (struct btrfs_timespec *)ptr;
  842. }
  843. static inline struct btrfs_timespec *
  844. btrfs_inode_otime(struct btrfs_inode_item *inode_item)
  845. {
  846. unsigned long ptr = (unsigned long)inode_item;
  847. ptr += offsetof(struct btrfs_inode_item, otime);
  848. return (struct btrfs_timespec *)ptr;
  849. }
  850. BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
  851. BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
  852. /* struct btrfs_extent_item */
  853. BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
  854. /* struct btrfs_dev_extent */
  855. BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
  856. chunk_tree, 64);
  857. BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
  858. chunk_objectid, 64);
  859. BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
  860. chunk_offset, 64);
  861. BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
  862. static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
  863. {
  864. unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
  865. return (u8 *)((unsigned long)dev + ptr);
  866. }
  867. /* struct btrfs_extent_ref */
  868. BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
  869. BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
  870. BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
  871. BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
  872. BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
  873. BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
  874. generation, 64);
  875. BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
  876. objectid, 64);
  877. BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64);
  878. BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
  879. refs, 32);
  880. /* struct btrfs_node */
  881. BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
  882. BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
  883. static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
  884. {
  885. unsigned long ptr;
  886. ptr = offsetof(struct btrfs_node, ptrs) +
  887. sizeof(struct btrfs_key_ptr) * nr;
  888. return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
  889. }
  890. static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
  891. int nr, u64 val)
  892. {
  893. unsigned long ptr;
  894. ptr = offsetof(struct btrfs_node, ptrs) +
  895. sizeof(struct btrfs_key_ptr) * nr;
  896. btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
  897. }
  898. static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
  899. {
  900. unsigned long ptr;
  901. ptr = offsetof(struct btrfs_node, ptrs) +
  902. sizeof(struct btrfs_key_ptr) * nr;
  903. return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
  904. }
  905. static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
  906. int nr, u64 val)
  907. {
  908. unsigned long ptr;
  909. ptr = offsetof(struct btrfs_node, ptrs) +
  910. sizeof(struct btrfs_key_ptr) * nr;
  911. btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
  912. }
  913. static inline unsigned long btrfs_node_key_ptr_offset(int nr)
  914. {
  915. return offsetof(struct btrfs_node, ptrs) +
  916. sizeof(struct btrfs_key_ptr) * nr;
  917. }
  918. void btrfs_node_key(struct extent_buffer *eb,
  919. struct btrfs_disk_key *disk_key, int nr);
  920. static inline void btrfs_set_node_key(struct extent_buffer *eb,
  921. struct btrfs_disk_key *disk_key, int nr)
  922. {
  923. unsigned long ptr;
  924. ptr = btrfs_node_key_ptr_offset(nr);
  925. write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
  926. struct btrfs_key_ptr, key, disk_key);
  927. }
  928. /* struct btrfs_item */
  929. BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
  930. BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
  931. static inline unsigned long btrfs_item_nr_offset(int nr)
  932. {
  933. return offsetof(struct btrfs_leaf, items) +
  934. sizeof(struct btrfs_item) * nr;
  935. }
  936. static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
  937. int nr)
  938. {
  939. return (struct btrfs_item *)btrfs_item_nr_offset(nr);
  940. }
  941. static inline u32 btrfs_item_end(struct extent_buffer *eb,
  942. struct btrfs_item *item)
  943. {
  944. return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
  945. }
  946. static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
  947. {
  948. return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
  949. }
  950. static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
  951. {
  952. return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
  953. }
  954. static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
  955. {
  956. return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
  957. }
  958. static inline void btrfs_item_key(struct extent_buffer *eb,
  959. struct btrfs_disk_key *disk_key, int nr)
  960. {
  961. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  962. read_eb_member(eb, item, struct btrfs_item, key, disk_key);
  963. }
  964. static inline void btrfs_set_item_key(struct extent_buffer *eb,
  965. struct btrfs_disk_key *disk_key, int nr)
  966. {
  967. struct btrfs_item *item = btrfs_item_nr(eb, nr);
  968. write_eb_member(eb, item, struct btrfs_item, key, disk_key);
  969. }
  970. /* struct btrfs_dir_item */
  971. BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
  972. BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
  973. BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
  974. static inline void btrfs_dir_item_key(struct extent_buffer *eb,
  975. struct btrfs_dir_item *item,
  976. struct btrfs_disk_key *key)
  977. {
  978. read_eb_member(eb, item, struct btrfs_dir_item, location, key);
  979. }
  980. static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
  981. struct btrfs_dir_item *item,
  982. struct btrfs_disk_key *key)
  983. {
  984. write_eb_member(eb, item, struct btrfs_dir_item, location, key);
  985. }
  986. /* struct btrfs_disk_key */
  987. BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
  988. objectid, 64);
  989. BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
  990. BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
  991. static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
  992. struct btrfs_disk_key *disk)
  993. {
  994. cpu->offset = le64_to_cpu(disk->offset);
  995. cpu->type = disk->type;
  996. cpu->objectid = le64_to_cpu(disk->objectid);
  997. }
  998. static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
  999. struct btrfs_key *cpu)
  1000. {
  1001. disk->offset = cpu_to_le64(cpu->offset);
  1002. disk->type = cpu->type;
  1003. disk->objectid = cpu_to_le64(cpu->objectid);
  1004. }
  1005. static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
  1006. struct btrfs_key *key, int nr)
  1007. {
  1008. struct btrfs_disk_key disk_key;
  1009. btrfs_node_key(eb, &disk_key, nr);
  1010. btrfs_disk_key_to_cpu(key, &disk_key);
  1011. }
  1012. static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
  1013. struct btrfs_key *key, int nr)
  1014. {
  1015. struct btrfs_disk_key disk_key;
  1016. btrfs_item_key(eb, &disk_key, nr);
  1017. btrfs_disk_key_to_cpu(key, &disk_key);
  1018. }
  1019. static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
  1020. struct btrfs_dir_item *item,
  1021. struct btrfs_key *key)
  1022. {
  1023. struct btrfs_disk_key disk_key;
  1024. btrfs_dir_item_key(eb, item, &disk_key);
  1025. btrfs_disk_key_to_cpu(key, &disk_key);
  1026. }
  1027. static inline u8 btrfs_key_type(struct btrfs_key *key)
  1028. {
  1029. return key->type;
  1030. }
  1031. static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
  1032. {
  1033. key->type = val;
  1034. }
  1035. /* struct btrfs_header */
  1036. BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
  1037. BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
  1038. generation, 64);
  1039. BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
  1040. BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
  1041. BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
  1042. BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
  1043. static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
  1044. {
  1045. return (btrfs_header_flags(eb) & flag) == flag;
  1046. }
  1047. static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
  1048. {
  1049. u64 flags = btrfs_header_flags(eb);
  1050. btrfs_set_header_flags(eb, flags | flag);
  1051. return (flags & flag) == flag;
  1052. }
  1053. static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
  1054. {
  1055. u64 flags = btrfs_header_flags(eb);
  1056. btrfs_set_header_flags(eb, flags & ~flag);
  1057. return (flags & flag) == flag;
  1058. }
  1059. static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
  1060. {
  1061. unsigned long ptr = offsetof(struct btrfs_header, fsid);
  1062. return (u8 *)ptr;
  1063. }
  1064. static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
  1065. {
  1066. unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
  1067. return (u8 *)ptr;
  1068. }
  1069. static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
  1070. {
  1071. unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
  1072. return (u8 *)ptr;
  1073. }
  1074. static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
  1075. {
  1076. unsigned long ptr = offsetof(struct btrfs_header, csum);
  1077. return (u8 *)ptr;
  1078. }
  1079. static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
  1080. {
  1081. return NULL;
  1082. }
  1083. static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
  1084. {
  1085. return NULL;
  1086. }
  1087. static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
  1088. {
  1089. return NULL;
  1090. }
  1091. static inline int btrfs_is_leaf(struct extent_buffer *eb)
  1092. {
  1093. return (btrfs_header_level(eb) == 0);
  1094. }
  1095. /* struct btrfs_root_item */
  1096. BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
  1097. BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
  1098. BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
  1099. BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
  1100. BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
  1101. BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
  1102. BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
  1103. BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
  1104. BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
  1105. BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
  1106. /* struct btrfs_super_block */
  1107. BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
  1108. BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
  1109. BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
  1110. generation, 64);
  1111. BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
  1112. BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
  1113. struct btrfs_super_block, sys_chunk_array_size, 32);
  1114. BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
  1115. root_level, 8);
  1116. BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
  1117. chunk_root, 64);
  1118. BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
  1119. chunk_root_level, 64);
  1120. BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
  1121. total_bytes, 64);
  1122. BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
  1123. bytes_used, 64);
  1124. BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
  1125. sectorsize, 32);
  1126. BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
  1127. nodesize, 32);
  1128. BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
  1129. leafsize, 32);
  1130. BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
  1131. stripesize, 32);
  1132. BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
  1133. root_dir_objectid, 64);
  1134. BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
  1135. num_devices, 64);
  1136. static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
  1137. {
  1138. return offsetof(struct btrfs_leaf, items);
  1139. }
  1140. /* struct btrfs_file_extent_item */
  1141. BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
  1142. static inline unsigned long btrfs_file_extent_inline_start(struct
  1143. btrfs_file_extent_item *e)
  1144. {
  1145. unsigned long offset = (unsigned long)e;
  1146. offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
  1147. return offset;
  1148. }
  1149. static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
  1150. {
  1151. return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
  1152. }
  1153. static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
  1154. struct btrfs_item *e)
  1155. {
  1156. unsigned long offset;
  1157. offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
  1158. return btrfs_item_size(eb, e) - offset;
  1159. }
  1160. BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
  1161. disk_bytenr, 64);
  1162. BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
  1163. generation, 64);
  1164. BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
  1165. disk_num_bytes, 64);
  1166. BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
  1167. offset, 64);
  1168. BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
  1169. num_bytes, 64);
  1170. static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
  1171. {
  1172. return sb->s_fs_info;
  1173. }
  1174. static inline int btrfs_set_root_name(struct btrfs_root *root,
  1175. const char *name, int len)
  1176. {
  1177. /* if we already have a name just free it */
  1178. if (root->name)
  1179. kfree(root->name);
  1180. root->name = kmalloc(len+1, GFP_KERNEL);
  1181. if (!root->name)
  1182. return -ENOMEM;
  1183. memcpy(root->name, name, len);
  1184. root->name[len] ='\0';
  1185. return 0;
  1186. }
  1187. static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
  1188. if (level == 0)
  1189. return root->leafsize;
  1190. return root->nodesize;
  1191. }
  1192. /* helper function to cast into the data area of the leaf. */
  1193. #define btrfs_item_ptr(leaf, slot, type) \
  1194. ((type *)(btrfs_leaf_data(leaf) + \
  1195. btrfs_item_offset_nr(leaf, slot)))
  1196. #define btrfs_item_ptr_offset(leaf, slot) \
  1197. ((unsigned long)(btrfs_leaf_data(leaf) + \
  1198. btrfs_item_offset_nr(leaf, slot)))
  1199. static inline struct dentry *fdentry(struct file *file) {
  1200. #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
  1201. return file->f_dentry;
  1202. #else
  1203. return file->f_path.dentry;
  1204. #endif
  1205. }
  1206. /* extent-tree.c */
  1207. int btrfs_cross_ref_exists(struct btrfs_trans_handle *trans,
  1208. struct btrfs_root *root,
  1209. struct btrfs_key *key, u64 bytenr);
  1210. int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
  1211. struct btrfs_root *root);
  1212. int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
  1213. struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
  1214. btrfs_fs_info *info,
  1215. u64 bytenr);
  1216. struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
  1217. struct btrfs_block_group_cache
  1218. *hint, u64 search_start,
  1219. int data, int owner);
  1220. struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
  1221. struct btrfs_root *root,
  1222. u32 blocksize,
  1223. u64 root_objectid,
  1224. u64 ref_generation,
  1225. u64 first_objectid,
  1226. int level,
  1227. u64 hint,
  1228. u64 empty_size);
  1229. struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans,
  1230. struct btrfs_root *root,
  1231. u64 bytenr, u32 blocksize);
  1232. int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
  1233. int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
  1234. struct btrfs_root *root,
  1235. struct btrfs_path *path, u64 bytenr,
  1236. u64 root_objectid, u64 ref_generation,
  1237. u64 owner, u64 owner_offset);
  1238. int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
  1239. struct btrfs_root *root,
  1240. u64 num_bytes, u64 min_bytes,
  1241. u64 root_objectid, u64 ref_generation,
  1242. u64 owner, u64 owner_offset,
  1243. u64 empty_size, u64 hint_byte,
  1244. u64 search_end, struct btrfs_key *ins, u64 data);
  1245. int btrfs_alloc_reserved_extent(struct btrfs_trans_handle *trans,
  1246. struct btrfs_root *root,
  1247. u64 root_objectid, u64 ref_generation,
  1248. u64 owner, u64 owner_offset,
  1249. struct btrfs_key *ins);
  1250. int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
  1251. struct btrfs_root *root,
  1252. u64 num_bytes, u64 min_alloc_size,
  1253. u64 empty_size, u64 hint_byte,
  1254. u64 search_end, struct btrfs_key *ins,
  1255. u64 data);
  1256. int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1257. struct extent_buffer *buf, int cache_ref);
  1258. int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
  1259. *root, u64 bytenr, u64 num_bytes,
  1260. u64 root_objectid, u64 ref_generation,
  1261. u64 owner_objectid, u64 owner_offset, int pin);
  1262. int btrfs_free_reserved_extent(struct btrfs_root *root, u64 start, u64 len);
  1263. int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
  1264. struct btrfs_root *root,
  1265. struct extent_io_tree *unpin);
  1266. int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
  1267. struct btrfs_root *root,
  1268. u64 bytenr, u64 num_bytes,
  1269. u64 root_objectid, u64 ref_generation,
  1270. u64 owner, u64 owner_offset);
  1271. int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
  1272. struct btrfs_root *root);
  1273. int btrfs_free_block_groups(struct btrfs_fs_info *info);
  1274. int btrfs_read_block_groups(struct btrfs_root *root);
  1275. int btrfs_make_block_group(struct btrfs_trans_handle *trans,
  1276. struct btrfs_root *root, u64 bytes_used,
  1277. u64 type, u64 chunk_objectid, u64 chunk_offset,
  1278. u64 size);
  1279. /* ctree.c */
  1280. int btrfs_previous_item(struct btrfs_root *root,
  1281. struct btrfs_path *path, u64 min_objectid,
  1282. int type);
  1283. struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
  1284. struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
  1285. int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
  1286. struct btrfs_key *key, int lowest_level,
  1287. int cache_only, u64 min_trans);
  1288. int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
  1289. struct btrfs_path *path, int cache_only,
  1290. u64 min_trans);
  1291. int btrfs_cow_block(struct btrfs_trans_handle *trans,
  1292. struct btrfs_root *root, struct extent_buffer *buf,
  1293. struct extent_buffer *parent, int parent_slot,
  1294. struct extent_buffer **cow_ret, u64 prealloc_dest);
  1295. int btrfs_copy_root(struct btrfs_trans_handle *trans,
  1296. struct btrfs_root *root,
  1297. struct extent_buffer *buf,
  1298. struct extent_buffer **cow_ret, u64 new_root_objectid);
  1299. int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1300. *root, struct btrfs_path *path, u32 data_size);
  1301. int btrfs_truncate_item(struct btrfs_trans_handle *trans,
  1302. struct btrfs_root *root,
  1303. struct btrfs_path *path,
  1304. u32 new_size, int from_end);
  1305. int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
  1306. *root, struct btrfs_key *key, struct btrfs_path *p, int
  1307. ins_len, int cow);
  1308. int btrfs_realloc_node(struct btrfs_trans_handle *trans,
  1309. struct btrfs_root *root, struct extent_buffer *parent,
  1310. int start_slot, int cache_only, u64 *last_ret,
  1311. struct btrfs_key *progress);
  1312. void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
  1313. struct btrfs_path *btrfs_alloc_path(void);
  1314. void btrfs_free_path(struct btrfs_path *p);
  1315. void btrfs_init_path(struct btrfs_path *p);
  1316. int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1317. struct btrfs_path *path, int slot, int nr);
  1318. static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
  1319. struct btrfs_root *root,
  1320. struct btrfs_path *path)
  1321. {
  1322. return btrfs_del_items(trans, root, path, path->slots[0], 1);
  1323. }
  1324. int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1325. *root, struct btrfs_key *key, void *data, u32 data_size);
  1326. int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
  1327. struct btrfs_root *root,
  1328. struct btrfs_path *path,
  1329. struct btrfs_key *cpu_key, u32 *data_size, int nr);
  1330. static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
  1331. struct btrfs_root *root,
  1332. struct btrfs_path *path,
  1333. struct btrfs_key *key,
  1334. u32 data_size)
  1335. {
  1336. return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
  1337. }
  1338. int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
  1339. int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
  1340. int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
  1341. int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
  1342. *root);
  1343. /* root-item.c */
  1344. int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  1345. struct btrfs_key *key);
  1346. int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
  1347. *root, struct btrfs_key *key, struct btrfs_root_item
  1348. *item);
  1349. int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
  1350. *root, struct btrfs_key *key, struct btrfs_root_item
  1351. *item);
  1352. int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
  1353. btrfs_root_item *item, struct btrfs_key *key);
  1354. int btrfs_search_root(struct btrfs_root *root, u64 search_start,
  1355. u64 *found_objectid);
  1356. int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
  1357. struct btrfs_root *latest_root);
  1358. /* dir-item.c */
  1359. int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
  1360. *root, const char *name, int name_len, u64 dir,
  1361. struct btrfs_key *location, u8 type, u64 index);
  1362. struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
  1363. struct btrfs_root *root,
  1364. struct btrfs_path *path, u64 dir,
  1365. const char *name, int name_len,
  1366. int mod);
  1367. struct btrfs_dir_item *
  1368. btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
  1369. struct btrfs_root *root,
  1370. struct btrfs_path *path, u64 dir,
  1371. u64 objectid, const char *name, int name_len,
  1372. int mod);
  1373. struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
  1374. struct btrfs_path *path,
  1375. const char *name, int name_len);
  1376. int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
  1377. struct btrfs_root *root,
  1378. struct btrfs_path *path,
  1379. struct btrfs_dir_item *di);
  1380. int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
  1381. struct btrfs_root *root, const char *name,
  1382. u16 name_len, const void *data, u16 data_len,
  1383. u64 dir);
  1384. struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
  1385. struct btrfs_root *root,
  1386. struct btrfs_path *path, u64 dir,
  1387. const char *name, u16 name_len,
  1388. int mod);
  1389. /* orphan.c */
  1390. int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
  1391. struct btrfs_root *root, u64 offset);
  1392. int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
  1393. struct btrfs_root *root, u64 offset);
  1394. /* inode-map.c */
  1395. int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
  1396. struct btrfs_root *fs_root,
  1397. u64 dirid, u64 *objectid);
  1398. int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
  1399. /* inode-item.c */
  1400. int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
  1401. struct btrfs_root *root,
  1402. const char *name, int name_len,
  1403. u64 inode_objectid, u64 ref_objectid, u64 index);
  1404. int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
  1405. struct btrfs_root *root,
  1406. const char *name, int name_len,
  1407. u64 inode_objectid, u64 ref_objectid, u64 *index);
  1408. int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
  1409. struct btrfs_root *root,
  1410. struct btrfs_path *path, u64 objectid);
  1411. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  1412. *root, struct btrfs_path *path,
  1413. struct btrfs_key *location, int mod);
  1414. /* file-item.c */
  1415. int btrfs_lookup_bio_sums(struct btrfs_root *root, struct inode *inode,
  1416. struct bio *bio);
  1417. int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
  1418. struct btrfs_root *root,
  1419. u64 objectid, u64 pos, u64 disk_offset,
  1420. u64 disk_num_bytes,
  1421. u64 num_bytes, u64 offset);
  1422. int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
  1423. struct btrfs_root *root,
  1424. struct btrfs_path *path, u64 objectid,
  1425. u64 bytenr, int mod);
  1426. int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
  1427. struct btrfs_root *root, struct inode *inode,
  1428. struct btrfs_ordered_sum *sums);
  1429. int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
  1430. struct bio *bio);
  1431. struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
  1432. struct btrfs_root *root,
  1433. struct btrfs_path *path,
  1434. u64 objectid, u64 offset,
  1435. int cow);
  1436. int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
  1437. struct btrfs_root *root, struct btrfs_path *path,
  1438. u64 isize);
  1439. /* inode.c */
  1440. /* RHEL and EL kernels have a patch that renames PG_checked to FsMisc */
  1441. #ifdef ClearPageFsMisc
  1442. #define ClearPageChecked ClearPageFsMisc
  1443. #define SetPageChecked SetPageFsMisc
  1444. #define PageChecked PageFsMisc
  1445. #endif
  1446. int btrfs_start_delalloc_inodes(struct btrfs_root *root);
  1447. int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end);
  1448. int btrfs_writepages(struct address_space *mapping,
  1449. struct writeback_control *wbc);
  1450. int btrfs_create_subvol_root(struct btrfs_root *new_root,
  1451. struct btrfs_trans_handle *trans, u64 new_dirid,
  1452. struct btrfs_block_group_cache *block_group);
  1453. void btrfs_invalidate_dcache_root(struct btrfs_root *root, char *name,
  1454. int namelen);
  1455. int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
  1456. size_t size, struct bio *bio);
  1457. static inline void dec_i_blocks(struct inode *inode, u64 dec)
  1458. {
  1459. dec = dec >> 9;
  1460. if (dec <= inode->i_blocks)
  1461. inode->i_blocks -= dec;
  1462. else
  1463. inode->i_blocks = 0;
  1464. }
  1465. unsigned long btrfs_force_ra(struct address_space *mapping,
  1466. struct file_ra_state *ra, struct file *file,
  1467. pgoff_t offset, pgoff_t last_index);
  1468. int btrfs_check_free_space(struct btrfs_root *root, u64 num_required,
  1469. int for_del);
  1470. int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page);
  1471. int btrfs_readpage(struct file *file, struct page *page);
  1472. void btrfs_delete_inode(struct inode *inode);
  1473. void btrfs_put_inode(struct inode *inode);
  1474. void btrfs_read_locked_inode(struct inode *inode);
  1475. int btrfs_write_inode(struct inode *inode, int wait);
  1476. void btrfs_dirty_inode(struct inode *inode);
  1477. struct inode *btrfs_alloc_inode(struct super_block *sb);
  1478. void btrfs_destroy_inode(struct inode *inode);
  1479. int btrfs_init_cachep(void);
  1480. void btrfs_destroy_cachep(void);
  1481. long btrfs_ioctl_trans_end(struct file *file);
  1482. struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
  1483. struct btrfs_root *root);
  1484. struct inode *btrfs_ilookup(struct super_block *s, u64 objectid,
  1485. u64 root_objectid);
  1486. int btrfs_commit_write(struct file *file, struct page *page,
  1487. unsigned from, unsigned to);
  1488. struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
  1489. size_t page_offset, u64 start, u64 end,
  1490. int create);
  1491. int btrfs_update_inode(struct btrfs_trans_handle *trans,
  1492. struct btrfs_root *root,
  1493. struct inode *inode);
  1494. /* ioctl.c */
  1495. long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  1496. /* file.c */
  1497. int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end);
  1498. int btrfs_check_file(struct btrfs_root *root, struct inode *inode);
  1499. extern struct file_operations btrfs_file_operations;
  1500. int btrfs_drop_extents(struct btrfs_trans_handle *trans,
  1501. struct btrfs_root *root, struct inode *inode,
  1502. u64 start, u64 end, u64 inline_limit, u64 *hint_block);
  1503. int btrfs_release_file(struct inode *inode, struct file *file);
  1504. /* tree-defrag.c */
  1505. int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
  1506. struct btrfs_root *root, int cache_only);
  1507. /* sysfs.c */
  1508. int btrfs_init_sysfs(void);
  1509. void btrfs_exit_sysfs(void);
  1510. int btrfs_sysfs_add_super(struct btrfs_fs_info *fs);
  1511. int btrfs_sysfs_add_root(struct btrfs_root *root);
  1512. void btrfs_sysfs_del_root(struct btrfs_root *root);
  1513. void btrfs_sysfs_del_super(struct btrfs_fs_info *root);
  1514. /* xattr.c */
  1515. ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  1516. /* super.c */
  1517. u64 btrfs_parse_size(char *str);
  1518. int btrfs_parse_options(struct btrfs_root *root, char *options);
  1519. int btrfs_sync_fs(struct super_block *sb, int wait);
  1520. /* acl.c */
  1521. int btrfs_check_acl(struct inode *inode, int mask);
  1522. int btrfs_init_acl(struct inode *inode, struct inode *dir);
  1523. int btrfs_acl_chmod(struct inode *inode);
  1524. #endif