ctree.h 54 KB

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