inode-tests.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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. if (!test_bit(EXTENT_FLAG_VACANCY, &em->flags)) {
  260. test_msg("Vacancy flag wasn't set properly\n");
  261. goto out;
  262. }
  263. free_extent_map(em);
  264. btrfs_drop_extent_cache(BTRFS_I(inode), 0, (u64)-1, 0);
  265. /*
  266. * All of the magic numbers are based on the mapping setup in
  267. * setup_file_extents, so if you change anything there you need to
  268. * update the comment and update the expected values below.
  269. */
  270. setup_file_extents(root, sectorsize);
  271. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, 0, (u64)-1, 0);
  272. if (IS_ERR(em)) {
  273. test_msg("Got an error when we shouldn't have\n");
  274. goto out;
  275. }
  276. if (em->block_start != EXTENT_MAP_HOLE) {
  277. test_msg("Expected a hole, got %llu\n", em->block_start);
  278. goto out;
  279. }
  280. if (em->start != 0 || em->len != 5) {
  281. test_msg("Unexpected extent wanted start 0 len 5, got start "
  282. "%llu len %llu\n", em->start, em->len);
  283. goto out;
  284. }
  285. if (em->flags != 0) {
  286. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  287. goto out;
  288. }
  289. offset = em->start + em->len;
  290. free_extent_map(em);
  291. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  292. if (IS_ERR(em)) {
  293. test_msg("Got an error when we shouldn't have\n");
  294. goto out;
  295. }
  296. if (em->block_start != EXTENT_MAP_INLINE) {
  297. test_msg("Expected an inline, got %llu\n", em->block_start);
  298. goto out;
  299. }
  300. if (em->start != offset || em->len != (sectorsize - 5)) {
  301. test_msg("Unexpected extent wanted start %llu len 1, got start "
  302. "%llu len %llu\n", offset, em->start, em->len);
  303. goto out;
  304. }
  305. if (em->flags != 0) {
  306. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  307. goto out;
  308. }
  309. /*
  310. * We don't test anything else for inline since it doesn't get set
  311. * unless we have a page for it to write into. Maybe we should change
  312. * this?
  313. */
  314. offset = em->start + em->len;
  315. free_extent_map(em);
  316. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  317. if (IS_ERR(em)) {
  318. test_msg("Got an error when we shouldn't have\n");
  319. goto out;
  320. }
  321. if (em->block_start != EXTENT_MAP_HOLE) {
  322. test_msg("Expected a hole, got %llu\n", em->block_start);
  323. goto out;
  324. }
  325. if (em->start != offset || em->len != 4) {
  326. test_msg("Unexpected extent wanted start %llu len 4, got start "
  327. "%llu len %llu\n", offset, em->start, em->len);
  328. goto out;
  329. }
  330. if (em->flags != 0) {
  331. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  332. goto out;
  333. }
  334. offset = em->start + em->len;
  335. free_extent_map(em);
  336. /* Regular extent */
  337. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  338. if (IS_ERR(em)) {
  339. test_msg("Got an error when we shouldn't have\n");
  340. goto out;
  341. }
  342. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  343. test_msg("Expected a real extent, got %llu\n", em->block_start);
  344. goto out;
  345. }
  346. if (em->start != offset || em->len != sectorsize - 1) {
  347. test_msg("Unexpected extent wanted start %llu len 4095, got "
  348. "start %llu len %llu\n", offset, em->start, em->len);
  349. goto out;
  350. }
  351. if (em->flags != 0) {
  352. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  353. goto out;
  354. }
  355. if (em->orig_start != em->start) {
  356. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  357. em->orig_start);
  358. goto out;
  359. }
  360. offset = em->start + em->len;
  361. free_extent_map(em);
  362. /* The next 3 are split extents */
  363. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  364. if (IS_ERR(em)) {
  365. test_msg("Got an error when we shouldn't have\n");
  366. goto out;
  367. }
  368. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  369. test_msg("Expected a real extent, got %llu\n", em->block_start);
  370. goto out;
  371. }
  372. if (em->start != offset || em->len != sectorsize) {
  373. test_msg("Unexpected extent start %llu len %u, "
  374. "got start %llu len %llu\n",
  375. offset, sectorsize, em->start, em->len);
  376. goto out;
  377. }
  378. if (em->flags != 0) {
  379. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  380. goto out;
  381. }
  382. if (em->orig_start != em->start) {
  383. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  384. em->orig_start);
  385. goto out;
  386. }
  387. disk_bytenr = em->block_start;
  388. orig_start = em->start;
  389. offset = em->start + em->len;
  390. free_extent_map(em);
  391. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  392. if (IS_ERR(em)) {
  393. test_msg("Got an error when we shouldn't have\n");
  394. goto out;
  395. }
  396. if (em->block_start != EXTENT_MAP_HOLE) {
  397. test_msg("Expected a hole, got %llu\n", em->block_start);
  398. goto out;
  399. }
  400. if (em->start != offset || em->len != sectorsize) {
  401. test_msg("Unexpected extent wanted start %llu len %u, "
  402. "got start %llu len %llu\n",
  403. offset, sectorsize, em->start, em->len);
  404. goto out;
  405. }
  406. if (em->flags != 0) {
  407. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  408. goto out;
  409. }
  410. offset = em->start + em->len;
  411. free_extent_map(em);
  412. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  413. if (IS_ERR(em)) {
  414. test_msg("Got an error when we shouldn't have\n");
  415. goto out;
  416. }
  417. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  418. test_msg("Expected a real extent, got %llu\n", em->block_start);
  419. goto out;
  420. }
  421. if (em->start != offset || em->len != 2 * sectorsize) {
  422. test_msg("Unexpected extent wanted start %llu len %u, "
  423. "got start %llu len %llu\n",
  424. offset, 2 * sectorsize, em->start, em->len);
  425. goto out;
  426. }
  427. if (em->flags != 0) {
  428. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  429. goto out;
  430. }
  431. if (em->orig_start != orig_start) {
  432. test_msg("Wrong orig offset, want %llu, have %llu\n",
  433. orig_start, em->orig_start);
  434. goto out;
  435. }
  436. disk_bytenr += (em->start - orig_start);
  437. if (em->block_start != disk_bytenr) {
  438. test_msg("Wrong block start, want %llu, have %llu\n",
  439. disk_bytenr, em->block_start);
  440. goto out;
  441. }
  442. offset = em->start + em->len;
  443. free_extent_map(em);
  444. /* Prealloc extent */
  445. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  446. if (IS_ERR(em)) {
  447. test_msg("Got an error when we shouldn't have\n");
  448. goto out;
  449. }
  450. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  451. test_msg("Expected a real extent, got %llu\n", em->block_start);
  452. goto out;
  453. }
  454. if (em->start != offset || em->len != sectorsize) {
  455. test_msg("Unexpected extent wanted start %llu len %u, "
  456. "got start %llu len %llu\n",
  457. offset, sectorsize, em->start, em->len);
  458. goto out;
  459. }
  460. if (em->flags != prealloc_only) {
  461. test_msg("Unexpected flags set, want %lu have %lu\n",
  462. prealloc_only, em->flags);
  463. goto out;
  464. }
  465. if (em->orig_start != em->start) {
  466. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  467. em->orig_start);
  468. goto out;
  469. }
  470. offset = em->start + em->len;
  471. free_extent_map(em);
  472. /* The next 3 are a half written prealloc extent */
  473. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  474. if (IS_ERR(em)) {
  475. test_msg("Got an error when we shouldn't have\n");
  476. goto out;
  477. }
  478. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  479. test_msg("Expected a real extent, got %llu\n", em->block_start);
  480. goto out;
  481. }
  482. if (em->start != offset || em->len != sectorsize) {
  483. test_msg("Unexpected extent wanted start %llu len %u, "
  484. "got start %llu len %llu\n",
  485. offset, sectorsize, em->start, em->len);
  486. goto out;
  487. }
  488. if (em->flags != prealloc_only) {
  489. test_msg("Unexpected flags set, want %lu have %lu\n",
  490. prealloc_only, em->flags);
  491. goto out;
  492. }
  493. if (em->orig_start != em->start) {
  494. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  495. em->orig_start);
  496. goto out;
  497. }
  498. disk_bytenr = em->block_start;
  499. orig_start = em->start;
  500. offset = em->start + em->len;
  501. free_extent_map(em);
  502. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  503. if (IS_ERR(em)) {
  504. test_msg("Got an error when we shouldn't have\n");
  505. goto out;
  506. }
  507. if (em->block_start >= EXTENT_MAP_HOLE) {
  508. test_msg("Expected a real extent, got %llu\n", em->block_start);
  509. goto out;
  510. }
  511. if (em->start != offset || em->len != sectorsize) {
  512. test_msg("Unexpected extent wanted start %llu len %u, "
  513. "got start %llu len %llu\n",
  514. offset, sectorsize, em->start, em->len);
  515. goto out;
  516. }
  517. if (em->flags != 0) {
  518. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  519. goto out;
  520. }
  521. if (em->orig_start != orig_start) {
  522. test_msg("Unexpected orig offset, wanted %llu, have %llu\n",
  523. orig_start, em->orig_start);
  524. goto out;
  525. }
  526. if (em->block_start != (disk_bytenr + (em->start - em->orig_start))) {
  527. test_msg("Unexpected block start, wanted %llu, have %llu\n",
  528. disk_bytenr + (em->start - em->orig_start),
  529. em->block_start);
  530. goto out;
  531. }
  532. offset = em->start + em->len;
  533. free_extent_map(em);
  534. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  535. if (IS_ERR(em)) {
  536. test_msg("Got an error when we shouldn't have\n");
  537. goto out;
  538. }
  539. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  540. test_msg("Expected a real extent, got %llu\n", em->block_start);
  541. goto out;
  542. }
  543. if (em->start != offset || em->len != 2 * sectorsize) {
  544. test_msg("Unexpected extent wanted start %llu len %u, "
  545. "got start %llu len %llu\n",
  546. offset, 2 * sectorsize, em->start, em->len);
  547. goto out;
  548. }
  549. if (em->flags != prealloc_only) {
  550. test_msg("Unexpected flags set, want %lu have %lu\n",
  551. prealloc_only, em->flags);
  552. goto out;
  553. }
  554. if (em->orig_start != orig_start) {
  555. test_msg("Wrong orig offset, want %llu, have %llu\n", orig_start,
  556. em->orig_start);
  557. goto out;
  558. }
  559. if (em->block_start != (disk_bytenr + (em->start - em->orig_start))) {
  560. test_msg("Unexpected block start, wanted %llu, have %llu\n",
  561. disk_bytenr + (em->start - em->orig_start),
  562. em->block_start);
  563. goto out;
  564. }
  565. offset = em->start + em->len;
  566. free_extent_map(em);
  567. /* Now for the compressed extent */
  568. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  569. if (IS_ERR(em)) {
  570. test_msg("Got an error when we shouldn't have\n");
  571. goto out;
  572. }
  573. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  574. test_msg("Expected a real extent, got %llu\n", em->block_start);
  575. goto out;
  576. }
  577. if (em->start != offset || em->len != 2 * sectorsize) {
  578. test_msg("Unexpected extent wanted start %llu len %u,"
  579. "got start %llu len %llu\n",
  580. offset, 2 * sectorsize, em->start, em->len);
  581. goto out;
  582. }
  583. if (em->flags != compressed_only) {
  584. test_msg("Unexpected flags set, want %lu have %lu\n",
  585. compressed_only, em->flags);
  586. goto out;
  587. }
  588. if (em->orig_start != em->start) {
  589. test_msg("Wrong orig offset, want %llu, have %llu\n",
  590. em->start, em->orig_start);
  591. goto out;
  592. }
  593. if (em->compress_type != BTRFS_COMPRESS_ZLIB) {
  594. test_msg("Unexpected compress type, wanted %d, got %d\n",
  595. BTRFS_COMPRESS_ZLIB, em->compress_type);
  596. goto out;
  597. }
  598. offset = em->start + em->len;
  599. free_extent_map(em);
  600. /* Split compressed extent */
  601. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  602. if (IS_ERR(em)) {
  603. test_msg("Got an error when we shouldn't have\n");
  604. goto out;
  605. }
  606. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  607. test_msg("Expected a real extent, got %llu\n", em->block_start);
  608. goto out;
  609. }
  610. if (em->start != offset || em->len != sectorsize) {
  611. test_msg("Unexpected extent wanted start %llu len %u,"
  612. "got start %llu len %llu\n",
  613. offset, sectorsize, em->start, em->len);
  614. goto out;
  615. }
  616. if (em->flags != compressed_only) {
  617. test_msg("Unexpected flags set, want %lu have %lu\n",
  618. compressed_only, em->flags);
  619. goto out;
  620. }
  621. if (em->orig_start != em->start) {
  622. test_msg("Wrong orig offset, want %llu, have %llu\n",
  623. em->start, em->orig_start);
  624. goto out;
  625. }
  626. if (em->compress_type != BTRFS_COMPRESS_ZLIB) {
  627. test_msg("Unexpected compress type, wanted %d, got %d\n",
  628. BTRFS_COMPRESS_ZLIB, em->compress_type);
  629. goto out;
  630. }
  631. disk_bytenr = em->block_start;
  632. orig_start = em->start;
  633. offset = em->start + em->len;
  634. free_extent_map(em);
  635. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  636. if (IS_ERR(em)) {
  637. test_msg("Got an error when we shouldn't have\n");
  638. goto out;
  639. }
  640. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  641. test_msg("Expected a real extent, got %llu\n", em->block_start);
  642. goto out;
  643. }
  644. if (em->start != offset || em->len != sectorsize) {
  645. test_msg("Unexpected extent wanted start %llu len %u, "
  646. "got start %llu len %llu\n",
  647. offset, sectorsize, em->start, em->len);
  648. goto out;
  649. }
  650. if (em->flags != 0) {
  651. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  652. goto out;
  653. }
  654. if (em->orig_start != em->start) {
  655. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  656. em->orig_start);
  657. goto out;
  658. }
  659. offset = em->start + em->len;
  660. free_extent_map(em);
  661. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  662. if (IS_ERR(em)) {
  663. test_msg("Got an error when we shouldn't have\n");
  664. goto out;
  665. }
  666. if (em->block_start != disk_bytenr) {
  667. test_msg("Block start does not match, want %llu got %llu\n",
  668. disk_bytenr, em->block_start);
  669. goto out;
  670. }
  671. if (em->start != offset || em->len != 2 * sectorsize) {
  672. test_msg("Unexpected extent wanted start %llu len %u, "
  673. "got start %llu len %llu\n",
  674. offset, 2 * sectorsize, em->start, em->len);
  675. goto out;
  676. }
  677. if (em->flags != compressed_only) {
  678. test_msg("Unexpected flags set, want %lu have %lu\n",
  679. compressed_only, em->flags);
  680. goto out;
  681. }
  682. if (em->orig_start != orig_start) {
  683. test_msg("Wrong orig offset, want %llu, have %llu\n",
  684. em->start, orig_start);
  685. goto out;
  686. }
  687. if (em->compress_type != BTRFS_COMPRESS_ZLIB) {
  688. test_msg("Unexpected compress type, wanted %d, got %d\n",
  689. BTRFS_COMPRESS_ZLIB, em->compress_type);
  690. goto out;
  691. }
  692. offset = em->start + em->len;
  693. free_extent_map(em);
  694. /* A hole between regular extents but no hole extent */
  695. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset + 6,
  696. sectorsize, 0);
  697. if (IS_ERR(em)) {
  698. test_msg("Got an error when we shouldn't have\n");
  699. goto out;
  700. }
  701. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  702. test_msg("Expected a real extent, got %llu\n", em->block_start);
  703. goto out;
  704. }
  705. if (em->start != offset || em->len != sectorsize) {
  706. test_msg("Unexpected extent wanted start %llu len %u, "
  707. "got start %llu len %llu\n",
  708. offset, sectorsize, em->start, em->len);
  709. goto out;
  710. }
  711. if (em->flags != 0) {
  712. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  713. goto out;
  714. }
  715. if (em->orig_start != em->start) {
  716. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  717. em->orig_start);
  718. goto out;
  719. }
  720. offset = em->start + em->len;
  721. free_extent_map(em);
  722. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, SZ_4M, 0);
  723. if (IS_ERR(em)) {
  724. test_msg("Got an error when we shouldn't have\n");
  725. goto out;
  726. }
  727. if (em->block_start != EXTENT_MAP_HOLE) {
  728. test_msg("Expected a hole extent, got %llu\n", em->block_start);
  729. goto out;
  730. }
  731. /*
  732. * Currently we just return a length that we requested rather than the
  733. * length of the actual hole, if this changes we'll have to change this
  734. * test.
  735. */
  736. if (em->start != offset || em->len != 3 * sectorsize) {
  737. test_msg("Unexpected extent wanted start %llu len %u, "
  738. "got start %llu len %llu\n",
  739. offset, 3 * sectorsize, em->start, em->len);
  740. goto out;
  741. }
  742. if (em->flags != vacancy_only) {
  743. test_msg("Unexpected flags set, want %lu have %lu\n",
  744. vacancy_only, em->flags);
  745. goto out;
  746. }
  747. if (em->orig_start != em->start) {
  748. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  749. em->orig_start);
  750. goto out;
  751. }
  752. offset = em->start + em->len;
  753. free_extent_map(em);
  754. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, offset, sectorsize, 0);
  755. if (IS_ERR(em)) {
  756. test_msg("Got an error when we shouldn't have\n");
  757. goto out;
  758. }
  759. if (em->block_start >= EXTENT_MAP_LAST_BYTE) {
  760. test_msg("Expected a real extent, got %llu\n", em->block_start);
  761. goto out;
  762. }
  763. if (em->start != offset || em->len != sectorsize) {
  764. test_msg("Unexpected extent wanted start %llu len %u,"
  765. "got start %llu len %llu\n",
  766. offset, sectorsize, em->start, em->len);
  767. goto out;
  768. }
  769. if (em->flags != 0) {
  770. test_msg("Unexpected flags set, want 0 have %lu\n", em->flags);
  771. goto out;
  772. }
  773. if (em->orig_start != em->start) {
  774. test_msg("Wrong orig offset, want %llu, have %llu\n", em->start,
  775. em->orig_start);
  776. goto out;
  777. }
  778. ret = 0;
  779. out:
  780. if (!IS_ERR(em))
  781. free_extent_map(em);
  782. iput(inode);
  783. btrfs_free_dummy_root(root);
  784. btrfs_free_dummy_fs_info(fs_info);
  785. return ret;
  786. }
  787. static int test_hole_first(u32 sectorsize, u32 nodesize)
  788. {
  789. struct btrfs_fs_info *fs_info = NULL;
  790. struct inode *inode = NULL;
  791. struct btrfs_root *root = NULL;
  792. struct extent_map *em = NULL;
  793. int ret = -ENOMEM;
  794. inode = btrfs_new_test_inode();
  795. if (!inode) {
  796. test_msg("Couldn't allocate inode\n");
  797. return ret;
  798. }
  799. BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
  800. BTRFS_I(inode)->location.objectid = BTRFS_FIRST_FREE_OBJECTID;
  801. BTRFS_I(inode)->location.offset = 0;
  802. fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
  803. if (!fs_info) {
  804. test_msg("Couldn't allocate dummy fs info\n");
  805. goto out;
  806. }
  807. root = btrfs_alloc_dummy_root(fs_info);
  808. if (IS_ERR(root)) {
  809. test_msg("Couldn't allocate root\n");
  810. goto out;
  811. }
  812. root->node = alloc_dummy_extent_buffer(fs_info, nodesize);
  813. if (!root->node) {
  814. test_msg("Couldn't allocate dummy buffer\n");
  815. goto out;
  816. }
  817. extent_buffer_get(root->node);
  818. btrfs_set_header_nritems(root->node, 0);
  819. btrfs_set_header_level(root->node, 0);
  820. BTRFS_I(inode)->root = root;
  821. ret = -EINVAL;
  822. /*
  823. * Need a blank inode item here just so we don't confuse
  824. * btrfs_get_extent.
  825. */
  826. insert_inode_item_key(root);
  827. insert_extent(root, sectorsize, sectorsize, sectorsize, 0, sectorsize,
  828. sectorsize, BTRFS_FILE_EXTENT_REG, 0, 1);
  829. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, 0, 2 * sectorsize, 0);
  830. if (IS_ERR(em)) {
  831. test_msg("Got an error when we shouldn't have\n");
  832. goto out;
  833. }
  834. if (em->block_start != EXTENT_MAP_HOLE) {
  835. test_msg("Expected a hole, got %llu\n", em->block_start);
  836. goto out;
  837. }
  838. if (em->start != 0 || em->len != sectorsize) {
  839. test_msg("Unexpected extent wanted start 0 len %u, "
  840. "got start %llu len %llu\n",
  841. sectorsize, em->start, em->len);
  842. goto out;
  843. }
  844. if (em->flags != vacancy_only) {
  845. test_msg("Wrong flags, wanted %lu, have %lu\n", vacancy_only,
  846. em->flags);
  847. goto out;
  848. }
  849. free_extent_map(em);
  850. em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, sectorsize,
  851. 2 * sectorsize, 0);
  852. if (IS_ERR(em)) {
  853. test_msg("Got an error when we shouldn't have\n");
  854. goto out;
  855. }
  856. if (em->block_start != sectorsize) {
  857. test_msg("Expected a real extent, got %llu\n", em->block_start);
  858. goto out;
  859. }
  860. if (em->start != sectorsize || em->len != sectorsize) {
  861. test_msg("Unexpected extent wanted start %u len %u, "
  862. "got start %llu len %llu\n",
  863. sectorsize, sectorsize, em->start, em->len);
  864. goto out;
  865. }
  866. if (em->flags != 0) {
  867. test_msg("Unexpected flags set, wanted 0 got %lu\n",
  868. em->flags);
  869. goto out;
  870. }
  871. ret = 0;
  872. out:
  873. if (!IS_ERR(em))
  874. free_extent_map(em);
  875. iput(inode);
  876. btrfs_free_dummy_root(root);
  877. btrfs_free_dummy_fs_info(fs_info);
  878. return ret;
  879. }
  880. static int test_extent_accounting(u32 sectorsize, u32 nodesize)
  881. {
  882. struct btrfs_fs_info *fs_info = NULL;
  883. struct inode *inode = NULL;
  884. struct btrfs_root *root = NULL;
  885. int ret = -ENOMEM;
  886. inode = btrfs_new_test_inode();
  887. if (!inode) {
  888. test_msg("Couldn't allocate inode\n");
  889. return ret;
  890. }
  891. fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
  892. if (!fs_info) {
  893. test_msg("Couldn't allocate dummy fs info\n");
  894. goto out;
  895. }
  896. root = btrfs_alloc_dummy_root(fs_info);
  897. if (IS_ERR(root)) {
  898. test_msg("Couldn't allocate root\n");
  899. goto out;
  900. }
  901. BTRFS_I(inode)->root = root;
  902. btrfs_test_inode_set_ops(inode);
  903. /* [BTRFS_MAX_EXTENT_SIZE] */
  904. ret = btrfs_set_extent_delalloc(inode, 0, BTRFS_MAX_EXTENT_SIZE - 1, 0,
  905. NULL, 0);
  906. if (ret) {
  907. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  908. goto out;
  909. }
  910. if (BTRFS_I(inode)->outstanding_extents != 1) {
  911. ret = -EINVAL;
  912. test_msg("Miscount, wanted 1, got %u\n",
  913. BTRFS_I(inode)->outstanding_extents);
  914. goto out;
  915. }
  916. /* [BTRFS_MAX_EXTENT_SIZE][sectorsize] */
  917. ret = btrfs_set_extent_delalloc(inode, BTRFS_MAX_EXTENT_SIZE,
  918. BTRFS_MAX_EXTENT_SIZE + sectorsize - 1,
  919. 0, NULL, 0);
  920. if (ret) {
  921. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  922. goto out;
  923. }
  924. if (BTRFS_I(inode)->outstanding_extents != 2) {
  925. ret = -EINVAL;
  926. test_msg("Miscount, wanted 2, got %u\n",
  927. BTRFS_I(inode)->outstanding_extents);
  928. goto out;
  929. }
  930. /* [BTRFS_MAX_EXTENT_SIZE/2][sectorsize HOLE][the rest] */
  931. ret = clear_extent_bit(&BTRFS_I(inode)->io_tree,
  932. BTRFS_MAX_EXTENT_SIZE >> 1,
  933. (BTRFS_MAX_EXTENT_SIZE >> 1) + sectorsize - 1,
  934. EXTENT_DELALLOC | EXTENT_DIRTY |
  935. EXTENT_UPTODATE, 0, 0,
  936. NULL, GFP_KERNEL);
  937. if (ret) {
  938. test_msg("clear_extent_bit returned %d\n", ret);
  939. goto out;
  940. }
  941. if (BTRFS_I(inode)->outstanding_extents != 2) {
  942. ret = -EINVAL;
  943. test_msg("Miscount, wanted 2, got %u\n",
  944. BTRFS_I(inode)->outstanding_extents);
  945. goto out;
  946. }
  947. /* [BTRFS_MAX_EXTENT_SIZE][sectorsize] */
  948. ret = btrfs_set_extent_delalloc(inode, BTRFS_MAX_EXTENT_SIZE >> 1,
  949. (BTRFS_MAX_EXTENT_SIZE >> 1)
  950. + sectorsize - 1,
  951. 0, NULL, 0);
  952. if (ret) {
  953. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  954. goto out;
  955. }
  956. if (BTRFS_I(inode)->outstanding_extents != 2) {
  957. ret = -EINVAL;
  958. test_msg("Miscount, wanted 2, got %u\n",
  959. BTRFS_I(inode)->outstanding_extents);
  960. goto out;
  961. }
  962. /*
  963. * [BTRFS_MAX_EXTENT_SIZE+sectorsize][sectorsize HOLE][BTRFS_MAX_EXTENT_SIZE+sectorsize]
  964. */
  965. ret = btrfs_set_extent_delalloc(inode,
  966. BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize,
  967. (BTRFS_MAX_EXTENT_SIZE << 1) + 3 * sectorsize - 1,
  968. 0, NULL, 0);
  969. if (ret) {
  970. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  971. goto out;
  972. }
  973. if (BTRFS_I(inode)->outstanding_extents != 4) {
  974. ret = -EINVAL;
  975. test_msg("Miscount, wanted 4, got %u\n",
  976. BTRFS_I(inode)->outstanding_extents);
  977. goto out;
  978. }
  979. /*
  980. * [BTRFS_MAX_EXTENT_SIZE+sectorsize][sectorsize][BTRFS_MAX_EXTENT_SIZE+sectorsize]
  981. */
  982. ret = btrfs_set_extent_delalloc(inode,
  983. BTRFS_MAX_EXTENT_SIZE + sectorsize,
  984. BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, 0, NULL, 0);
  985. if (ret) {
  986. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  987. goto out;
  988. }
  989. if (BTRFS_I(inode)->outstanding_extents != 3) {
  990. ret = -EINVAL;
  991. test_msg("Miscount, wanted 3, got %u\n",
  992. BTRFS_I(inode)->outstanding_extents);
  993. goto out;
  994. }
  995. /* [BTRFS_MAX_EXTENT_SIZE+4k][4K HOLE][BTRFS_MAX_EXTENT_SIZE+4k] */
  996. ret = clear_extent_bit(&BTRFS_I(inode)->io_tree,
  997. BTRFS_MAX_EXTENT_SIZE + sectorsize,
  998. BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1,
  999. EXTENT_DIRTY | EXTENT_DELALLOC |
  1000. EXTENT_UPTODATE, 0, 0,
  1001. NULL, GFP_KERNEL);
  1002. if (ret) {
  1003. test_msg("clear_extent_bit returned %d\n", ret);
  1004. goto out;
  1005. }
  1006. if (BTRFS_I(inode)->outstanding_extents != 4) {
  1007. ret = -EINVAL;
  1008. test_msg("Miscount, wanted 4, got %u\n",
  1009. BTRFS_I(inode)->outstanding_extents);
  1010. goto out;
  1011. }
  1012. /*
  1013. * Refill the hole again just for good measure, because I thought it
  1014. * might fail and I'd rather satisfy my paranoia at this point.
  1015. */
  1016. ret = btrfs_set_extent_delalloc(inode,
  1017. BTRFS_MAX_EXTENT_SIZE + sectorsize,
  1018. BTRFS_MAX_EXTENT_SIZE + 2 * sectorsize - 1, 0, NULL, 0);
  1019. if (ret) {
  1020. test_msg("btrfs_set_extent_delalloc returned %d\n", ret);
  1021. goto out;
  1022. }
  1023. if (BTRFS_I(inode)->outstanding_extents != 3) {
  1024. ret = -EINVAL;
  1025. test_msg("Miscount, wanted 3, got %u\n",
  1026. BTRFS_I(inode)->outstanding_extents);
  1027. goto out;
  1028. }
  1029. /* Empty */
  1030. ret = clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1,
  1031. EXTENT_DIRTY | EXTENT_DELALLOC |
  1032. EXTENT_UPTODATE, 0, 0,
  1033. NULL, GFP_KERNEL);
  1034. if (ret) {
  1035. test_msg("clear_extent_bit returned %d\n", ret);
  1036. goto out;
  1037. }
  1038. if (BTRFS_I(inode)->outstanding_extents) {
  1039. ret = -EINVAL;
  1040. test_msg("Miscount, wanted 0, got %u\n",
  1041. BTRFS_I(inode)->outstanding_extents);
  1042. goto out;
  1043. }
  1044. ret = 0;
  1045. out:
  1046. if (ret)
  1047. clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, (u64)-1,
  1048. EXTENT_DIRTY | EXTENT_DELALLOC |
  1049. EXTENT_UPTODATE, 0, 0,
  1050. NULL, GFP_KERNEL);
  1051. iput(inode);
  1052. btrfs_free_dummy_root(root);
  1053. btrfs_free_dummy_fs_info(fs_info);
  1054. return ret;
  1055. }
  1056. int btrfs_test_inodes(u32 sectorsize, u32 nodesize)
  1057. {
  1058. int ret;
  1059. set_bit(EXTENT_FLAG_COMPRESSED, &compressed_only);
  1060. set_bit(EXTENT_FLAG_VACANCY, &vacancy_only);
  1061. set_bit(EXTENT_FLAG_PREALLOC, &prealloc_only);
  1062. test_msg("Running btrfs_get_extent tests\n");
  1063. ret = test_btrfs_get_extent(sectorsize, nodesize);
  1064. if (ret)
  1065. return ret;
  1066. test_msg("Running hole first btrfs_get_extent test\n");
  1067. ret = test_hole_first(sectorsize, nodesize);
  1068. if (ret)
  1069. return ret;
  1070. test_msg("Running outstanding_extents tests\n");
  1071. return test_extent_accounting(sectorsize, nodesize);
  1072. }