inode-tests.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  1. /*
  2. * Copyright (C) 2013 Fusion IO. 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. #include <linux/types.h>
  19. #include "btrfs-tests.h"
  20. #include "../ctree.h"
  21. #include "../btrfs_inode.h"
  22. #include "../disk-io.h"
  23. #include "../extent_io.h"
  24. #include "../volumes.h"
  25. #include "../compression.h"
  26. static void insert_extent(struct btrfs_root *root, u64 start, u64 len,
  27. u64 ram_bytes, u64 offset, u64 disk_bytenr,
  28. u64 disk_len, u32 type, u8 compression, int slot)
  29. {
  30. struct btrfs_path path;
  31. struct btrfs_file_extent_item *fi;
  32. struct extent_buffer *leaf = root->node;
  33. struct btrfs_key key;
  34. u32 value_len = sizeof(struct btrfs_file_extent_item);
  35. if (type == BTRFS_FILE_EXTENT_INLINE)
  36. value_len += len;
  37. memset(&path, 0, sizeof(path));
  38. path.nodes[0] = leaf;
  39. path.slots[0] = slot;
  40. key.objectid = BTRFS_FIRST_FREE_OBJECTID;
  41. key.type = BTRFS_EXTENT_DATA_KEY;
  42. key.offset = start;
  43. setup_items_for_insert(root, &path, &key, &value_len, value_len,
  44. value_len + sizeof(struct btrfs_item), 1);
  45. fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
  46. btrfs_set_file_extent_generation(leaf, fi, 1);
  47. btrfs_set_file_extent_type(leaf, fi, type);
  48. btrfs_set_file_extent_disk_bytenr(leaf, fi, disk_bytenr);
  49. btrfs_set_file_extent_disk_num_bytes(leaf, fi, disk_len);
  50. btrfs_set_file_extent_offset(leaf, fi, offset);
  51. btrfs_set_file_extent_num_bytes(leaf, fi, len);
  52. btrfs_set_file_extent_ram_bytes(leaf, fi, ram_bytes);
  53. btrfs_set_file_extent_compression(leaf, fi, compression);
  54. btrfs_set_file_extent_encryption(leaf, fi, 0);
  55. btrfs_set_file_extent_other_encoding(leaf, fi, 0);
  56. }
  57. static void insert_inode_item_key(struct btrfs_root *root)
  58. {
  59. struct btrfs_path path;
  60. struct extent_buffer *leaf = root->node;
  61. struct btrfs_key key;
  62. u32 value_len = 0;
  63. memset(&path, 0, sizeof(path));
  64. path.nodes[0] = leaf;
  65. path.slots[0] = 0;
  66. key.objectid = BTRFS_INODE_ITEM_KEY;
  67. key.type = BTRFS_INODE_ITEM_KEY;
  68. key.offset = 0;
  69. setup_items_for_insert(root, &path, &key, &value_len, value_len,
  70. value_len + sizeof(struct btrfs_item), 1);
  71. }
  72. /*
  73. * Build the most complicated map of extents the earth has ever seen. We want
  74. * this so we can test all of the corner cases of btrfs_get_extent. Here is a
  75. * diagram of how the extents will look though this may not be possible we still
  76. * want to make sure everything acts normally (the last number is not inclusive)
  77. *
  78. * [0 - 5][5 - 6][ 6 - 4096 ][ 4096 - 4100][4100 - 8195][8195 - 12291]
  79. * [hole ][inline][hole but no extent][ hole ][ regular ][regular1 split]
  80. *
  81. * [12291 - 16387][16387 - 24579][24579 - 28675][ 28675 - 32771][32771 - 36867 ]
  82. * [ hole ][regular1 split][ prealloc ][ prealloc1 ][prealloc1 written]
  83. *
  84. * [36867 - 45059][45059 - 53251][53251 - 57347][57347 - 61443][61443- 69635]
  85. * [ prealloc1 ][ compressed ][ compressed1 ][ regular ][ compressed1]
  86. *
  87. * [69635-73731][ 73731 - 86019 ][86019-90115]
  88. * [ regular ][ hole but no extent][ regular ]
  89. */
  90. static void setup_file_extents(struct btrfs_root *root, u32 sectorsize)
  91. {
  92. int slot = 0;
  93. u64 disk_bytenr = SZ_1M;
  94. u64 offset = 0;
  95. /* First we want a hole */
  96. insert_extent(root, offset, 5, 5, 0, 0, 0, BTRFS_FILE_EXTENT_REG, 0,
  97. slot);
  98. slot++;
  99. offset += 5;
  100. /*
  101. * Now we want an inline extent, I don't think this is possible but hey
  102. * why not? Also keep in mind if we have an inline extent it counts as
  103. * the whole first page. If we were to expand it we would have to cow
  104. * and we wouldn't have an inline extent anymore.
  105. */
  106. insert_extent(root, offset, 1, 1, 0, 0, 0, BTRFS_FILE_EXTENT_INLINE, 0,
  107. slot);
  108. slot++;
  109. offset = sectorsize;
  110. /* Now another hole */
  111. insert_extent(root, offset, 4, 4, 0, 0, 0, BTRFS_FILE_EXTENT_REG, 0,
  112. slot);
  113. slot++;
  114. offset += 4;
  115. /* Now for a regular extent */
  116. insert_extent(root, offset, sectorsize - 1, sectorsize - 1, 0,
  117. disk_bytenr, sectorsize, BTRFS_FILE_EXTENT_REG, 0, slot);
  118. slot++;
  119. disk_bytenr += sectorsize;
  120. offset += sectorsize - 1;
  121. /*
  122. * Now for 3 extents that were split from a hole punch so we test
  123. * offsets properly.
  124. */
  125. insert_extent(root, offset, sectorsize, 4 * sectorsize, 0, disk_bytenr,
  126. 4 * sectorsize, BTRFS_FILE_EXTENT_REG, 0, slot);
  127. slot++;
  128. offset += sectorsize;
  129. insert_extent(root, offset, sectorsize, sectorsize, 0, 0, 0,
  130. BTRFS_FILE_EXTENT_REG, 0, slot);
  131. slot++;
  132. offset += sectorsize;
  133. insert_extent(root, offset, 2 * sectorsize, 4 * sectorsize,
  134. 2 * sectorsize, disk_bytenr, 4 * sectorsize,
  135. BTRFS_FILE_EXTENT_REG, 0, slot);
  136. slot++;
  137. offset += 2 * sectorsize;
  138. disk_bytenr += 4 * sectorsize;
  139. /* Now for a unwritten prealloc extent */
  140. insert_extent(root, offset, sectorsize, sectorsize, 0, disk_bytenr,
  141. sectorsize, BTRFS_FILE_EXTENT_PREALLOC, 0, slot);
  142. slot++;
  143. offset += sectorsize;
  144. /*
  145. * We want to jack up disk_bytenr a little more so the em stuff doesn't
  146. * merge our records.
  147. */
  148. disk_bytenr += 2 * sectorsize;
  149. /*
  150. * Now for a partially written prealloc extent, basically the same as
  151. * the hole punch example above. Ram_bytes never changes when you mark
  152. * extents written btw.
  153. */
  154. insert_extent(root, offset, sectorsize, 4 * sectorsize, 0, disk_bytenr,
  155. 4 * sectorsize, BTRFS_FILE_EXTENT_PREALLOC, 0, slot);
  156. slot++;
  157. offset += sectorsize;
  158. insert_extent(root, offset, sectorsize, 4 * sectorsize, sectorsize,
  159. disk_bytenr, 4 * sectorsize, BTRFS_FILE_EXTENT_REG, 0,
  160. slot);
  161. slot++;
  162. offset += sectorsize;
  163. insert_extent(root, offset, 2 * sectorsize, 4 * sectorsize,
  164. 2 * sectorsize, disk_bytenr, 4 * sectorsize,
  165. BTRFS_FILE_EXTENT_PREALLOC, 0, slot);
  166. slot++;
  167. offset += 2 * sectorsize;
  168. disk_bytenr += 4 * sectorsize;
  169. /* Now a normal compressed extent */
  170. insert_extent(root, offset, 2 * sectorsize, 2 * sectorsize, 0,
  171. disk_bytenr, sectorsize, BTRFS_FILE_EXTENT_REG,
  172. BTRFS_COMPRESS_ZLIB, slot);
  173. slot++;
  174. offset += 2 * sectorsize;
  175. /* No merges */
  176. disk_bytenr += 2 * sectorsize;
  177. /* Now a split compressed extent */
  178. insert_extent(root, offset, sectorsize, 4 * sectorsize, 0, disk_bytenr,
  179. sectorsize, BTRFS_FILE_EXTENT_REG,
  180. BTRFS_COMPRESS_ZLIB, slot);
  181. slot++;
  182. offset += sectorsize;
  183. insert_extent(root, offset, sectorsize, sectorsize, 0,
  184. disk_bytenr + sectorsize, sectorsize,
  185. BTRFS_FILE_EXTENT_REG, 0, slot);
  186. slot++;
  187. offset += sectorsize;
  188. insert_extent(root, offset, 2 * sectorsize, 4 * sectorsize,
  189. 2 * sectorsize, disk_bytenr, sectorsize,
  190. BTRFS_FILE_EXTENT_REG, BTRFS_COMPRESS_ZLIB, slot);
  191. slot++;
  192. offset += 2 * sectorsize;
  193. disk_bytenr += 2 * sectorsize;
  194. /* Now extents that have a hole but no hole extent */
  195. insert_extent(root, offset, sectorsize, sectorsize, 0, disk_bytenr,
  196. sectorsize, BTRFS_FILE_EXTENT_REG, 0, slot);
  197. slot++;
  198. offset += 4 * sectorsize;
  199. disk_bytenr += sectorsize;
  200. insert_extent(root, offset, sectorsize, sectorsize, 0, disk_bytenr,
  201. sectorsize, BTRFS_FILE_EXTENT_REG, 0, slot);
  202. }
  203. static unsigned long prealloc_only = 0;
  204. static unsigned long compressed_only = 0;
  205. static unsigned long vacancy_only = 0;
  206. static noinline int test_btrfs_get_extent(u32 sectorsize, u32 nodesize)
  207. {
  208. struct btrfs_fs_info *fs_info = NULL;
  209. struct inode *inode = NULL;
  210. struct btrfs_root *root = NULL;
  211. struct extent_map *em = NULL;
  212. u64 orig_start;
  213. u64 disk_bytenr;
  214. u64 offset;
  215. int ret = -ENOMEM;
  216. inode = btrfs_new_test_inode();
  217. if (!inode) {
  218. test_msg("Couldn't allocate inode\n");
  219. return ret;
  220. }
  221. BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
  222. BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
  223. BTRFS_I(inode)->location.offset = 0;
  224. fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
  225. if (!fs_info) {
  226. test_msg("Couldn't allocate dummy fs info\n");
  227. goto out;
  228. }
  229. root = btrfs_alloc_dummy_root(fs_info);
  230. if (IS_ERR(root)) {
  231. test_msg("Couldn't allocate root\n");
  232. goto out;
  233. }
  234. root->node = alloc_dummy_extent_buffer(fs_info, nodesize);
  235. if (!root->node) {
  236. test_msg("Couldn't allocate dummy buffer\n");
  237. goto out;
  238. }
  239. /*
  240. * We will just free a dummy node if it's ref count is 2 so we need an
  241. * extra ref so our searches don't accidentally release our page.
  242. */
  243. extent_buffer_get(root->node);
  244. btrfs_set_header_nritems(root->node, 0);
  245. btrfs_set_header_level(root->node, 0);
  246. ret = -EINVAL;
  247. /* First with no extents */
  248. BTRFS_I(inode)->root = root;
  249. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, 0, sectorsize, 0);
  250. if (IS_ERR(em)) {
  251. em = NULL;
  252. test_msg("Got an error when we shouldn't have\n");
  253. goto out;
  254. }
  255. if (em->block_start != EXTENT_MAP_HOLE) {
  256. test_msg("Expected a hole, got %llu\n", em->block_start);
  257. goto out;
  258. }
  259. free_extent_map(em);
  260. btrfs_drop_extent_cache(BTRFS_I(inode), 0, (u64)-1, 0);
  261. /*
  262. * All of the magic numbers are based on the mapping setup in
  263. * setup_file_extents, so if you change anything there you need to
  264. * update the comment and update the expected values below.
  265. */
  266. setup_file_extents(root, sectorsize);
  267. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, 0, (u64)-1, 0);
  268. if (IS_ERR(em)) {
  269. test_msg("Got an error when we shouldn't have\n");
  270. goto out;
  271. }
  272. if (em->block_start != EXTENT_MAP_HOLE) {
  273. test_msg("Expected a hole, got %llu\n", em->block_start);
  274. goto out;
  275. }
  276. if (em->start != 0 || em->len != 5) {
  277. test_msg("Unexpected extent wanted start 0 len 5, got start "
  278. "%llu len %llu\n", em->start, em->len);
  279. goto out;
  280. }
  281. if (em->flags != 0) {
  282. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  283. goto out;
  284. }
  285. offset = em->start + em->len;
  286. free_extent_map(em);
  287. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  288. if (IS_ERR(em)) {
  289. test_msg("Got an error when we shouldn't have\n");
  290. goto out;
  291. }
  292. if (em->block_start != EXTENT_MAP_INLINE) {
  293. test_msg("Expected an inline, got %llu\n", em->block_start);
  294. goto out;
  295. }
  296. if (em->start != offset || em->len != (sectorsize - 5)) {
  297. test_msg("Unexpected extent wanted start %llu len 1, got start "
  298. "%llu len %llu\n", offset, em->start, em->len);
  299. goto out;
  300. }
  301. if (em->flags != 0) {
  302. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  303. goto out;
  304. }
  305. /*
  306. * We don't test anything else for inline since it doesn't get set
  307. * unless we have a page for it to write into. Maybe we should change
  308. * this?
  309. */
  310. offset = em->start + em->len;
  311. free_extent_map(em);
  312. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  313. if (IS_ERR(em)) {
  314. test_msg("Got an error when we shouldn't have\n");
  315. goto out;
  316. }
  317. if (em->block_start != EXTENT_MAP_HOLE) {
  318. test_msg("Expected a hole, got %llu\n", em->block_start);
  319. goto out;
  320. }
  321. if (em->start != offset || em->len != 4) {
  322. test_msg("Unexpected extent wanted start %llu len 4, got start "
  323. "%llu len %llu\n", offset, em->start, em->len);
  324. goto out;
  325. }
  326. if (em->flags != 0) {
  327. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  328. goto out;
  329. }
  330. offset = em->start + em->len;
  331. free_extent_map(em);
  332. /* Regular extent */
  333. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  334. if (IS_ERR(em)) {
  335. test_msg("Got an error when we shouldn't have\n");
  336. goto out;
  337. }
  338. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  339. test_msg("Expected a real extent, got %llu\n", em->block_start);
  340. goto out;
  341. }
  342. if (em->start != offset || em->len != sectorsize - 1) {
  343. test_msg("Unexpected extent wanted start %llu len 4095, got "
  344. "start %llu len %llu\n", offset, em->start, em->len);
  345. goto out;
  346. }
  347. if (em->flags != 0) {
  348. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  349. goto out;
  350. }
  351. if (em->orig_start != em->start) {
  352. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  353. em->orig_start);
  354. goto out;
  355. }
  356. offset = em->start + em->len;
  357. free_extent_map(em);
  358. /* The next 3 are split extents */
  359. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  360. if (IS_ERR(em)) {
  361. test_msg("Got an error when we shouldn't have\n");
  362. goto out;
  363. }
  364. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  365. test_msg("Expected a real extent, got %llu\n", em->block_start);
  366. goto out;
  367. }
  368. if (em->start != offset || em->len != sectorsize) {
  369. test_msg("Unexpected extent start %llu len %u, "
  370. "got start %llu len %llu\n",
  371. offset, sectorsize, em->start, em->len);
  372. goto out;
  373. }
  374. if (em->flags != 0) {
  375. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  376. goto out;
  377. }
  378. if (em->orig_start != em->start) {
  379. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  380. em->orig_start);
  381. goto out;
  382. }
  383. disk_bytenr = em->block_start;
  384. orig_start = em->start;
  385. offset = em->start + em->len;
  386. free_extent_map(em);
  387. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  388. if (IS_ERR(em)) {
  389. test_msg("Got an error when we shouldn't have\n");
  390. goto out;
  391. }
  392. if (em->block_start != EXTENT_MAP_HOLE) {
  393. test_msg("Expected a hole, got %llu\n", em->block_start);
  394. goto out;
  395. }
  396. if (em->start != offset || em->len != sectorsize) {
  397. test_msg("Unexpected extent wanted start %llu len %u, "
  398. "got start %llu len %llu\n",
  399. offset, sectorsize, em->start, em->len);
  400. goto out;
  401. }
  402. if (em->flags != 0) {
  403. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  404. goto out;
  405. }
  406. offset = em->start + em->len;
  407. free_extent_map(em);
  408. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  409. if (IS_ERR(em)) {
  410. test_msg("Got an error when we shouldn't have\n");
  411. goto out;
  412. }
  413. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  414. test_msg("Expected a real extent, got %llu\n", em->block_start);
  415. goto out;
  416. }
  417. if (em->start != offset || em->len != 2 * sectorsize) {
  418. test_msg("Unexpected extent wanted start %llu len %u, "
  419. "got start %llu len %llu\n",
  420. offset, 2 * sectorsize, em->start, em->len);
  421. goto out;
  422. }
  423. if (em->flags != 0) {
  424. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  425. goto out;
  426. }
  427. if (em->orig_start != orig_start) {
  428. test_msg("Wrong orig offset, want %llu, have %llu\n",
  429. orig_start, em->orig_start);
  430. goto out;
  431. }
  432. disk_bytenr += (em->start - orig_start);
  433. if (em->block_start != disk_bytenr) {
  434. test_msg("Wrong block start, want %llu, have %llu\n",
  435. disk_bytenr, em->block_start);
  436. goto out;
  437. }
  438. offset = em->start + em->len;
  439. free_extent_map(em);
  440. /* Prealloc extent */
  441. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  442. if (IS_ERR(em)) {
  443. test_msg("Got an error when we shouldn't have\n");
  444. goto out;
  445. }
  446. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  447. test_msg("Expected a real extent, got %llu\n", em->block_start);
  448. goto out;
  449. }
  450. if (em->start != offset || em->len != sectorsize) {
  451. test_msg("Unexpected extent wanted start %llu len %u, "
  452. "got start %llu len %llu\n",
  453. offset, sectorsize, em->start, em->len);
  454. goto out;
  455. }
  456. if (em->flags != prealloc_only) {
  457. test_msg("Unexpected flags set, want %lu have %lu\n",
  458. prealloc_only, em->flags);
  459. goto out;
  460. }
  461. if (em->orig_start != em->start) {
  462. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  463. em->orig_start);
  464. goto out;
  465. }
  466. offset = em->start + em->len;
  467. free_extent_map(em);
  468. /* The next 3 are a half written prealloc extent */
  469. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  470. if (IS_ERR(em)) {
  471. test_msg("Got an error when we shouldn't have\n");
  472. goto out;
  473. }
  474. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  475. test_msg("Expected a real extent, got %llu\n", em->block_start);
  476. goto out;
  477. }
  478. if (em->start != offset || em->len != sectorsize) {
  479. test_msg("Unexpected extent wanted start %llu len %u, "
  480. "got start %llu len %llu\n",
  481. offset, sectorsize, em->start, em->len);
  482. goto out;
  483. }
  484. if (em->flags != prealloc_only) {
  485. test_msg("Unexpected flags set, want %lu have %lu\n",
  486. prealloc_only, em->flags);
  487. goto out;
  488. }
  489. if (em->orig_start != em->start) {
  490. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  491. em->orig_start);
  492. goto out;
  493. }
  494. disk_bytenr = em->block_start;
  495. orig_start = em->start;
  496. offset = em->start + em->len;
  497. free_extent_map(em);
  498. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  499. if (IS_ERR(em)) {
  500. test_msg("Got an error when we shouldn't have\n");
  501. goto out;
  502. }
  503. if (em->block_start >= EXTENT_MAP_HOLE) {
  504. test_msg("Expected a real extent, got %llu\n", em->block_start);
  505. goto out;
  506. }
  507. if (em->start != offset || em->len != sectorsize) {
  508. test_msg("Unexpected extent wanted start %llu len %u, "
  509. "got start %llu len %llu\n",
  510. offset, sectorsize, em->start, em->len);
  511. goto out;
  512. }
  513. if (em->flags != 0) {
  514. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  515. goto out;
  516. }
  517. if (em->orig_start != orig_start) {
  518. test_msg("Unexpected orig offset, wanted %llu, have %llu\n",
  519. orig_start, em->orig_start);
  520. goto out;
  521. }
  522. if (em->block_start != (disk_bytenr + (em->start - em->orig_start))) {
  523. test_msg("Unexpected block start, wanted %llu, have %llu\n",
  524. disk_bytenr + (em->start - em->orig_start),
  525. em->block_start);
  526. goto out;
  527. }
  528. offset = em->start + em->len;
  529. free_extent_map(em);
  530. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  531. if (IS_ERR(em)) {
  532. test_msg("Got an error when we shouldn't have\n");
  533. goto out;
  534. }
  535. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  536. test_msg("Expected a real extent, got %llu\n", em->block_start);
  537. goto out;
  538. }
  539. if (em->start != offset || em->len != 2 * sectorsize) {
  540. test_msg("Unexpected extent wanted start %llu len %u, "
  541. "got start %llu len %llu\n",
  542. offset, 2 * sectorsize, em->start, em->len);
  543. goto out;
  544. }
  545. if (em->flags != prealloc_only) {
  546. test_msg("Unexpected flags set, want %lu have %lu\n",
  547. prealloc_only, em->flags);
  548. goto out;
  549. }
  550. if (em->orig_start != orig_start) {
  551. test_msg("Wrong orig offset, want %llu, have %llu\n", orig_start,
  552. em->orig_start);
  553. goto out;
  554. }
  555. if (em->block_start != (disk_bytenr + (em->start - em->orig_start))) {
  556. test_msg("Unexpected block start, wanted %llu, have %llu\n",
  557. disk_bytenr + (em->start - em->orig_start),
  558. em->block_start);
  559. goto out;
  560. }
  561. offset = em->start + em->len;
  562. free_extent_map(em);
  563. /* Now for the compressed extent */
  564. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  565. if (IS_ERR(em)) {
  566. test_msg("Got an error when we shouldn't have\n");
  567. goto out;
  568. }
  569. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  570. test_msg("Expected a real extent, got %llu\n", em->block_start);
  571. goto out;
  572. }
  573. if (em->start != offset || em->len != 2 * sectorsize) {
  574. test_msg("Unexpected extent wanted start %llu len %u,"
  575. "got start %llu len %llu\n",
  576. offset, 2 * sectorsize, em->start, em->len);
  577. goto out;
  578. }
  579. if (em->flags != compressed_only) {
  580. test_msg("Unexpected flags set, want %lu have %lu\n",
  581. compressed_only, em->flags);
  582. goto out;
  583. }
  584. if (em->orig_start != em->start) {
  585. test_msg("Wrong orig offset, want %llu, have %llu\n",
  586. em->start, em->orig_start);
  587. goto out;
  588. }
  589. if (em->compress_type != BTRFS_COMPRESS_ZLIB) {
  590. test_msg("Unexpected compress type, wanted %d, got %d\n",
  591. BTRFS_COMPRESS_ZLIB, em->compress_type);
  592. goto out;
  593. }
  594. offset = em->start + em->len;
  595. free_extent_map(em);
  596. /* Split compressed extent */
  597. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  598. if (IS_ERR(em)) {
  599. test_msg("Got an error when we shouldn't have\n");
  600. goto out;
  601. }
  602. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  603. test_msg("Expected a real extent, got %llu\n", em->block_start);
  604. goto out;
  605. }
  606. if (em->start != offset || em->len != sectorsize) {
  607. test_msg("Unexpected extent wanted start %llu len %u,"
  608. "got start %llu len %llu\n",
  609. offset, sectorsize, em->start, em->len);
  610. goto out;
  611. }
  612. if (em->flags != compressed_only) {
  613. test_msg("Unexpected flags set, want %lu have %lu\n",
  614. compressed_only, em->flags);
  615. goto out;
  616. }
  617. if (em->orig_start != em->start) {
  618. test_msg("Wrong orig offset, want %llu, have %llu\n",
  619. em->start, em->orig_start);
  620. goto out;
  621. }
  622. if (em->compress_type != BTRFS_COMPRESS_ZLIB) {
  623. test_msg("Unexpected compress type, wanted %d, got %d\n",
  624. BTRFS_COMPRESS_ZLIB, em->compress_type);
  625. goto out;
  626. }
  627. disk_bytenr = em->block_start;
  628. orig_start = em->start;
  629. offset = em->start + em->len;
  630. free_extent_map(em);
  631. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  632. if (IS_ERR(em)) {
  633. test_msg("Got an error when we shouldn't have\n");
  634. goto out;
  635. }
  636. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  637. test_msg("Expected a real extent, got %llu\n", em->block_start);
  638. goto out;
  639. }
  640. if (em->start != offset || em->len != sectorsize) {
  641. test_msg("Unexpected extent wanted start %llu len %u, "
  642. "got start %llu len %llu\n",
  643. offset, sectorsize, em->start, em->len);
  644. goto out;
  645. }
  646. if (em->flags != 0) {
  647. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  648. goto out;
  649. }
  650. if (em->orig_start != em->start) {
  651. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  652. em->orig_start);
  653. goto out;
  654. }
  655. offset = em->start + em->len;
  656. free_extent_map(em);
  657. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  658. if (IS_ERR(em)) {
  659. test_msg("Got an error when we shouldn't have\n");
  660. goto out;
  661. }
  662. if (em->block_start != disk_bytenr) {
  663. test_msg("Block start does not match, want %llu got %llu\n",
  664. disk_bytenr, em->block_start);
  665. goto out;
  666. }
  667. if (em->start != offset || em->len != 2 * sectorsize) {
  668. test_msg("Unexpected extent wanted start %llu len %u, "
  669. "got start %llu len %llu\n",
  670. offset, 2 * sectorsize, em->start, em->len);
  671. goto out;
  672. }
  673. if (em->flags != compressed_only) {
  674. test_msg("Unexpected flags set, want %lu have %lu\n",
  675. compressed_only, em->flags);
  676. goto out;
  677. }
  678. if (em->orig_start != orig_start) {
  679. test_msg("Wrong orig offset, want %llu, have %llu\n",
  680. em->start, orig_start);
  681. goto out;
  682. }
  683. if (em->compress_type != BTRFS_COMPRESS_ZLIB) {
  684. test_msg("Unexpected compress type, wanted %d, got %d\n",
  685. BTRFS_COMPRESS_ZLIB, em->compress_type);
  686. goto out;
  687. }
  688. offset = em->start + em->len;
  689. free_extent_map(em);
  690. /* A hole between regular extents but no hole extent */
  691. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset + 6,
  692. sectorsize, 0);
  693. if (IS_ERR(em)) {
  694. test_msg("Got an error when we shouldn't have\n");
  695. goto out;
  696. }
  697. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  698. test_msg("Expected a real extent, got %llu\n", em->block_start);
  699. goto out;
  700. }
  701. if (em->start != offset || em->len != sectorsize) {
  702. test_msg("Unexpected extent wanted start %llu len %u, "
  703. "got start %llu len %llu\n",
  704. offset, sectorsize, em->start, em->len);
  705. goto out;
  706. }
  707. if (em->flags != 0) {
  708. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  709. goto out;
  710. }
  711. if (em->orig_start != em->start) {
  712. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  713. em->orig_start);
  714. goto out;
  715. }
  716. offset = em->start + em->len;
  717. free_extent_map(em);
  718. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, SZ_4M, 0);
  719. if (IS_ERR(em)) {
  720. test_msg("Got an error when we shouldn't have\n");
  721. goto out;
  722. }
  723. if (em->block_start != EXTENT_MAP_HOLE) {
  724. test_msg("Expected a hole extent, got %llu\n", em->block_start);
  725. goto out;
  726. }
  727. /*
  728. * Currently we just return a length that we requested rather than the
  729. * length of the actual hole, if this changes we'll have to change this
  730. * test.
  731. */
  732. if (em->start != offset || em->len != 3 * sectorsize) {
  733. test_msg("Unexpected extent wanted start %llu len %u, "
  734. "got start %llu len %llu\n",
  735. offset, 3 * sectorsize, em->start, em->len);
  736. goto out;
  737. }
  738. if (em->flags != vacancy_only) {
  739. test_msg("Unexpected flags set, want %lu have %lu\n",
  740. vacancy_only, em->flags);
  741. goto out;
  742. }
  743. if (em->orig_start != em->start) {
  744. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  745. em->orig_start);
  746. goto out;
  747. }
  748. offset = em->start + em->len;
  749. free_extent_map(em);
  750. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  751. if (IS_ERR(em)) {
  752. test_msg("Got an error when we shouldn't have\n");
  753. goto out;
  754. }
  755. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  756. test_msg("Expected a real extent, got %llu\n", em->block_start);
  757. goto out;
  758. }
  759. if (em->start != offset || em->len != sectorsize) {
  760. test_msg("Unexpected extent wanted start %llu len %u,"
  761. "got start %llu len %llu\n",
  762. offset, sectorsize, em->start, em->len);
  763. goto out;
  764. }
  765. if (em->flags != 0) {
  766. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  767. goto out;
  768. }
  769. if (em->orig_start != em->start) {
  770. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  771. em->orig_start);
  772. goto out;
  773. }
  774. ret = 0;
  775. out:
  776. if (!IS_ERR(em))
  777. free_extent_map(em);
  778. iput(inode);
  779. btrfs_free_dummy_root(root);
  780. btrfs_free_dummy_fs_info(fs_info);
  781. return ret;
  782. }
  783. static int test_hole_first(u32 sectorsize, u32 nodesize)
  784. {
  785. struct btrfs_fs_info *fs_info = NULL;
  786. struct inode *inode = NULL;
  787. struct btrfs_root *root = NULL;
  788. struct extent_map *em = NULL;
  789. int ret = -ENOMEM;
  790. inode = btrfs_new_test_inode();
  791. if (!inode) {
  792. test_msg("Couldn't allocate inode\n");
  793. return ret;
  794. }
  795. BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
  796. BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
  797. BTRFS_I(inode)->location.offset = 0;
  798. fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
  799. if (!fs_info) {
  800. test_msg("Couldn't allocate dummy fs info\n");
  801. goto out;
  802. }
  803. root = btrfs_alloc_dummy_root(fs_info);
  804. if (IS_ERR(root)) {
  805. test_msg("Couldn't allocate root\n");
  806. goto out;
  807. }
  808. root->node = alloc_dummy_extent_buffer(fs_info, nodesize);
  809. if (!root->node) {
  810. test_msg("Couldn't allocate dummy buffer\n");
  811. goto out;
  812. }
  813. extent_buffer_get(root->node);
  814. btrfs_set_header_nritems(root->node, 0);
  815. btrfs_set_header_level(root->node, 0);
  816. BTRFS_I(inode)->root = root;
  817. ret = -EINVAL;
  818. /*
  819. * Need a blank inode item here just so we don't confuse
  820. * btrfs_get_extent.
  821. */
  822. insert_inode_item_key(root);
  823. insert_extent(root, sectorsize, sectorsize, sectorsize, 0, sectorsize,
  824. sectorsize, BTRFS_FILE_EXTENT_REG, 0, 1);
  825. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, 0, 2 * sectorsize, 0);
  826. if (IS_ERR(em)) {
  827. test_msg("Got an error when we shouldn't have\n");
  828. goto out;
  829. }
  830. if (em->block_start != EXTENT_MAP_HOLE) {
  831. test_msg("Expected a hole, got %llu\n", em->block_start);
  832. goto out;
  833. }
  834. if (em->start != 0 || em->len != sectorsize) {
  835. test_msg("Unexpected extent wanted start 0 len %u, "
  836. "got start %llu len %llu\n",
  837. sectorsize, em->start, em->len);
  838. goto out;
  839. }
  840. if (em->flags != vacancy_only) {
  841. test_msg("Wrong flags, wanted %lu, have %lu\n", vacancy_only,
  842. em->flags);
  843. goto out;
  844. }
  845. free_extent_map(em);
  846. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, sectorsize,
  847. 2 * sectorsize, 0);
  848. if (IS_ERR(em)) {
  849. test_msg("Got an error when we shouldn't have\n");
  850. goto out;
  851. }
  852. if (em->block_start != sectorsize) {
  853. test_msg("Expected a real extent, got %llu\n", em->block_start);
  854. goto out;
  855. }
  856. if (em->start != sectorsize || em->len != sectorsize) {
  857. test_msg("Unexpected extent wanted start %u len %u, "
  858. "got start %llu len %llu\n",
  859. sectorsize, sectorsize, em->start, em->len);
  860. goto out;
  861. }
  862. if (em->flags != 0) {
  863. test_msg("Unexpected flags set, wanted 0 got %lu\n",
  864. em->flags);
  865. goto out;
  866. }
  867. ret = 0;
  868. out:
  869. if (!IS_ERR(em))
  870. free_extent_map(em);
  871. iput(inode);
  872. btrfs_free_dummy_root(root);
  873. btrfs_free_dummy_fs_info(fs_info);
  874. return ret;
  875. }
  876. static int test_extent_accounting(u32 sectorsize, u32 nodesize)
  877. {
  878. struct btrfs_fs_info *fs_info = NULL;
  879. struct inode *inode = NULL;
  880. struct btrfs_root *root = NULL;
  881. int ret = -ENOMEM;
  882. inode = btrfs_new_test_inode();
  883. if (!inode) {
  884. test_msg("Couldn't allocate inode\n");
  885. return ret;
  886. }
  887. fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
  888. if (!fs_info) {
  889. test_msg("Couldn't allocate dummy fs info\n");
  890. goto out;
  891. }
  892. root = btrfs_alloc_dummy_root(fs_info);
  893. if (IS_ERR(root)) {
  894. test_msg("Couldn't allocate root\n");
  895. goto out;
  896. }
  897. BTRFS_I(inode)->root = root;
  898. btrfs_test_inode_set_ops(inode);
  899. /* [BTRFS_MAX_EXTENT_SIZE] */
  900. ret = btrfs_set_extent_delalloc(inode, 0, BTRFS_MAX_EXTENT_SIZE - 1, 0,
  901. NULL, 0);
  902. if (ret) {
  903. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  904. goto out;
  905. }
  906. if (BTRFS_I(inode)->outstanding_extents != 1) {
  907. ret = -EINVAL;
  908. test_msg("Miscount, wanted 1, got %u\n",
  909. BTRFS_I(inode)->outstanding_extents);
  910. goto out;
  911. }
  912. /* [BTRFS_MAX_EXTENT_SIZE][sectorsize] */
  913. ret = btrfs_set_extent_delalloc(inode, BTRFS_MAX_EXTENT_SIZE,
  914. BTRFS_MAX_EXTENT_SIZE + sectorsize - 1,
  915. 0, NULL, 0);
  916. if (ret) {
  917. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  918. goto out;
  919. }
  920. if (BTRFS_I(inode)->outstanding_extents != 2) {
  921. ret = -EINVAL;
  922. test_msg("Miscount, wanted 2, got %u\n",
  923. BTRFS_I(inode)->outstanding_extents);
  924. goto out;
  925. }
  926. /* [BTRFS_MAX_EXTENT_SIZE/2][sectorsize HOLE][the rest] */
  927. ret = clear_extent_bit(&BTRFS_I(inode)->io_tree,
  928. BTRFS_MAX_EXTENT_SIZE >> 1,
  929. (BTRFS_MAX_EXTENT_SIZE >> 1) + sectorsize - 1,
  930. EXTENT_DELALLOC | EXTENT_DIRTY |
  931. EXTENT_UPTODATE, 0, 0, NULL);
  932. if (ret) {
  933. test_msg("clear_extent_bit returned %d\n", ret);
  934. goto out;
  935. }
  936. if (BTRFS_I(inode)->outstanding_extents != 2) {
  937. ret = -EINVAL;
  938. test_msg("Miscount, wanted 2, got %u\n",
  939. BTRFS_I(inode)->outstanding_extents);
  940. goto out;
  941. }
  942. /* [BTRFS_MAX_EXTENT_SIZE][sectorsize] */
  943. ret = btrfs_set_extent_delalloc(inode, BTRFS_MAX_EXTENT_SIZE >> 1,
  944. (BTRFS_MAX_EXTENT_SIZE >> 1)
  945. + sectorsize - 1,
  946. 0, NULL, 0);
  947. if (ret) {
  948. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  949. goto out;
  950. }
  951. if (BTRFS_I(inode)->outstanding_extents != 2) {
  952. ret = -EINVAL;
  953. test_msg("Miscount, wanted 2, got %u\n",
  954. BTRFS_I(inode)->outstanding_extents);
  955. goto out;
  956. }
  957. /*
  958. * [BTRFS_MAX_EXTENT_SIZE+sectorsize][sectorsize HOLE][BTRFS_MAX_EXTENT_SIZE+sectorsize]
  959. */
  960. ret = btrfs_set_extent_delalloc(inode,
  961. BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize,
  962. (BTRFS_MAX_EXTENT_SIZE << 1) + 3 * sectorsize - 1,
  963. 0, NULL, 0);
  964. if (ret) {
  965. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  966. goto out;
  967. }
  968. if (BTRFS_I(inode)->outstanding_extents != 4) {
  969. ret = -EINVAL;
  970. test_msg("Miscount, wanted 4, got %u\n",
  971. BTRFS_I(inode)->outstanding_extents);
  972. goto out;
  973. }
  974. /*
  975. * [BTRFS_MAX_EXTENT_SIZE+sectorsize][sectorsize][BTRFS_MAX_EXTENT_SIZE+sectorsize]
  976. */
  977. ret = btrfs_set_extent_delalloc(inode,
  978. BTRFS_MAX_EXTENT_SIZE + sectorsize,
  979. BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, 0, NULL, 0);
  980. if (ret) {
  981. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  982. goto out;
  983. }
  984. if (BTRFS_I(inode)->outstanding_extents != 3) {
  985. ret = -EINVAL;
  986. test_msg("Miscount, wanted 3, got %u\n",
  987. BTRFS_I(inode)->outstanding_extents);
  988. goto out;
  989. }
  990. /* [BTRFS_MAX_EXTENT_SIZE+4k][4K HOLE][BTRFS_MAX_EXTENT_SIZE+4k] */
  991. ret = clear_extent_bit(&BTRFS_I(inode)->io_tree,
  992. BTRFS_MAX_EXTENT_SIZE + sectorsize,
  993. BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1,
  994. EXTENT_DIRTY | EXTENT_DELALLOC |
  995. EXTENT_UPTODATE, 0, 0, NULL);
  996. if (ret) {
  997. test_msg("clear_extent_bit returned %d\n", ret);
  998. goto out;
  999. }
  1000. if (BTRFS_I(inode)->outstanding_extents != 4) {
  1001. ret = -EINVAL;
  1002. test_msg("Miscount, wanted 4, got %u\n",
  1003. BTRFS_I(inode)->outstanding_extents);
  1004. goto out;
  1005. }
  1006. /*
  1007. * Refill the hole again just for good measure, because I thought it
  1008. * might fail and I'd rather satisfy my paranoia at this point.
  1009. */
  1010. ret = btrfs_set_extent_delalloc(inode,
  1011. BTRFS_MAX_EXTENT_SIZE + sectorsize,
  1012. BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, 0, NULL, 0);
  1013. if (ret) {
  1014. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  1015. goto out;
  1016. }
  1017. if (BTRFS_I(inode)->outstanding_extents != 3) {
  1018. ret = -EINVAL;
  1019. test_msg("Miscount, wanted 3, got %u\n",
  1020. BTRFS_I(inode)->outstanding_extents);
  1021. goto out;
  1022. }
  1023. /* Empty */
  1024. ret = clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1,
  1025. EXTENT_DIRTY | EXTENT_DELALLOC |
  1026. EXTENT_UPTODATE, 0, 0, NULL);
  1027. if (ret) {
  1028. test_msg("clear_extent_bit returned %d\n", ret);
  1029. goto out;
  1030. }
  1031. if (BTRFS_I(inode)->outstanding_extents) {
  1032. ret = -EINVAL;
  1033. test_msg("Miscount, wanted 0, got %u\n",
  1034. BTRFS_I(inode)->outstanding_extents);
  1035. goto out;
  1036. }
  1037. ret = 0;
  1038. out:
  1039. if (ret)
  1040. clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1,
  1041. EXTENT_DIRTY | EXTENT_DELALLOC |
  1042. EXTENT_UPTODATE, 0, 0, NULL);
  1043. iput(inode);
  1044. btrfs_free_dummy_root(root);
  1045. btrfs_free_dummy_fs_info(fs_info);
  1046. return ret;
  1047. }
  1048. int btrfs_test_inodes(u32 sectorsize, u32 nodesize)
  1049. {
  1050. int ret;
  1051. set_bit(EXTENT_FLAG_COMPRESSED, &compressed_only);
  1052. set_bit(EXTENT_FLAG_PREALLOC, &prealloc_only);
  1053. test_msg("Running btrfs_get_extent tests\n");
  1054. ret = test_btrfs_get_extent(sectorsize, nodesize);
  1055. if (ret)
  1056. return ret;
  1057. test_msg("Running hole first btrfs_get_extent test\n");
  1058. ret = test_hole_first(sectorsize, nodesize);
  1059. if (ret)
  1060. return ret;
  1061. test_msg("Running outstanding_extents tests\n");
  1062. return test_extent_accounting(sectorsize, nodesize);
  1063. }