ctree.h 54 KB

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