ctree.h 61 KB

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