PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/linux-2.6.33/kernel/linux-2.6.33/fs/xfs/xfs_alloc.c

https://bitbucket.org/microcreat/cortexm_uclinux
C | 2603 lines | 1813 code | 129 blank | 661 comment | 461 complexity | b4fb12d2c36e8ce1ccae689878f96e90 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_bit.h"
  22. #include "xfs_log.h"
  23. #include "xfs_inum.h"
  24. #include "xfs_trans.h"
  25. #include "xfs_sb.h"
  26. #include "xfs_ag.h"
  27. #include "xfs_dir2.h"
  28. #include "xfs_dmapi.h"
  29. #include "xfs_mount.h"
  30. #include "xfs_bmap_btree.h"
  31. #include "xfs_alloc_btree.h"
  32. #include "xfs_ialloc_btree.h"
  33. #include "xfs_dir2_sf.h"
  34. #include "xfs_attr_sf.h"
  35. #include "xfs_dinode.h"
  36. #include "xfs_inode.h"
  37. #include "xfs_btree.h"
  38. #include "xfs_ialloc.h"
  39. #include "xfs_alloc.h"
  40. #include "xfs_error.h"
  41. #include "xfs_trace.h"
  42. #define XFS_ABSDIFF(a,b) (((a) <= (b)) ? ((b) - (a)) : ((a) - (b)))
  43. #define XFSA_FIXUP_BNO_OK 1
  44. #define XFSA_FIXUP_CNT_OK 2
  45. STATIC void
  46. xfs_alloc_search_busy(xfs_trans_t *tp,
  47. xfs_agnumber_t agno,
  48. xfs_agblock_t bno,
  49. xfs_extlen_t len);
  50. /*
  51. * Prototypes for per-ag allocation routines
  52. */
  53. STATIC int xfs_alloc_ag_vextent_exact(xfs_alloc_arg_t *);
  54. STATIC int xfs_alloc_ag_vextent_near(xfs_alloc_arg_t *);
  55. STATIC int xfs_alloc_ag_vextent_size(xfs_alloc_arg_t *);
  56. STATIC int xfs_alloc_ag_vextent_small(xfs_alloc_arg_t *,
  57. xfs_btree_cur_t *, xfs_agblock_t *, xfs_extlen_t *, int *);
  58. /*
  59. * Internal functions.
  60. */
  61. /*
  62. * Lookup the record equal to [bno, len] in the btree given by cur.
  63. */
  64. STATIC int /* error */
  65. xfs_alloc_lookup_eq(
  66. struct xfs_btree_cur *cur, /* btree cursor */
  67. xfs_agblock_t bno, /* starting block of extent */
  68. xfs_extlen_t len, /* length of extent */
  69. int *stat) /* success/failure */
  70. {
  71. cur->bc_rec.a.ar_startblock = bno;
  72. cur->bc_rec.a.ar_blockcount = len;
  73. return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
  74. }
  75. /*
  76. * Lookup the first record greater than or equal to [bno, len]
  77. * in the btree given by cur.
  78. */
  79. STATIC int /* error */
  80. xfs_alloc_lookup_ge(
  81. struct xfs_btree_cur *cur, /* btree cursor */
  82. xfs_agblock_t bno, /* starting block of extent */
  83. xfs_extlen_t len, /* length of extent */
  84. int *stat) /* success/failure */
  85. {
  86. cur->bc_rec.a.ar_startblock = bno;
  87. cur->bc_rec.a.ar_blockcount = len;
  88. return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
  89. }
  90. /*
  91. * Lookup the first record less than or equal to [bno, len]
  92. * in the btree given by cur.
  93. */
  94. STATIC int /* error */
  95. xfs_alloc_lookup_le(
  96. struct xfs_btree_cur *cur, /* btree cursor */
  97. xfs_agblock_t bno, /* starting block of extent */
  98. xfs_extlen_t len, /* length of extent */
  99. int *stat) /* success/failure */
  100. {
  101. cur->bc_rec.a.ar_startblock = bno;
  102. cur->bc_rec.a.ar_blockcount = len;
  103. return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
  104. }
  105. /*
  106. * Update the record referred to by cur to the value given
  107. * by [bno, len].
  108. * This either works (return 0) or gets an EFSCORRUPTED error.
  109. */
  110. STATIC int /* error */
  111. xfs_alloc_update(
  112. struct xfs_btree_cur *cur, /* btree cursor */
  113. xfs_agblock_t bno, /* starting block of extent */
  114. xfs_extlen_t len) /* length of extent */
  115. {
  116. union xfs_btree_rec rec;
  117. rec.alloc.ar_startblock = cpu_to_be32(bno);
  118. rec.alloc.ar_blockcount = cpu_to_be32(len);
  119. return xfs_btree_update(cur, &rec);
  120. }
  121. /*
  122. * Get the data from the pointed-to record.
  123. */
  124. STATIC int /* error */
  125. xfs_alloc_get_rec(
  126. struct xfs_btree_cur *cur, /* btree cursor */
  127. xfs_agblock_t *bno, /* output: starting block of extent */
  128. xfs_extlen_t *len, /* output: length of extent */
  129. int *stat) /* output: success/failure */
  130. {
  131. union xfs_btree_rec *rec;
  132. int error;
  133. error = xfs_btree_get_rec(cur, &rec, stat);
  134. if (!error && *stat == 1) {
  135. *bno = be32_to_cpu(rec->alloc.ar_startblock);
  136. *len = be32_to_cpu(rec->alloc.ar_blockcount);
  137. }
  138. return error;
  139. }
  140. /*
  141. * Compute aligned version of the found extent.
  142. * Takes alignment and min length into account.
  143. */
  144. STATIC void
  145. xfs_alloc_compute_aligned(
  146. xfs_agblock_t foundbno, /* starting block in found extent */
  147. xfs_extlen_t foundlen, /* length in found extent */
  148. xfs_extlen_t alignment, /* alignment for allocation */
  149. xfs_extlen_t minlen, /* minimum length for allocation */
  150. xfs_agblock_t *resbno, /* result block number */
  151. xfs_extlen_t *reslen) /* result length */
  152. {
  153. xfs_agblock_t bno;
  154. xfs_extlen_t diff;
  155. xfs_extlen_t len;
  156. if (alignment > 1 && foundlen >= minlen) {
  157. bno = roundup(foundbno, alignment);
  158. diff = bno - foundbno;
  159. len = diff >= foundlen ? 0 : foundlen - diff;
  160. } else {
  161. bno = foundbno;
  162. len = foundlen;
  163. }
  164. *resbno = bno;
  165. *reslen = len;
  166. }
  167. /*
  168. * Compute best start block and diff for "near" allocations.
  169. * freelen >= wantlen already checked by caller.
  170. */
  171. STATIC xfs_extlen_t /* difference value (absolute) */
  172. xfs_alloc_compute_diff(
  173. xfs_agblock_t wantbno, /* target starting block */
  174. xfs_extlen_t wantlen, /* target length */
  175. xfs_extlen_t alignment, /* target alignment */
  176. xfs_agblock_t freebno, /* freespace's starting block */
  177. xfs_extlen_t freelen, /* freespace's length */
  178. xfs_agblock_t *newbnop) /* result: best start block from free */
  179. {
  180. xfs_agblock_t freeend; /* end of freespace extent */
  181. xfs_agblock_t newbno1; /* return block number */
  182. xfs_agblock_t newbno2; /* other new block number */
  183. xfs_extlen_t newlen1=0; /* length with newbno1 */
  184. xfs_extlen_t newlen2=0; /* length with newbno2 */
  185. xfs_agblock_t wantend; /* end of target extent */
  186. ASSERT(freelen >= wantlen);
  187. freeend = freebno + freelen;
  188. wantend = wantbno + wantlen;
  189. if (freebno >= wantbno) {
  190. if ((newbno1 = roundup(freebno, alignment)) >= freeend)
  191. newbno1 = NULLAGBLOCK;
  192. } else if (freeend >= wantend && alignment > 1) {
  193. newbno1 = roundup(wantbno, alignment);
  194. newbno2 = newbno1 - alignment;
  195. if (newbno1 >= freeend)
  196. newbno1 = NULLAGBLOCK;
  197. else
  198. newlen1 = XFS_EXTLEN_MIN(wantlen, freeend - newbno1);
  199. if (newbno2 < freebno)
  200. newbno2 = NULLAGBLOCK;
  201. else
  202. newlen2 = XFS_EXTLEN_MIN(wantlen, freeend - newbno2);
  203. if (newbno1 != NULLAGBLOCK && newbno2 != NULLAGBLOCK) {
  204. if (newlen1 < newlen2 ||
  205. (newlen1 == newlen2 &&
  206. XFS_ABSDIFF(newbno1, wantbno) >
  207. XFS_ABSDIFF(newbno2, wantbno)))
  208. newbno1 = newbno2;
  209. } else if (newbno2 != NULLAGBLOCK)
  210. newbno1 = newbno2;
  211. } else if (freeend >= wantend) {
  212. newbno1 = wantbno;
  213. } else if (alignment > 1) {
  214. newbno1 = roundup(freeend - wantlen, alignment);
  215. if (newbno1 > freeend - wantlen &&
  216. newbno1 - alignment >= freebno)
  217. newbno1 -= alignment;
  218. else if (newbno1 >= freeend)
  219. newbno1 = NULLAGBLOCK;
  220. } else
  221. newbno1 = freeend - wantlen;
  222. *newbnop = newbno1;
  223. return newbno1 == NULLAGBLOCK ? 0 : XFS_ABSDIFF(newbno1, wantbno);
  224. }
  225. /*
  226. * Fix up the length, based on mod and prod.
  227. * len should be k * prod + mod for some k.
  228. * If len is too small it is returned unchanged.
  229. * If len hits maxlen it is left alone.
  230. */
  231. STATIC void
  232. xfs_alloc_fix_len(
  233. xfs_alloc_arg_t *args) /* allocation argument structure */
  234. {
  235. xfs_extlen_t k;
  236. xfs_extlen_t rlen;
  237. ASSERT(args->mod < args->prod);
  238. rlen = args->len;
  239. ASSERT(rlen >= args->minlen);
  240. ASSERT(rlen <= args->maxlen);
  241. if (args->prod <= 1 || rlen < args->mod || rlen == args->maxlen ||
  242. (args->mod == 0 && rlen < args->prod))
  243. return;
  244. k = rlen % args->prod;
  245. if (k == args->mod)
  246. return;
  247. if (k > args->mod) {
  248. if ((int)(rlen = rlen - k - args->mod) < (int)args->minlen)
  249. return;
  250. } else {
  251. if ((int)(rlen = rlen - args->prod - (args->mod - k)) <
  252. (int)args->minlen)
  253. return;
  254. }
  255. ASSERT(rlen >= args->minlen);
  256. ASSERT(rlen <= args->maxlen);
  257. args->len = rlen;
  258. }
  259. /*
  260. * Fix up length if there is too little space left in the a.g.
  261. * Return 1 if ok, 0 if too little, should give up.
  262. */
  263. STATIC int
  264. xfs_alloc_fix_minleft(
  265. xfs_alloc_arg_t *args) /* allocation argument structure */
  266. {
  267. xfs_agf_t *agf; /* a.g. freelist header */
  268. int diff; /* free space difference */
  269. if (args->minleft == 0)
  270. return 1;
  271. agf = XFS_BUF_TO_AGF(args->agbp);
  272. diff = be32_to_cpu(agf->agf_freeblks)
  273. + be32_to_cpu(agf->agf_flcount)
  274. - args->len - args->minleft;
  275. if (diff >= 0)
  276. return 1;
  277. args->len += diff; /* shrink the allocated space */
  278. if (args->len >= args->minlen)
  279. return 1;
  280. args->agbno = NULLAGBLOCK;
  281. return 0;
  282. }
  283. /*
  284. * Update the two btrees, logically removing from freespace the extent
  285. * starting at rbno, rlen blocks. The extent is contained within the
  286. * actual (current) free extent fbno for flen blocks.
  287. * Flags are passed in indicating whether the cursors are set to the
  288. * relevant records.
  289. */
  290. STATIC int /* error code */
  291. xfs_alloc_fixup_trees(
  292. xfs_btree_cur_t *cnt_cur, /* cursor for by-size btree */
  293. xfs_btree_cur_t *bno_cur, /* cursor for by-block btree */
  294. xfs_agblock_t fbno, /* starting block of free extent */
  295. xfs_extlen_t flen, /* length of free extent */
  296. xfs_agblock_t rbno, /* starting block of returned extent */
  297. xfs_extlen_t rlen, /* length of returned extent */
  298. int flags) /* flags, XFSA_FIXUP_... */
  299. {
  300. int error; /* error code */
  301. int i; /* operation results */
  302. xfs_agblock_t nfbno1; /* first new free startblock */
  303. xfs_agblock_t nfbno2; /* second new free startblock */
  304. xfs_extlen_t nflen1=0; /* first new free length */
  305. xfs_extlen_t nflen2=0; /* second new free length */
  306. /*
  307. * Look up the record in the by-size tree if necessary.
  308. */
  309. if (flags & XFSA_FIXUP_CNT_OK) {
  310. #ifdef DEBUG
  311. if ((error = xfs_alloc_get_rec(cnt_cur, &nfbno1, &nflen1, &i)))
  312. return error;
  313. XFS_WANT_CORRUPTED_RETURN(
  314. i == 1 && nfbno1 == fbno && nflen1 == flen);
  315. #endif
  316. } else {
  317. if ((error = xfs_alloc_lookup_eq(cnt_cur, fbno, flen, &i)))
  318. return error;
  319. XFS_WANT_CORRUPTED_RETURN(i == 1);
  320. }
  321. /*
  322. * Look up the record in the by-block tree if necessary.
  323. */
  324. if (flags & XFSA_FIXUP_BNO_OK) {
  325. #ifdef DEBUG
  326. if ((error = xfs_alloc_get_rec(bno_cur, &nfbno1, &nflen1, &i)))
  327. return error;
  328. XFS_WANT_CORRUPTED_RETURN(
  329. i == 1 && nfbno1 == fbno && nflen1 == flen);
  330. #endif
  331. } else {
  332. if ((error = xfs_alloc_lookup_eq(bno_cur, fbno, flen, &i)))
  333. return error;
  334. XFS_WANT_CORRUPTED_RETURN(i == 1);
  335. }
  336. #ifdef DEBUG
  337. if (bno_cur->bc_nlevels == 1 && cnt_cur->bc_nlevels == 1) {
  338. struct xfs_btree_block *bnoblock;
  339. struct xfs_btree_block *cntblock;
  340. bnoblock = XFS_BUF_TO_BLOCK(bno_cur->bc_bufs[0]);
  341. cntblock = XFS_BUF_TO_BLOCK(cnt_cur->bc_bufs[0]);
  342. XFS_WANT_CORRUPTED_RETURN(
  343. bnoblock->bb_numrecs == cntblock->bb_numrecs);
  344. }
  345. #endif
  346. /*
  347. * Deal with all four cases: the allocated record is contained
  348. * within the freespace record, so we can have new freespace
  349. * at either (or both) end, or no freespace remaining.
  350. */
  351. if (rbno == fbno && rlen == flen)
  352. nfbno1 = nfbno2 = NULLAGBLOCK;
  353. else if (rbno == fbno) {
  354. nfbno1 = rbno + rlen;
  355. nflen1 = flen - rlen;
  356. nfbno2 = NULLAGBLOCK;
  357. } else if (rbno + rlen == fbno + flen) {
  358. nfbno1 = fbno;
  359. nflen1 = flen - rlen;
  360. nfbno2 = NULLAGBLOCK;
  361. } else {
  362. nfbno1 = fbno;
  363. nflen1 = rbno - fbno;
  364. nfbno2 = rbno + rlen;
  365. nflen2 = (fbno + flen) - nfbno2;
  366. }
  367. /*
  368. * Delete the entry from the by-size btree.
  369. */
  370. if ((error = xfs_btree_delete(cnt_cur, &i)))
  371. return error;
  372. XFS_WANT_CORRUPTED_RETURN(i == 1);
  373. /*
  374. * Add new by-size btree entry(s).
  375. */
  376. if (nfbno1 != NULLAGBLOCK) {
  377. if ((error = xfs_alloc_lookup_eq(cnt_cur, nfbno1, nflen1, &i)))
  378. return error;
  379. XFS_WANT_CORRUPTED_RETURN(i == 0);
  380. if ((error = xfs_btree_insert(cnt_cur, &i)))
  381. return error;
  382. XFS_WANT_CORRUPTED_RETURN(i == 1);
  383. }
  384. if (nfbno2 != NULLAGBLOCK) {
  385. if ((error = xfs_alloc_lookup_eq(cnt_cur, nfbno2, nflen2, &i)))
  386. return error;
  387. XFS_WANT_CORRUPTED_RETURN(i == 0);
  388. if ((error = xfs_btree_insert(cnt_cur, &i)))
  389. return error;
  390. XFS_WANT_CORRUPTED_RETURN(i == 1);
  391. }
  392. /*
  393. * Fix up the by-block btree entry(s).
  394. */
  395. if (nfbno1 == NULLAGBLOCK) {
  396. /*
  397. * No remaining freespace, just delete the by-block tree entry.
  398. */
  399. if ((error = xfs_btree_delete(bno_cur, &i)))
  400. return error;
  401. XFS_WANT_CORRUPTED_RETURN(i == 1);
  402. } else {
  403. /*
  404. * Update the by-block entry to start later|be shorter.
  405. */
  406. if ((error = xfs_alloc_update(bno_cur, nfbno1, nflen1)))
  407. return error;
  408. }
  409. if (nfbno2 != NULLAGBLOCK) {
  410. /*
  411. * 2 resulting free entries, need to add one.
  412. */
  413. if ((error = xfs_alloc_lookup_eq(bno_cur, nfbno2, nflen2, &i)))
  414. return error;
  415. XFS_WANT_CORRUPTED_RETURN(i == 0);
  416. if ((error = xfs_btree_insert(bno_cur, &i)))
  417. return error;
  418. XFS_WANT_CORRUPTED_RETURN(i == 1);
  419. }
  420. return 0;
  421. }
  422. /*
  423. * Read in the allocation group free block array.
  424. */
  425. STATIC int /* error */
  426. xfs_alloc_read_agfl(
  427. xfs_mount_t *mp, /* mount point structure */
  428. xfs_trans_t *tp, /* transaction pointer */
  429. xfs_agnumber_t agno, /* allocation group number */
  430. xfs_buf_t **bpp) /* buffer for the ag free block array */
  431. {
  432. xfs_buf_t *bp; /* return value */
  433. int error;
  434. ASSERT(agno != NULLAGNUMBER);
  435. error = xfs_trans_read_buf(
  436. mp, tp, mp->m_ddev_targp,
  437. XFS_AG_DADDR(mp, agno, XFS_AGFL_DADDR(mp)),
  438. XFS_FSS_TO_BB(mp, 1), 0, &bp);
  439. if (error)
  440. return error;
  441. ASSERT(bp);
  442. ASSERT(!XFS_BUF_GETERROR(bp));
  443. XFS_BUF_SET_VTYPE_REF(bp, B_FS_AGFL, XFS_AGFL_REF);
  444. *bpp = bp;
  445. return 0;
  446. }
  447. /*
  448. * Allocation group level functions.
  449. */
  450. /*
  451. * Allocate a variable extent in the allocation group agno.
  452. * Type and bno are used to determine where in the allocation group the
  453. * extent will start.
  454. * Extent's length (returned in *len) will be between minlen and maxlen,
  455. * and of the form k * prod + mod unless there's nothing that large.
  456. * Return the starting a.g. block, or NULLAGBLOCK if we can't do it.
  457. */
  458. STATIC int /* error */
  459. xfs_alloc_ag_vextent(
  460. xfs_alloc_arg_t *args) /* argument structure for allocation */
  461. {
  462. int error=0;
  463. ASSERT(args->minlen > 0);
  464. ASSERT(args->maxlen > 0);
  465. ASSERT(args->minlen <= args->maxlen);
  466. ASSERT(args->mod < args->prod);
  467. ASSERT(args->alignment > 0);
  468. /*
  469. * Branch to correct routine based on the type.
  470. */
  471. args->wasfromfl = 0;
  472. switch (args->type) {
  473. case XFS_ALLOCTYPE_THIS_AG:
  474. error = xfs_alloc_ag_vextent_size(args);
  475. break;
  476. case XFS_ALLOCTYPE_NEAR_BNO:
  477. error = xfs_alloc_ag_vextent_near(args);
  478. break;
  479. case XFS_ALLOCTYPE_THIS_BNO:
  480. error = xfs_alloc_ag_vextent_exact(args);
  481. break;
  482. default:
  483. ASSERT(0);
  484. /* NOTREACHED */
  485. }
  486. if (error)
  487. return error;
  488. /*
  489. * If the allocation worked, need to change the agf structure
  490. * (and log it), and the superblock.
  491. */
  492. if (args->agbno != NULLAGBLOCK) {
  493. xfs_agf_t *agf; /* allocation group freelist header */
  494. long slen = (long)args->len;
  495. ASSERT(args->len >= args->minlen && args->len <= args->maxlen);
  496. ASSERT(!(args->wasfromfl) || !args->isfl);
  497. ASSERT(args->agbno % args->alignment == 0);
  498. if (!(args->wasfromfl)) {
  499. agf = XFS_BUF_TO_AGF(args->agbp);
  500. be32_add_cpu(&agf->agf_freeblks, -(args->len));
  501. xfs_trans_agblocks_delta(args->tp,
  502. -((long)(args->len)));
  503. args->pag->pagf_freeblks -= args->len;
  504. ASSERT(be32_to_cpu(agf->agf_freeblks) <=
  505. be32_to_cpu(agf->agf_length));
  506. xfs_alloc_log_agf(args->tp, args->agbp,
  507. XFS_AGF_FREEBLKS);
  508. /* search the busylist for these blocks */
  509. xfs_alloc_search_busy(args->tp, args->agno,
  510. args->agbno, args->len);
  511. }
  512. if (!args->isfl)
  513. xfs_trans_mod_sb(args->tp,
  514. args->wasdel ? XFS_TRANS_SB_RES_FDBLOCKS :
  515. XFS_TRANS_SB_FDBLOCKS, -slen);
  516. XFS_STATS_INC(xs_allocx);
  517. XFS_STATS_ADD(xs_allocb, args->len);
  518. }
  519. return 0;
  520. }
  521. /*
  522. * Allocate a variable extent at exactly agno/bno.
  523. * Extent's length (returned in *len) will be between minlen and maxlen,
  524. * and of the form k * prod + mod unless there's nothing that large.
  525. * Return the starting a.g. block (bno), or NULLAGBLOCK if we can't do it.
  526. */
  527. STATIC int /* error */
  528. xfs_alloc_ag_vextent_exact(
  529. xfs_alloc_arg_t *args) /* allocation argument structure */
  530. {
  531. xfs_btree_cur_t *bno_cur;/* by block-number btree cursor */
  532. xfs_btree_cur_t *cnt_cur;/* by count btree cursor */
  533. xfs_agblock_t end; /* end of allocated extent */
  534. int error;
  535. xfs_agblock_t fbno; /* start block of found extent */
  536. xfs_agblock_t fend; /* end block of found extent */
  537. xfs_extlen_t flen; /* length of found extent */
  538. int i; /* success/failure of operation */
  539. xfs_agblock_t maxend; /* end of maximal extent */
  540. xfs_agblock_t minend; /* end of minimal extent */
  541. xfs_extlen_t rlen; /* length of returned extent */
  542. ASSERT(args->alignment == 1);
  543. /*
  544. * Allocate/initialize a cursor for the by-number freespace btree.
  545. */
  546. bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
  547. args->agno, XFS_BTNUM_BNO);
  548. /*
  549. * Lookup bno and minlen in the btree (minlen is irrelevant, really).
  550. * Look for the closest free block <= bno, it must contain bno
  551. * if any free block does.
  552. */
  553. if ((error = xfs_alloc_lookup_le(bno_cur, args->agbno, args->minlen, &i)))
  554. goto error0;
  555. if (!i) {
  556. /*
  557. * Didn't find it, return null.
  558. */
  559. xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
  560. args->agbno = NULLAGBLOCK;
  561. return 0;
  562. }
  563. /*
  564. * Grab the freespace record.
  565. */
  566. if ((error = xfs_alloc_get_rec(bno_cur, &fbno, &flen, &i)))
  567. goto error0;
  568. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  569. ASSERT(fbno <= args->agbno);
  570. minend = args->agbno + args->minlen;
  571. maxend = args->agbno + args->maxlen;
  572. fend = fbno + flen;
  573. /*
  574. * Give up if the freespace isn't long enough for the minimum request.
  575. */
  576. if (fend < minend) {
  577. xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
  578. args->agbno = NULLAGBLOCK;
  579. return 0;
  580. }
  581. /*
  582. * End of extent will be smaller of the freespace end and the
  583. * maximal requested end.
  584. */
  585. end = XFS_AGBLOCK_MIN(fend, maxend);
  586. /*
  587. * Fix the length according to mod and prod if given.
  588. */
  589. args->len = end - args->agbno;
  590. xfs_alloc_fix_len(args);
  591. if (!xfs_alloc_fix_minleft(args)) {
  592. xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
  593. return 0;
  594. }
  595. rlen = args->len;
  596. ASSERT(args->agbno + rlen <= fend);
  597. end = args->agbno + rlen;
  598. /*
  599. * We are allocating agbno for rlen [agbno .. end]
  600. * Allocate/initialize a cursor for the by-size btree.
  601. */
  602. cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
  603. args->agno, XFS_BTNUM_CNT);
  604. ASSERT(args->agbno + args->len <=
  605. be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length));
  606. if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen,
  607. args->agbno, args->len, XFSA_FIXUP_BNO_OK))) {
  608. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_ERROR);
  609. goto error0;
  610. }
  611. xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
  612. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  613. trace_xfs_alloc_exact_done(args);
  614. args->wasfromfl = 0;
  615. return 0;
  616. error0:
  617. xfs_btree_del_cursor(bno_cur, XFS_BTREE_ERROR);
  618. trace_xfs_alloc_exact_error(args);
  619. return error;
  620. }
  621. /*
  622. * Allocate a variable extent near bno in the allocation group agno.
  623. * Extent's length (returned in len) will be between minlen and maxlen,
  624. * and of the form k * prod + mod unless there's nothing that large.
  625. * Return the starting a.g. block, or NULLAGBLOCK if we can't do it.
  626. */
  627. STATIC int /* error */
  628. xfs_alloc_ag_vextent_near(
  629. xfs_alloc_arg_t *args) /* allocation argument structure */
  630. {
  631. xfs_btree_cur_t *bno_cur_gt; /* cursor for bno btree, right side */
  632. xfs_btree_cur_t *bno_cur_lt; /* cursor for bno btree, left side */
  633. xfs_btree_cur_t *cnt_cur; /* cursor for count btree */
  634. xfs_agblock_t gtbno; /* start bno of right side entry */
  635. xfs_agblock_t gtbnoa; /* aligned ... */
  636. xfs_extlen_t gtdiff; /* difference to right side entry */
  637. xfs_extlen_t gtlen; /* length of right side entry */
  638. xfs_extlen_t gtlena; /* aligned ... */
  639. xfs_agblock_t gtnew; /* useful start bno of right side */
  640. int error; /* error code */
  641. int i; /* result code, temporary */
  642. int j; /* result code, temporary */
  643. xfs_agblock_t ltbno; /* start bno of left side entry */
  644. xfs_agblock_t ltbnoa; /* aligned ... */
  645. xfs_extlen_t ltdiff; /* difference to left side entry */
  646. /*REFERENCED*/
  647. xfs_agblock_t ltend; /* end bno of left side entry */
  648. xfs_extlen_t ltlen; /* length of left side entry */
  649. xfs_extlen_t ltlena; /* aligned ... */
  650. xfs_agblock_t ltnew; /* useful start bno of left side */
  651. xfs_extlen_t rlen; /* length of returned extent */
  652. #if defined(DEBUG) && defined(__KERNEL__)
  653. /*
  654. * Randomly don't execute the first algorithm.
  655. */
  656. int dofirst; /* set to do first algorithm */
  657. dofirst = random32() & 1;
  658. #endif
  659. /*
  660. * Get a cursor for the by-size btree.
  661. */
  662. cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
  663. args->agno, XFS_BTNUM_CNT);
  664. ltlen = 0;
  665. bno_cur_lt = bno_cur_gt = NULL;
  666. /*
  667. * See if there are any free extents as big as maxlen.
  668. */
  669. if ((error = xfs_alloc_lookup_ge(cnt_cur, 0, args->maxlen, &i)))
  670. goto error0;
  671. /*
  672. * If none, then pick up the last entry in the tree unless the
  673. * tree is empty.
  674. */
  675. if (!i) {
  676. if ((error = xfs_alloc_ag_vextent_small(args, cnt_cur, &ltbno,
  677. &ltlen, &i)))
  678. goto error0;
  679. if (i == 0 || ltlen == 0) {
  680. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  681. return 0;
  682. }
  683. ASSERT(i == 1);
  684. }
  685. args->wasfromfl = 0;
  686. /*
  687. * First algorithm.
  688. * If the requested extent is large wrt the freespaces available
  689. * in this a.g., then the cursor will be pointing to a btree entry
  690. * near the right edge of the tree. If it's in the last btree leaf
  691. * block, then we just examine all the entries in that block
  692. * that are big enough, and pick the best one.
  693. * This is written as a while loop so we can break out of it,
  694. * but we never loop back to the top.
  695. */
  696. while (xfs_btree_islastblock(cnt_cur, 0)) {
  697. xfs_extlen_t bdiff;
  698. int besti=0;
  699. xfs_extlen_t blen=0;
  700. xfs_agblock_t bnew=0;
  701. #if defined(DEBUG) && defined(__KERNEL__)
  702. if (!dofirst)
  703. break;
  704. #endif
  705. /*
  706. * Start from the entry that lookup found, sequence through
  707. * all larger free blocks. If we're actually pointing at a
  708. * record smaller than maxlen, go to the start of this block,
  709. * and skip all those smaller than minlen.
  710. */
  711. if (ltlen || args->alignment > 1) {
  712. cnt_cur->bc_ptrs[0] = 1;
  713. do {
  714. if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno,
  715. &ltlen, &i)))
  716. goto error0;
  717. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  718. if (ltlen >= args->minlen)
  719. break;
  720. if ((error = xfs_btree_increment(cnt_cur, 0, &i)))
  721. goto error0;
  722. } while (i);
  723. ASSERT(ltlen >= args->minlen);
  724. if (!i)
  725. break;
  726. }
  727. i = cnt_cur->bc_ptrs[0];
  728. for (j = 1, blen = 0, bdiff = 0;
  729. !error && j && (blen < args->maxlen || bdiff > 0);
  730. error = xfs_btree_increment(cnt_cur, 0, &j)) {
  731. /*
  732. * For each entry, decide if it's better than
  733. * the previous best entry.
  734. */
  735. if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno, &ltlen, &i)))
  736. goto error0;
  737. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  738. xfs_alloc_compute_aligned(ltbno, ltlen, args->alignment,
  739. args->minlen, &ltbnoa, &ltlena);
  740. if (ltlena < args->minlen)
  741. continue;
  742. args->len = XFS_EXTLEN_MIN(ltlena, args->maxlen);
  743. xfs_alloc_fix_len(args);
  744. ASSERT(args->len >= args->minlen);
  745. if (args->len < blen)
  746. continue;
  747. ltdiff = xfs_alloc_compute_diff(args->agbno, args->len,
  748. args->alignment, ltbno, ltlen, &ltnew);
  749. if (ltnew != NULLAGBLOCK &&
  750. (args->len > blen || ltdiff < bdiff)) {
  751. bdiff = ltdiff;
  752. bnew = ltnew;
  753. blen = args->len;
  754. besti = cnt_cur->bc_ptrs[0];
  755. }
  756. }
  757. /*
  758. * It didn't work. We COULD be in a case where
  759. * there's a good record somewhere, so try again.
  760. */
  761. if (blen == 0)
  762. break;
  763. /*
  764. * Point at the best entry, and retrieve it again.
  765. */
  766. cnt_cur->bc_ptrs[0] = besti;
  767. if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno, &ltlen, &i)))
  768. goto error0;
  769. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  770. ltend = ltbno + ltlen;
  771. ASSERT(ltend <= be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length));
  772. args->len = blen;
  773. if (!xfs_alloc_fix_minleft(args)) {
  774. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  775. trace_xfs_alloc_near_nominleft(args);
  776. return 0;
  777. }
  778. blen = args->len;
  779. /*
  780. * We are allocating starting at bnew for blen blocks.
  781. */
  782. args->agbno = bnew;
  783. ASSERT(bnew >= ltbno);
  784. ASSERT(bnew + blen <= ltend);
  785. /*
  786. * Set up a cursor for the by-bno tree.
  787. */
  788. bno_cur_lt = xfs_allocbt_init_cursor(args->mp, args->tp,
  789. args->agbp, args->agno, XFS_BTNUM_BNO);
  790. /*
  791. * Fix up the btree entries.
  792. */
  793. if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur_lt, ltbno,
  794. ltlen, bnew, blen, XFSA_FIXUP_CNT_OK)))
  795. goto error0;
  796. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  797. xfs_btree_del_cursor(bno_cur_lt, XFS_BTREE_NOERROR);
  798. trace_xfs_alloc_near_first(args);
  799. return 0;
  800. }
  801. /*
  802. * Second algorithm.
  803. * Search in the by-bno tree to the left and to the right
  804. * simultaneously, until in each case we find a space big enough,
  805. * or run into the edge of the tree. When we run into the edge,
  806. * we deallocate that cursor.
  807. * If both searches succeed, we compare the two spaces and pick
  808. * the better one.
  809. * With alignment, it's possible for both to fail; the upper
  810. * level algorithm that picks allocation groups for allocations
  811. * is not supposed to do this.
  812. */
  813. /*
  814. * Allocate and initialize the cursor for the leftward search.
  815. */
  816. bno_cur_lt = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
  817. args->agno, XFS_BTNUM_BNO);
  818. /*
  819. * Lookup <= bno to find the leftward search's starting point.
  820. */
  821. if ((error = xfs_alloc_lookup_le(bno_cur_lt, args->agbno, args->maxlen, &i)))
  822. goto error0;
  823. if (!i) {
  824. /*
  825. * Didn't find anything; use this cursor for the rightward
  826. * search.
  827. */
  828. bno_cur_gt = bno_cur_lt;
  829. bno_cur_lt = NULL;
  830. }
  831. /*
  832. * Found something. Duplicate the cursor for the rightward search.
  833. */
  834. else if ((error = xfs_btree_dup_cursor(bno_cur_lt, &bno_cur_gt)))
  835. goto error0;
  836. /*
  837. * Increment the cursor, so we will point at the entry just right
  838. * of the leftward entry if any, or to the leftmost entry.
  839. */
  840. if ((error = xfs_btree_increment(bno_cur_gt, 0, &i)))
  841. goto error0;
  842. if (!i) {
  843. /*
  844. * It failed, there are no rightward entries.
  845. */
  846. xfs_btree_del_cursor(bno_cur_gt, XFS_BTREE_NOERROR);
  847. bno_cur_gt = NULL;
  848. }
  849. /*
  850. * Loop going left with the leftward cursor, right with the
  851. * rightward cursor, until either both directions give up or
  852. * we find an entry at least as big as minlen.
  853. */
  854. do {
  855. if (bno_cur_lt) {
  856. if ((error = xfs_alloc_get_rec(bno_cur_lt, &ltbno, &ltlen, &i)))
  857. goto error0;
  858. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  859. xfs_alloc_compute_aligned(ltbno, ltlen, args->alignment,
  860. args->minlen, &ltbnoa, &ltlena);
  861. if (ltlena >= args->minlen)
  862. break;
  863. if ((error = xfs_btree_decrement(bno_cur_lt, 0, &i)))
  864. goto error0;
  865. if (!i) {
  866. xfs_btree_del_cursor(bno_cur_lt,
  867. XFS_BTREE_NOERROR);
  868. bno_cur_lt = NULL;
  869. }
  870. }
  871. if (bno_cur_gt) {
  872. if ((error = xfs_alloc_get_rec(bno_cur_gt, &gtbno, &gtlen, &i)))
  873. goto error0;
  874. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  875. xfs_alloc_compute_aligned(gtbno, gtlen, args->alignment,
  876. args->minlen, &gtbnoa, &gtlena);
  877. if (gtlena >= args->minlen)
  878. break;
  879. if ((error = xfs_btree_increment(bno_cur_gt, 0, &i)))
  880. goto error0;
  881. if (!i) {
  882. xfs_btree_del_cursor(bno_cur_gt,
  883. XFS_BTREE_NOERROR);
  884. bno_cur_gt = NULL;
  885. }
  886. }
  887. } while (bno_cur_lt || bno_cur_gt);
  888. /*
  889. * Got both cursors still active, need to find better entry.
  890. */
  891. if (bno_cur_lt && bno_cur_gt) {
  892. /*
  893. * Left side is long enough, look for a right side entry.
  894. */
  895. if (ltlena >= args->minlen) {
  896. /*
  897. * Fix up the length.
  898. */
  899. args->len = XFS_EXTLEN_MIN(ltlena, args->maxlen);
  900. xfs_alloc_fix_len(args);
  901. rlen = args->len;
  902. ltdiff = xfs_alloc_compute_diff(args->agbno, rlen,
  903. args->alignment, ltbno, ltlen, &ltnew);
  904. /*
  905. * Not perfect.
  906. */
  907. if (ltdiff) {
  908. /*
  909. * Look until we find a better one, run out of
  910. * space, or run off the end.
  911. */
  912. while (bno_cur_lt && bno_cur_gt) {
  913. if ((error = xfs_alloc_get_rec(
  914. bno_cur_gt, &gtbno,
  915. &gtlen, &i)))
  916. goto error0;
  917. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  918. xfs_alloc_compute_aligned(gtbno, gtlen,
  919. args->alignment, args->minlen,
  920. &gtbnoa, &gtlena);
  921. /*
  922. * The left one is clearly better.
  923. */
  924. if (gtbnoa >= args->agbno + ltdiff) {
  925. xfs_btree_del_cursor(
  926. bno_cur_gt,
  927. XFS_BTREE_NOERROR);
  928. bno_cur_gt = NULL;
  929. break;
  930. }
  931. /*
  932. * If we reach a big enough entry,
  933. * compare the two and pick the best.
  934. */
  935. if (gtlena >= args->minlen) {
  936. args->len =
  937. XFS_EXTLEN_MIN(gtlena,
  938. args->maxlen);
  939. xfs_alloc_fix_len(args);
  940. rlen = args->len;
  941. gtdiff = xfs_alloc_compute_diff(
  942. args->agbno, rlen,
  943. args->alignment,
  944. gtbno, gtlen, &gtnew);
  945. /*
  946. * Right side is better.
  947. */
  948. if (gtdiff < ltdiff) {
  949. xfs_btree_del_cursor(
  950. bno_cur_lt,
  951. XFS_BTREE_NOERROR);
  952. bno_cur_lt = NULL;
  953. }
  954. /*
  955. * Left side is better.
  956. */
  957. else {
  958. xfs_btree_del_cursor(
  959. bno_cur_gt,
  960. XFS_BTREE_NOERROR);
  961. bno_cur_gt = NULL;
  962. }
  963. break;
  964. }
  965. /*
  966. * Fell off the right end.
  967. */
  968. if ((error = xfs_btree_increment(
  969. bno_cur_gt, 0, &i)))
  970. goto error0;
  971. if (!i) {
  972. xfs_btree_del_cursor(
  973. bno_cur_gt,
  974. XFS_BTREE_NOERROR);
  975. bno_cur_gt = NULL;
  976. break;
  977. }
  978. }
  979. }
  980. /*
  981. * The left side is perfect, trash the right side.
  982. */
  983. else {
  984. xfs_btree_del_cursor(bno_cur_gt,
  985. XFS_BTREE_NOERROR);
  986. bno_cur_gt = NULL;
  987. }
  988. }
  989. /*
  990. * It's the right side that was found first, look left.
  991. */
  992. else {
  993. /*
  994. * Fix up the length.
  995. */
  996. args->len = XFS_EXTLEN_MIN(gtlena, args->maxlen);
  997. xfs_alloc_fix_len(args);
  998. rlen = args->len;
  999. gtdiff = xfs_alloc_compute_diff(args->agbno, rlen,
  1000. args->alignment, gtbno, gtlen, &gtnew);
  1001. /*
  1002. * Right side entry isn't perfect.
  1003. */
  1004. if (gtdiff) {
  1005. /*
  1006. * Look until we find a better one, run out of
  1007. * space, or run off the end.
  1008. */
  1009. while (bno_cur_lt && bno_cur_gt) {
  1010. if ((error = xfs_alloc_get_rec(
  1011. bno_cur_lt, &ltbno,
  1012. &ltlen, &i)))
  1013. goto error0;
  1014. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1015. xfs_alloc_compute_aligned(ltbno, ltlen,
  1016. args->alignment, args->minlen,
  1017. &ltbnoa, &ltlena);
  1018. /*
  1019. * The right one is clearly better.
  1020. */
  1021. if (ltbnoa <= args->agbno - gtdiff) {
  1022. xfs_btree_del_cursor(
  1023. bno_cur_lt,
  1024. XFS_BTREE_NOERROR);
  1025. bno_cur_lt = NULL;
  1026. break;
  1027. }
  1028. /*
  1029. * If we reach a big enough entry,
  1030. * compare the two and pick the best.
  1031. */
  1032. if (ltlena >= args->minlen) {
  1033. args->len = XFS_EXTLEN_MIN(
  1034. ltlena, args->maxlen);
  1035. xfs_alloc_fix_len(args);
  1036. rlen = args->len;
  1037. ltdiff = xfs_alloc_compute_diff(
  1038. args->agbno, rlen,
  1039. args->alignment,
  1040. ltbno, ltlen, &ltnew);
  1041. /*
  1042. * Left side is better.
  1043. */
  1044. if (ltdiff < gtdiff) {
  1045. xfs_btree_del_cursor(
  1046. bno_cur_gt,
  1047. XFS_BTREE_NOERROR);
  1048. bno_cur_gt = NULL;
  1049. }
  1050. /*
  1051. * Right side is better.
  1052. */
  1053. else {
  1054. xfs_btree_del_cursor(
  1055. bno_cur_lt,
  1056. XFS_BTREE_NOERROR);
  1057. bno_cur_lt = NULL;
  1058. }
  1059. break;
  1060. }
  1061. /*
  1062. * Fell off the left end.
  1063. */
  1064. if ((error = xfs_btree_decrement(
  1065. bno_cur_lt, 0, &i)))
  1066. goto error0;
  1067. if (!i) {
  1068. xfs_btree_del_cursor(bno_cur_lt,
  1069. XFS_BTREE_NOERROR);
  1070. bno_cur_lt = NULL;
  1071. break;
  1072. }
  1073. }
  1074. }
  1075. /*
  1076. * The right side is perfect, trash the left side.
  1077. */
  1078. else {
  1079. xfs_btree_del_cursor(bno_cur_lt,
  1080. XFS_BTREE_NOERROR);
  1081. bno_cur_lt = NULL;
  1082. }
  1083. }
  1084. }
  1085. /*
  1086. * If we couldn't get anything, give up.
  1087. */
  1088. if (bno_cur_lt == NULL && bno_cur_gt == NULL) {
  1089. trace_xfs_alloc_size_neither(args);
  1090. args->agbno = NULLAGBLOCK;
  1091. return 0;
  1092. }
  1093. /*
  1094. * At this point we have selected a freespace entry, either to the
  1095. * left or to the right. If it's on the right, copy all the
  1096. * useful variables to the "left" set so we only have one
  1097. * copy of this code.
  1098. */
  1099. if (bno_cur_gt) {
  1100. bno_cur_lt = bno_cur_gt;
  1101. bno_cur_gt = NULL;
  1102. ltbno = gtbno;
  1103. ltbnoa = gtbnoa;
  1104. ltlen = gtlen;
  1105. ltlena = gtlena;
  1106. j = 1;
  1107. } else
  1108. j = 0;
  1109. /*
  1110. * Fix up the length and compute the useful address.
  1111. */
  1112. ltend = ltbno + ltlen;
  1113. args->len = XFS_EXTLEN_MIN(ltlena, args->maxlen);
  1114. xfs_alloc_fix_len(args);
  1115. if (!xfs_alloc_fix_minleft(args)) {
  1116. trace_xfs_alloc_near_nominleft(args);
  1117. xfs_btree_del_cursor(bno_cur_lt, XFS_BTREE_NOERROR);
  1118. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  1119. return 0;
  1120. }
  1121. rlen = args->len;
  1122. (void)xfs_alloc_compute_diff(args->agbno, rlen, args->alignment, ltbno,
  1123. ltlen, &ltnew);
  1124. ASSERT(ltnew >= ltbno);
  1125. ASSERT(ltnew + rlen <= ltend);
  1126. ASSERT(ltnew + rlen <= be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length));
  1127. args->agbno = ltnew;
  1128. if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur_lt, ltbno, ltlen,
  1129. ltnew, rlen, XFSA_FIXUP_BNO_OK)))
  1130. goto error0;
  1131. if (j)
  1132. trace_xfs_alloc_near_greater(args);
  1133. else
  1134. trace_xfs_alloc_near_lesser(args);
  1135. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  1136. xfs_btree_del_cursor(bno_cur_lt, XFS_BTREE_NOERROR);
  1137. return 0;
  1138. error0:
  1139. trace_xfs_alloc_near_error(args);
  1140. if (cnt_cur != NULL)
  1141. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_ERROR);
  1142. if (bno_cur_lt != NULL)
  1143. xfs_btree_del_cursor(bno_cur_lt, XFS_BTREE_ERROR);
  1144. if (bno_cur_gt != NULL)
  1145. xfs_btree_del_cursor(bno_cur_gt, XFS_BTREE_ERROR);
  1146. return error;
  1147. }
  1148. /*
  1149. * Allocate a variable extent anywhere in the allocation group agno.
  1150. * Extent's length (returned in len) will be between minlen and maxlen,
  1151. * and of the form k * prod + mod unless there's nothing that large.
  1152. * Return the starting a.g. block, or NULLAGBLOCK if we can't do it.
  1153. */
  1154. STATIC int /* error */
  1155. xfs_alloc_ag_vextent_size(
  1156. xfs_alloc_arg_t *args) /* allocation argument structure */
  1157. {
  1158. xfs_btree_cur_t *bno_cur; /* cursor for bno btree */
  1159. xfs_btree_cur_t *cnt_cur; /* cursor for cnt btree */
  1160. int error; /* error result */
  1161. xfs_agblock_t fbno; /* start of found freespace */
  1162. xfs_extlen_t flen; /* length of found freespace */
  1163. int i; /* temp status variable */
  1164. xfs_agblock_t rbno; /* returned block number */
  1165. xfs_extlen_t rlen; /* length of returned extent */
  1166. /*
  1167. * Allocate and initialize a cursor for the by-size btree.
  1168. */
  1169. cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
  1170. args->agno, XFS_BTNUM_CNT);
  1171. bno_cur = NULL;
  1172. /*
  1173. * Look for an entry >= maxlen+alignment-1 blocks.
  1174. */
  1175. if ((error = xfs_alloc_lookup_ge(cnt_cur, 0,
  1176. args->maxlen + args->alignment - 1, &i)))
  1177. goto error0;
  1178. /*
  1179. * If none, then pick up the last entry in the tree unless the
  1180. * tree is empty.
  1181. */
  1182. if (!i) {
  1183. if ((error = xfs_alloc_ag_vextent_small(args, cnt_cur, &fbno,
  1184. &flen, &i)))
  1185. goto error0;
  1186. if (i == 0 || flen == 0) {
  1187. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  1188. trace_xfs_alloc_size_noentry(args);
  1189. return 0;
  1190. }
  1191. ASSERT(i == 1);
  1192. }
  1193. /*
  1194. * There's a freespace as big as maxlen+alignment-1, get it.
  1195. */
  1196. else {
  1197. if ((error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen, &i)))
  1198. goto error0;
  1199. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1200. }
  1201. /*
  1202. * In the first case above, we got the last entry in the
  1203. * by-size btree. Now we check to see if the space hits maxlen
  1204. * once aligned; if not, we search left for something better.
  1205. * This can't happen in the second case above.
  1206. */
  1207. xfs_alloc_compute_aligned(fbno, flen, args->alignment, args->minlen,
  1208. &rbno, &rlen);
  1209. rlen = XFS_EXTLEN_MIN(args->maxlen, rlen);
  1210. XFS_WANT_CORRUPTED_GOTO(rlen == 0 ||
  1211. (rlen <= flen && rbno + rlen <= fbno + flen), error0);
  1212. if (rlen < args->maxlen) {
  1213. xfs_agblock_t bestfbno;
  1214. xfs_extlen_t bestflen;
  1215. xfs_agblock_t bestrbno;
  1216. xfs_extlen_t bestrlen;
  1217. bestrlen = rlen;
  1218. bestrbno = rbno;
  1219. bestflen = flen;
  1220. bestfbno = fbno;
  1221. for (;;) {
  1222. if ((error = xfs_btree_decrement(cnt_cur, 0, &i)))
  1223. goto error0;
  1224. if (i == 0)
  1225. break;
  1226. if ((error = xfs_alloc_get_rec(cnt_cur, &fbno, &flen,
  1227. &i)))
  1228. goto error0;
  1229. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1230. if (flen < bestrlen)
  1231. break;
  1232. xfs_alloc_compute_aligned(fbno, flen, args->alignment,
  1233. args->minlen, &rbno, &rlen);
  1234. rlen = XFS_EXTLEN_MIN(args->maxlen, rlen);
  1235. XFS_WANT_CORRUPTED_GOTO(rlen == 0 ||
  1236. (rlen <= flen && rbno + rlen <= fbno + flen),
  1237. error0);
  1238. if (rlen > bestrlen) {
  1239. bestrlen = rlen;
  1240. bestrbno = rbno;
  1241. bestflen = flen;
  1242. bestfbno = fbno;
  1243. if (rlen == args->maxlen)
  1244. break;
  1245. }
  1246. }
  1247. if ((error = xfs_alloc_lookup_eq(cnt_cur, bestfbno, bestflen,
  1248. &i)))
  1249. goto error0;
  1250. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1251. rlen = bestrlen;
  1252. rbno = bestrbno;
  1253. flen = bestflen;
  1254. fbno = bestfbno;
  1255. }
  1256. args->wasfromfl = 0;
  1257. /*
  1258. * Fix up the length.
  1259. */
  1260. args->len = rlen;
  1261. xfs_alloc_fix_len(args);
  1262. if (rlen < args->minlen || !xfs_alloc_fix_minleft(args)) {
  1263. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  1264. trace_xfs_alloc_size_nominleft(args);
  1265. args->agbno = NULLAGBLOCK;
  1266. return 0;
  1267. }
  1268. rlen = args->len;
  1269. XFS_WANT_CORRUPTED_GOTO(rlen <= flen, error0);
  1270. /*
  1271. * Allocate and initialize a cursor for the by-block tree.
  1272. */
  1273. bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
  1274. args->agno, XFS_BTNUM_BNO);
  1275. if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen,
  1276. rbno, rlen, XFSA_FIXUP_CNT_OK)))
  1277. goto error0;
  1278. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  1279. xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
  1280. cnt_cur = bno_cur = NULL;
  1281. args->len = rlen;
  1282. args->agbno = rbno;
  1283. XFS_WANT_CORRUPTED_GOTO(
  1284. args->agbno + args->len <=
  1285. be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length),
  1286. error0);
  1287. trace_xfs_alloc_size_done(args);
  1288. return 0;
  1289. error0:
  1290. trace_xfs_alloc_size_error(args);
  1291. if (cnt_cur)
  1292. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_ERROR);
  1293. if (bno_cur)
  1294. xfs_btree_del_cursor(bno_cur, XFS_BTREE_ERROR);
  1295. return error;
  1296. }
  1297. /*
  1298. * Deal with the case where only small freespaces remain.
  1299. * Either return the contents of the last freespace record,
  1300. * or allocate space from the freelist if there is nothing in the tree.
  1301. */
  1302. STATIC int /* error */
  1303. xfs_alloc_ag_vextent_small(
  1304. xfs_alloc_arg_t *args, /* allocation argument structure */
  1305. xfs_btree_cur_t *ccur, /* by-size cursor */
  1306. xfs_agblock_t *fbnop, /* result block number */
  1307. xfs_extlen_t *flenp, /* result length */
  1308. int *stat) /* status: 0-freelist, 1-normal/none */
  1309. {
  1310. int error;
  1311. xfs_agblock_t fbno;
  1312. xfs_extlen_t flen;
  1313. int i;
  1314. if ((error = xfs_btree_decrement(ccur, 0, &i)))
  1315. goto error0;
  1316. if (i) {
  1317. if ((error = xfs_alloc_get_rec(ccur, &fbno, &flen, &i)))
  1318. goto error0;
  1319. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1320. }
  1321. /*
  1322. * Nothing in the btree, try the freelist. Make sure
  1323. * to respect minleft even when pulling from the
  1324. * freelist.
  1325. */
  1326. else if (args->minlen == 1 && args->alignment == 1 && !args->isfl &&
  1327. (be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_flcount)
  1328. > args->minleft)) {
  1329. error = xfs_alloc_get_freelist(args->tp, args->agbp, &fbno, 0);
  1330. if (error)
  1331. goto error0;
  1332. if (fbno != NULLAGBLOCK) {
  1333. if (args->userdata) {
  1334. xfs_buf_t *bp;
  1335. bp = xfs_btree_get_bufs(args->mp, args->tp,
  1336. args->agno, fbno, 0);
  1337. xfs_trans_binval(args->tp, bp);
  1338. }
  1339. args->len = 1;
  1340. args->agbno = fbno;
  1341. XFS_WANT_CORRUPTED_GOTO(
  1342. args->agbno + args->len <=
  1343. be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length),
  1344. error0);
  1345. args->wasfromfl = 1;
  1346. trace_xfs_alloc_small_freelist(args);
  1347. *stat = 0;
  1348. return 0;
  1349. }
  1350. /*
  1351. * Nothing in the freelist.
  1352. */
  1353. else
  1354. flen = 0;
  1355. }
  1356. /*
  1357. * Can't allocate from the freelist for some reason.
  1358. */
  1359. else {
  1360. fbno = NULLAGBLOCK;
  1361. flen = 0;
  1362. }
  1363. /*
  1364. * Can't do the allocation, give up.
  1365. */
  1366. if (flen < args->minlen) {
  1367. args->agbno = NULLAGBLOCK;
  1368. trace_xfs_alloc_small_notenough(args);
  1369. flen = 0;
  1370. }
  1371. *fbnop = fbno;
  1372. *flenp = flen;
  1373. *stat = 1;
  1374. trace_xfs_alloc_small_done(args);
  1375. return 0;
  1376. error0:
  1377. trace_xfs_alloc_small_error(args);
  1378. return error;
  1379. }
  1380. /*
  1381. * Free the extent starting at agno/bno for length.
  1382. */
  1383. STATIC int /* error */
  1384. xfs_free_ag_extent(
  1385. xfs_trans_t *tp, /* transaction pointer */
  1386. xfs_buf_t *agbp, /* buffer for a.g. freelist header */
  1387. xfs_agnumber_t agno, /* allocation group number */
  1388. xfs_agblock_t bno, /* starting block number */
  1389. xfs_extlen_t len, /* length of extent */
  1390. int isfl) /* set if is freelist blocks - no sb acctg */
  1391. {
  1392. xfs_btree_cur_t *bno_cur; /* cursor for by-block btree */
  1393. xfs_btree_cur_t *cnt_cur; /* cursor for by-size btree */
  1394. int error; /* error return value */
  1395. xfs_agblock_t gtbno; /* start of right neighbor block */
  1396. xfs_extlen_t gtlen; /* length of right neighbor block */
  1397. int haveleft; /* have a left neighbor block */
  1398. int haveright; /* have a right neighbor block */
  1399. int i; /* temp, result code */
  1400. xfs_agblock_t ltbno; /* start of left neighbor block */
  1401. xfs_extlen_t ltlen; /* length of left neighbor block */
  1402. xfs_mount_t *mp; /* mount point struct for filesystem */
  1403. xfs_agblock_t nbno; /* new starting block of freespace */
  1404. xfs_extlen_t nlen; /* new length of freespace */
  1405. mp = tp->t_mountp;
  1406. /*
  1407. * Allocate and initialize a cursor for the by-block btree.
  1408. */
  1409. bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_BNO);
  1410. cnt_cur = NULL;
  1411. /*
  1412. * Look for a neighboring block on the left (lower block numbers)
  1413. * that is contiguous with this space.
  1414. */
  1415. if ((error = xfs_alloc_lookup_le(bno_cur, bno, len, &haveleft)))
  1416. goto error0;
  1417. if (haveleft) {
  1418. /*
  1419. * There is a block to our left.
  1420. */
  1421. if ((error = xfs_alloc_get_rec(bno_cur, &ltbno, &ltlen, &i)))
  1422. goto error0;
  1423. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1424. /*
  1425. * It's not contiguous, though.
  1426. */
  1427. if (ltbno + ltlen < bno)
  1428. haveleft = 0;
  1429. else {
  1430. /*
  1431. * If this failure happens the request to free this
  1432. * space was invalid, it's (partly) already free.
  1433. * Very bad.
  1434. */
  1435. XFS_WANT_CORRUPTED_GOTO(ltbno + ltlen <= bno, error0);
  1436. }
  1437. }
  1438. /*
  1439. * Look for a neighboring block on the right (higher block numbers)
  1440. * that is contiguous with this space.
  1441. */
  1442. if ((error = xfs_btree_increment(bno_cur, 0, &haveright)))
  1443. goto error0;
  1444. if (haveright) {
  1445. /*
  1446. * There is a block to our right.
  1447. */
  1448. if ((error = xfs_alloc_get_rec(bno_cur, &gtbno, &gtlen, &i)))
  1449. goto error0;
  1450. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1451. /*
  1452. * It's not contiguous, though.
  1453. */
  1454. if (bno + len < gtbno)
  1455. haveright = 0;
  1456. else {
  1457. /*
  1458. * If this failure happens the request to free this
  1459. * space was invalid, it's (partly) already free.
  1460. * Very bad.
  1461. */
  1462. XFS_WANT_CORRUPTED_GOTO(gtbno >= bno + len, error0);
  1463. }
  1464. }
  1465. /*
  1466. * Now allocate and initialize a cursor for the by-size tree.
  1467. */
  1468. cnt_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_CNT);
  1469. /*
  1470. * Have both left and right contiguous neighbors.
  1471. * Merge all three into a single free block.
  1472. */
  1473. if (haveleft && haveright) {
  1474. /*
  1475. * Delete the old by-size entry on the left.
  1476. */
  1477. if ((error = xfs_alloc_lookup_eq(cnt_cur, ltbno, ltlen, &i)))
  1478. goto error0;
  1479. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1480. if ((error = xfs_btree_delete(cnt_cur, &i)))
  1481. goto error0;
  1482. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1483. /*
  1484. * Delete the old by-size entry on the right.
  1485. */
  1486. if ((error = xfs_alloc_lookup_eq(cnt_cur, gtbno, gtlen, &i)))
  1487. goto error0;
  1488. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1489. if ((error = xfs_btree_delete(cnt_cur, &i)))
  1490. goto error0;
  1491. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1492. /*
  1493. * Delete the old by-block entry for the right block.
  1494. */
  1495. if ((error = xfs_btree_delete(bno_cur, &i)))
  1496. goto error0;
  1497. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1498. /*
  1499. * Move the by-block cursor back to the left neighbor.
  1500. */
  1501. if ((error = xfs_btree_decrement(bno_cur, 0, &i)))
  1502. goto error0;
  1503. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1504. #ifdef DEBUG
  1505. /*
  1506. * Check that this is the right record: delete didn't
  1507. * mangle the cursor.
  1508. */
  1509. {
  1510. xfs_agblock_t xxbno;
  1511. xfs_extlen_t xxlen;
  1512. if ((error = xfs_alloc_get_rec(bno_cur, &xxbno, &xxlen,
  1513. &i)))
  1514. goto error0;
  1515. XFS_WANT_CORRUPTED_GOTO(
  1516. i == 1 && xxbno == ltbno && xxlen == ltlen,
  1517. error0);
  1518. }
  1519. #endif
  1520. /*
  1521. * Update remaining by-block entry to the new, joined block.
  1522. */
  1523. nbno = ltbno;
  1524. nlen = len + ltlen + gtlen;
  1525. if ((error = xfs_alloc_update(bno_cur, nbno, nlen)))
  1526. goto error0;
  1527. }
  1528. /*
  1529. * Have only a left contiguous neighbor.
  1530. * Merge it together with the new freespace.
  1531. */
  1532. else if (haveleft) {
  1533. /*
  1534. * Delete the old by-size entry on the left.
  1535. */
  1536. if ((error = xfs_alloc_lookup_eq(cnt_cur, ltbno, ltlen, &i)))
  1537. goto error0;
  1538. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1539. if ((error = xfs_btree_delete(cnt_cur, &i)))
  1540. goto error0;
  1541. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1542. /*
  1543. * Back up the by-block cursor to the left neighbor, and
  1544. * update its length.
  1545. */
  1546. if ((error = xfs_btree_decrement(bno_cur, 0, &i)))
  1547. goto error0;
  1548. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1549. nbno = ltbno;
  1550. nlen = len + ltlen;
  1551. if ((error = xfs_alloc_update(bno_cur, nbno, nlen)))
  1552. goto error0;
  1553. }
  1554. /*
  1555. * Have only a right contiguous neighbor.
  1556. * Merge it together with the new freespace.
  1557. */
  1558. else if (haveright) {
  1559. /*
  1560. * Delete the old by-size entry on the right.
  1561. */
  1562. if ((error = xfs_alloc_lookup_eq(cnt_cur, gtbno, gtlen, &i)))
  1563. goto error0;
  1564. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1565. if ((error = xfs_btree_delete(cnt_cur, &i)))
  1566. goto error0;
  1567. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1568. /*
  1569. * Update the starting block and length of the right
  1570. * neighbor in the by-block tree.
  1571. */
  1572. nbno = bno;
  1573. nlen = len + gtlen;
  1574. if ((error = xfs_alloc_update(bno_cur, nbno, nlen)))
  1575. goto error0;
  1576. }
  1577. /*
  1578. * No contiguous neighbors.
  1579. * Insert the new freespace into the by-block tree.
  1580. */
  1581. else {
  1582. nbno = bno;
  1583. nlen = len;
  1584. if ((error = xfs_btree_insert(bno_cur, &i)))
  1585. goto error0;
  1586. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1587. }
  1588. xfs_btree_del_cursor(bno_cur, XFS_BTREE_NOERROR);
  1589. bno_cur = NULL;
  1590. /*
  1591. * In all cases we need to insert the new freespace in the by-size tree.
  1592. */
  1593. if ((error = xfs_alloc_lookup_eq(cnt_cur, nbno, nlen, &i)))
  1594. goto error0;
  1595. XFS_WANT_CORRUPTED_GOTO(i == 0, error0);
  1596. if ((error = xfs_btree_insert(cnt_cur, &i)))
  1597. goto error0;
  1598. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  1599. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
  1600. cnt_cur = NULL;
  1601. /*
  1602. * Update the freespace totals in the ag and superblock.
  1603. */
  1604. {
  1605. xfs_agf_t *agf;
  1606. xfs_perag_t *pag; /* per allocation group data */
  1607. agf = XFS_BUF_TO_AGF(agbp);
  1608. pag = &mp->m_perag[agno];
  1609. be32_add_cpu(&agf->agf_freeblks, len);
  1610. xfs_trans_agblocks_delta(tp, len);
  1611. pag->pagf_freeblks += len;
  1612. XFS_WANT_CORRUPTED_GOTO(
  1613. be32_to_cpu(agf->agf_freeblks) <=
  1614. be32_to_cpu(agf->agf_length),
  1615. error0);
  1616. xfs_alloc_log_agf(tp, agbp, XFS_AGF_FREEBLKS);
  1617. if (!isfl)
  1618. xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, (long)len);
  1619. XFS_STATS_INC(xs_freex);
  1620. XFS_STATS_ADD(xs_freeb, len);
  1621. }
  1622. trace_xfs_free_extent(mp, agno, bno, len, isfl, haveleft, haveright);
  1623. /*
  1624. * Since blocks move to the free list without the coordination
  1625. * used in xfs_bmap_finish, we can't allow block to be available
  1626. * for reallocation and non-transaction writing (user data)
  1627. * until we know that the transaction that moved it to the free
  1628. * list is permanently on disk. We track the blocks by declaring
  1629. * these blocks as "busy"; the busy list is maintained on a per-ag
  1630. * basis and each transaction records which entries should be removed
  1631. * when the iclog commits to disk. If a busy block is allocated,
  1632. * the iclog is pushed up to the LSN that freed the block.
  1633. */
  1634. xfs_alloc_mark_busy(tp, agno, bno, len);
  1635. return 0;
  1636. error0:
  1637. trace_xfs_free_extent(mp, agno, bno, len, isfl, -1, -1);
  1638. if (bno_cur)
  1639. xfs_btree_del_cursor(bno_cur, XFS_BTREE_ERROR);
  1640. if (cnt_cur)
  1641. xfs_btree_del_cursor(cnt_cur, XFS_BTREE_ERROR);
  1642. return error;
  1643. }
  1644. /*
  1645. * Visible (exported) allocation/free functions.
  1646. * Some of these are used just by xfs_alloc_btree.c and this file.
  1647. */
  1648. /*
  1649. * Compute and fill in value of m_ag_maxlevels.
  1650. */
  1651. void
  1652. xfs_alloc_compute_maxlevels(
  1653. xfs_mount_t *mp) /* file system mount structure */
  1654. {
  1655. int level;
  1656. uint maxblocks;
  1657. uint maxleafents;
  1658. int minleafrecs;
  1659. int minnoderecs;
  1660. maxleafents = (mp->m_sb.sb_agblocks + 1) / 2;
  1661. minleafrecs = mp->m_alloc_mnr[0];
  1662. minnoderecs = mp->m_alloc_mnr[1];
  1663. maxblocks = (maxleafents + minleafrecs - 1) / minleafrecs;
  1664. for (level = 1; maxblocks > 1; level++)
  1665. maxblocks = (maxblocks + minnoderecs - 1) / minnoderecs;
  1666. mp->m_ag_maxlevels = level;
  1667. }
  1668. /*
  1669. * Find the length of the longest extent in an AG.
  1670. */
  1671. xfs_extlen_t
  1672. xfs_alloc_longest_free_extent(
  1673. struct xfs_mount *mp,
  1674. struct xfs_perag *pag)
  1675. {
  1676. xfs_extlen_t need, delta = 0;
  1677. need = XFS_MIN_FREELIST_PAG(pag, mp);
  1678. if (need > pag->pagf_flcount)
  1679. delta = need - pag->pagf_flcount;
  1680. if (pag->pagf_longest > delta)
  1681. return pag->pagf_longest - delta;
  1682. return pag->pagf_flcount > 0 || pag->pagf_longest > 0;
  1683. }
  1684. /*
  1685. * Decide whether to use this allocation group for this allocation.
  1686. * If so, fix up the btree freelist's size.
  1687. */
  1688. STATIC int /* error */
  1689. xfs_alloc_fix_freelist(
  1690. xfs_alloc_arg_t *args, /* allocation argument structure */
  1691. int flags) /* XFS_ALLOC_FLAG_... */
  1692. {
  1693. xfs_buf_t *agbp; /* agf buffer pointer */
  1694. xfs_agf_t *agf; /* a.g. freespace structure pointer */
  1695. xfs_buf_t *agflbp;/* agfl buffer pointer */
  1696. xfs_agblock_t bno; /* freelist block */
  1697. xfs_extlen_t delta; /* new blocks needed in freelist */
  1698. int error; /* error result code *…

Large files files are truncated, but you can click here to view the full file