xfs_alloc_btree.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  1. /*
  2. * Copyright (c) 2000-2001,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. /*
  42. * Prototypes for internal functions.
  43. */
  44. STATIC void xfs_alloc_log_block(xfs_trans_t *, xfs_buf_t *, int);
  45. STATIC void xfs_alloc_log_keys(xfs_btree_cur_t *, xfs_buf_t *, int, int);
  46. STATIC void xfs_alloc_log_ptrs(xfs_btree_cur_t *, xfs_buf_t *, int, int);
  47. STATIC void xfs_alloc_log_recs(xfs_btree_cur_t *, xfs_buf_t *, int, int);
  48. STATIC int xfs_alloc_newroot(xfs_btree_cur_t *, int *);
  49. STATIC int xfs_alloc_split(xfs_btree_cur_t *, int, xfs_agblock_t *,
  50. xfs_alloc_key_t *, xfs_btree_cur_t **, int *);
  51. /*
  52. * Internal functions.
  53. */
  54. /*
  55. * Single level of the xfs_alloc_delete record deletion routine.
  56. * Delete record pointed to by cur/level.
  57. * Remove the record from its block then rebalance the tree.
  58. * Return 0 for error, 1 for done, 2 to go on to the next level.
  59. */
  60. STATIC int /* error */
  61. xfs_alloc_delrec(
  62. xfs_btree_cur_t *cur, /* btree cursor */
  63. int level, /* level removing record from */
  64. int *stat) /* fail/done/go-on */
  65. {
  66. xfs_agf_t *agf; /* allocation group freelist header */
  67. xfs_alloc_block_t *block; /* btree block record/key lives in */
  68. xfs_agblock_t bno; /* btree block number */
  69. xfs_buf_t *bp; /* buffer for block */
  70. int error; /* error return value */
  71. int i; /* loop index */
  72. xfs_alloc_key_t key; /* kp points here if block is level 0 */
  73. xfs_agblock_t lbno; /* left block's block number */
  74. xfs_buf_t *lbp; /* left block's buffer pointer */
  75. xfs_alloc_block_t *left; /* left btree block */
  76. xfs_alloc_key_t *lkp=NULL; /* left block key pointer */
  77. xfs_alloc_ptr_t *lpp=NULL; /* left block address pointer */
  78. int lrecs=0; /* number of records in left block */
  79. xfs_alloc_rec_t *lrp; /* left block record pointer */
  80. xfs_mount_t *mp; /* mount structure */
  81. int ptr; /* index in btree block for this rec */
  82. xfs_agblock_t rbno; /* right block's block number */
  83. xfs_buf_t *rbp; /* right block's buffer pointer */
  84. xfs_alloc_block_t *right; /* right btree block */
  85. xfs_alloc_key_t *rkp; /* right block key pointer */
  86. xfs_alloc_ptr_t *rpp; /* right block address pointer */
  87. int rrecs=0; /* number of records in right block */
  88. int numrecs;
  89. xfs_alloc_rec_t *rrp; /* right block record pointer */
  90. xfs_btree_cur_t *tcur; /* temporary btree cursor */
  91. /*
  92. * Get the index of the entry being deleted, check for nothing there.
  93. */
  94. ptr = cur->bc_ptrs[level];
  95. if (ptr == 0) {
  96. *stat = 0;
  97. return 0;
  98. }
  99. /*
  100. * Get the buffer & block containing the record or key/ptr.
  101. */
  102. bp = cur->bc_bufs[level];
  103. block = XFS_BUF_TO_ALLOC_BLOCK(bp);
  104. #ifdef DEBUG
  105. if ((error = xfs_btree_check_sblock(cur, block, level, bp)))
  106. return error;
  107. #endif
  108. /*
  109. * Fail if we're off the end of the block.
  110. */
  111. numrecs = be16_to_cpu(block->bb_numrecs);
  112. if (ptr > numrecs) {
  113. *stat = 0;
  114. return 0;
  115. }
  116. XFS_STATS_INC(xs_abt_delrec);
  117. /*
  118. * It's a nonleaf. Excise the key and ptr being deleted, by
  119. * sliding the entries past them down one.
  120. * Log the changed areas of the block.
  121. */
  122. if (level > 0) {
  123. lkp = XFS_ALLOC_KEY_ADDR(block, 1, cur);
  124. lpp = XFS_ALLOC_PTR_ADDR(block, 1, cur);
  125. #ifdef DEBUG
  126. for (i = ptr; i < numrecs; i++) {
  127. if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(lpp[i]), level)))
  128. return error;
  129. }
  130. #endif
  131. if (ptr < numrecs) {
  132. memmove(&lkp[ptr - 1], &lkp[ptr],
  133. (numrecs - ptr) * sizeof(*lkp));
  134. memmove(&lpp[ptr - 1], &lpp[ptr],
  135. (numrecs - ptr) * sizeof(*lpp));
  136. xfs_alloc_log_ptrs(cur, bp, ptr, numrecs - 1);
  137. xfs_alloc_log_keys(cur, bp, ptr, numrecs - 1);
  138. }
  139. }
  140. /*
  141. * It's a leaf. Excise the record being deleted, by sliding the
  142. * entries past it down one. Log the changed areas of the block.
  143. */
  144. else {
  145. lrp = XFS_ALLOC_REC_ADDR(block, 1, cur);
  146. if (ptr < numrecs) {
  147. memmove(&lrp[ptr - 1], &lrp[ptr],
  148. (numrecs - ptr) * sizeof(*lrp));
  149. xfs_alloc_log_recs(cur, bp, ptr, numrecs - 1);
  150. }
  151. /*
  152. * If it's the first record in the block, we'll need a key
  153. * structure to pass up to the next level (updkey).
  154. */
  155. if (ptr == 1) {
  156. key.ar_startblock = lrp->ar_startblock;
  157. key.ar_blockcount = lrp->ar_blockcount;
  158. lkp = &key;
  159. }
  160. }
  161. /*
  162. * Decrement and log the number of entries in the block.
  163. */
  164. numrecs--;
  165. block->bb_numrecs = cpu_to_be16(numrecs);
  166. xfs_alloc_log_block(cur->bc_tp, bp, XFS_BB_NUMRECS);
  167. /*
  168. * See if the longest free extent in the allocation group was
  169. * changed by this operation. True if it's the by-size btree, and
  170. * this is the leaf level, and there is no right sibling block,
  171. * and this was the last record.
  172. */
  173. agf = XFS_BUF_TO_AGF(cur->bc_private.a.agbp);
  174. mp = cur->bc_mp;
  175. if (level == 0 &&
  176. cur->bc_btnum == XFS_BTNUM_CNT &&
  177. be32_to_cpu(block->bb_rightsib) == NULLAGBLOCK &&
  178. ptr > numrecs) {
  179. ASSERT(ptr == numrecs + 1);
  180. /*
  181. * There are still records in the block. Grab the size
  182. * from the last one.
  183. */
  184. if (numrecs) {
  185. rrp = XFS_ALLOC_REC_ADDR(block, numrecs, cur);
  186. agf->agf_longest = rrp->ar_blockcount;
  187. }
  188. /*
  189. * No free extents left.
  190. */
  191. else
  192. agf->agf_longest = 0;
  193. mp->m_perag[be32_to_cpu(agf->agf_seqno)].pagf_longest =
  194. be32_to_cpu(agf->agf_longest);
  195. xfs_alloc_log_agf(cur->bc_tp, cur->bc_private.a.agbp,
  196. XFS_AGF_LONGEST);
  197. }
  198. /*
  199. * Is this the root level? If so, we're almost done.
  200. */
  201. if (level == cur->bc_nlevels - 1) {
  202. /*
  203. * If this is the root level,
  204. * and there's only one entry left,
  205. * and it's NOT the leaf level,
  206. * then we can get rid of this level.
  207. */
  208. if (numrecs == 1 && level > 0) {
  209. /*
  210. * lpp is still set to the first pointer in the block.
  211. * Make it the new root of the btree.
  212. */
  213. bno = be32_to_cpu(agf->agf_roots[cur->bc_btnum]);
  214. agf->agf_roots[cur->bc_btnum] = *lpp;
  215. be32_add_cpu(&agf->agf_levels[cur->bc_btnum], -1);
  216. mp->m_perag[be32_to_cpu(agf->agf_seqno)].pagf_levels[cur->bc_btnum]--;
  217. /*
  218. * Put this buffer/block on the ag's freelist.
  219. */
  220. error = xfs_alloc_put_freelist(cur->bc_tp,
  221. cur->bc_private.a.agbp, NULL, bno, 1);
  222. if (error)
  223. return error;
  224. /*
  225. * Since blocks move to the free list without the
  226. * coordination used in xfs_bmap_finish, we can't allow
  227. * block to be available for reallocation and
  228. * non-transaction writing (user data) until we know
  229. * that the transaction that moved it to the free list
  230. * is permanently on disk. We track the blocks by
  231. * declaring these blocks as "busy"; the busy list is
  232. * maintained on a per-ag basis and each transaction
  233. * records which entries should be removed when the
  234. * iclog commits to disk. If a busy block is
  235. * allocated, the iclog is pushed up to the LSN
  236. * that freed the block.
  237. */
  238. xfs_alloc_mark_busy(cur->bc_tp,
  239. be32_to_cpu(agf->agf_seqno), bno, 1);
  240. xfs_trans_agbtree_delta(cur->bc_tp, -1);
  241. xfs_alloc_log_agf(cur->bc_tp, cur->bc_private.a.agbp,
  242. XFS_AGF_ROOTS | XFS_AGF_LEVELS);
  243. /*
  244. * Update the cursor so there's one fewer level.
  245. */
  246. xfs_btree_setbuf(cur, level, NULL);
  247. cur->bc_nlevels--;
  248. } else if (level > 0 &&
  249. (error = xfs_btree_decrement(cur, level, &i)))
  250. return error;
  251. *stat = 1;
  252. return 0;
  253. }
  254. /*
  255. * If we deleted the leftmost entry in the block, update the
  256. * key values above us in the tree.
  257. */
  258. if (ptr == 1 && (error = xfs_btree_updkey(cur, (union xfs_btree_key *)lkp, level + 1)))
  259. return error;
  260. /*
  261. * If the number of records remaining in the block is at least
  262. * the minimum, we're done.
  263. */
  264. if (numrecs >= XFS_ALLOC_BLOCK_MINRECS(level, cur)) {
  265. if (level > 0 && (error = xfs_btree_decrement(cur, level, &i)))
  266. return error;
  267. *stat = 1;
  268. return 0;
  269. }
  270. /*
  271. * Otherwise, we have to move some records around to keep the
  272. * tree balanced. Look at the left and right sibling blocks to
  273. * see if we can re-balance by moving only one record.
  274. */
  275. rbno = be32_to_cpu(block->bb_rightsib);
  276. lbno = be32_to_cpu(block->bb_leftsib);
  277. bno = NULLAGBLOCK;
  278. ASSERT(rbno != NULLAGBLOCK || lbno != NULLAGBLOCK);
  279. /*
  280. * Duplicate the cursor so our btree manipulations here won't
  281. * disrupt the next level up.
  282. */
  283. if ((error = xfs_btree_dup_cursor(cur, &tcur)))
  284. return error;
  285. /*
  286. * If there's a right sibling, see if it's ok to shift an entry
  287. * out of it.
  288. */
  289. if (rbno != NULLAGBLOCK) {
  290. /*
  291. * Move the temp cursor to the last entry in the next block.
  292. * Actually any entry but the first would suffice.
  293. */
  294. i = xfs_btree_lastrec(tcur, level);
  295. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  296. if ((error = xfs_btree_increment(tcur, level, &i)))
  297. goto error0;
  298. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  299. i = xfs_btree_lastrec(tcur, level);
  300. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  301. /*
  302. * Grab a pointer to the block.
  303. */
  304. rbp = tcur->bc_bufs[level];
  305. right = XFS_BUF_TO_ALLOC_BLOCK(rbp);
  306. #ifdef DEBUG
  307. if ((error = xfs_btree_check_sblock(cur, right, level, rbp)))
  308. goto error0;
  309. #endif
  310. /*
  311. * Grab the current block number, for future use.
  312. */
  313. bno = be32_to_cpu(right->bb_leftsib);
  314. /*
  315. * If right block is full enough so that removing one entry
  316. * won't make it too empty, and left-shifting an entry out
  317. * of right to us works, we're done.
  318. */
  319. if (be16_to_cpu(right->bb_numrecs) - 1 >=
  320. XFS_ALLOC_BLOCK_MINRECS(level, cur)) {
  321. if ((error = xfs_btree_lshift(tcur, level, &i)))
  322. goto error0;
  323. if (i) {
  324. ASSERT(be16_to_cpu(block->bb_numrecs) >=
  325. XFS_ALLOC_BLOCK_MINRECS(level, cur));
  326. xfs_btree_del_cursor(tcur,
  327. XFS_BTREE_NOERROR);
  328. if (level > 0 &&
  329. (error = xfs_btree_decrement(cur, level,
  330. &i)))
  331. return error;
  332. *stat = 1;
  333. return 0;
  334. }
  335. }
  336. /*
  337. * Otherwise, grab the number of records in right for
  338. * future reference, and fix up the temp cursor to point
  339. * to our block again (last record).
  340. */
  341. rrecs = be16_to_cpu(right->bb_numrecs);
  342. if (lbno != NULLAGBLOCK) {
  343. i = xfs_btree_firstrec(tcur, level);
  344. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  345. if ((error = xfs_btree_decrement(tcur, level, &i)))
  346. goto error0;
  347. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  348. }
  349. }
  350. /*
  351. * If there's a left sibling, see if it's ok to shift an entry
  352. * out of it.
  353. */
  354. if (lbno != NULLAGBLOCK) {
  355. /*
  356. * Move the temp cursor to the first entry in the
  357. * previous block.
  358. */
  359. i = xfs_btree_firstrec(tcur, level);
  360. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  361. if ((error = xfs_btree_decrement(tcur, level, &i)))
  362. goto error0;
  363. XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
  364. xfs_btree_firstrec(tcur, level);
  365. /*
  366. * Grab a pointer to the block.
  367. */
  368. lbp = tcur->bc_bufs[level];
  369. left = XFS_BUF_TO_ALLOC_BLOCK(lbp);
  370. #ifdef DEBUG
  371. if ((error = xfs_btree_check_sblock(cur, left, level, lbp)))
  372. goto error0;
  373. #endif
  374. /*
  375. * Grab the current block number, for future use.
  376. */
  377. bno = be32_to_cpu(left->bb_rightsib);
  378. /*
  379. * If left block is full enough so that removing one entry
  380. * won't make it too empty, and right-shifting an entry out
  381. * of left to us works, we're done.
  382. */
  383. if (be16_to_cpu(left->bb_numrecs) - 1 >=
  384. XFS_ALLOC_BLOCK_MINRECS(level, cur)) {
  385. if ((error = xfs_btree_rshift(tcur, level, &i)))
  386. goto error0;
  387. if (i) {
  388. ASSERT(be16_to_cpu(block->bb_numrecs) >=
  389. XFS_ALLOC_BLOCK_MINRECS(level, cur));
  390. xfs_btree_del_cursor(tcur,
  391. XFS_BTREE_NOERROR);
  392. if (level == 0)
  393. cur->bc_ptrs[0]++;
  394. *stat = 1;
  395. return 0;
  396. }
  397. }
  398. /*
  399. * Otherwise, grab the number of records in right for
  400. * future reference.
  401. */
  402. lrecs = be16_to_cpu(left->bb_numrecs);
  403. }
  404. /*
  405. * Delete the temp cursor, we're done with it.
  406. */
  407. xfs_btree_del_cursor(tcur, XFS_BTREE_NOERROR);
  408. /*
  409. * If here, we need to do a join to keep the tree balanced.
  410. */
  411. ASSERT(bno != NULLAGBLOCK);
  412. /*
  413. * See if we can join with the left neighbor block.
  414. */
  415. if (lbno != NULLAGBLOCK &&
  416. lrecs + numrecs <= XFS_ALLOC_BLOCK_MAXRECS(level, cur)) {
  417. /*
  418. * Set "right" to be the starting block,
  419. * "left" to be the left neighbor.
  420. */
  421. rbno = bno;
  422. right = block;
  423. rrecs = be16_to_cpu(right->bb_numrecs);
  424. rbp = bp;
  425. if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
  426. cur->bc_private.a.agno, lbno, 0, &lbp,
  427. XFS_ALLOC_BTREE_REF)))
  428. return error;
  429. left = XFS_BUF_TO_ALLOC_BLOCK(lbp);
  430. lrecs = be16_to_cpu(left->bb_numrecs);
  431. if ((error = xfs_btree_check_sblock(cur, left, level, lbp)))
  432. return error;
  433. }
  434. /*
  435. * If that won't work, see if we can join with the right neighbor block.
  436. */
  437. else if (rbno != NULLAGBLOCK &&
  438. rrecs + numrecs <= XFS_ALLOC_BLOCK_MAXRECS(level, cur)) {
  439. /*
  440. * Set "left" to be the starting block,
  441. * "right" to be the right neighbor.
  442. */
  443. lbno = bno;
  444. left = block;
  445. lrecs = be16_to_cpu(left->bb_numrecs);
  446. lbp = bp;
  447. if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
  448. cur->bc_private.a.agno, rbno, 0, &rbp,
  449. XFS_ALLOC_BTREE_REF)))
  450. return error;
  451. right = XFS_BUF_TO_ALLOC_BLOCK(rbp);
  452. rrecs = be16_to_cpu(right->bb_numrecs);
  453. if ((error = xfs_btree_check_sblock(cur, right, level, rbp)))
  454. return error;
  455. }
  456. /*
  457. * Otherwise, we can't fix the imbalance.
  458. * Just return. This is probably a logic error, but it's not fatal.
  459. */
  460. else {
  461. if (level > 0 && (error = xfs_btree_decrement(cur, level, &i)))
  462. return error;
  463. *stat = 1;
  464. return 0;
  465. }
  466. /*
  467. * We're now going to join "left" and "right" by moving all the stuff
  468. * in "right" to "left" and deleting "right".
  469. */
  470. if (level > 0) {
  471. /*
  472. * It's a non-leaf. Move keys and pointers.
  473. */
  474. lkp = XFS_ALLOC_KEY_ADDR(left, lrecs + 1, cur);
  475. lpp = XFS_ALLOC_PTR_ADDR(left, lrecs + 1, cur);
  476. rkp = XFS_ALLOC_KEY_ADDR(right, 1, cur);
  477. rpp = XFS_ALLOC_PTR_ADDR(right, 1, cur);
  478. #ifdef DEBUG
  479. for (i = 0; i < rrecs; i++) {
  480. if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(rpp[i]), level)))
  481. return error;
  482. }
  483. #endif
  484. memcpy(lkp, rkp, rrecs * sizeof(*lkp));
  485. memcpy(lpp, rpp, rrecs * sizeof(*lpp));
  486. xfs_alloc_log_keys(cur, lbp, lrecs + 1, lrecs + rrecs);
  487. xfs_alloc_log_ptrs(cur, lbp, lrecs + 1, lrecs + rrecs);
  488. } else {
  489. /*
  490. * It's a leaf. Move records.
  491. */
  492. lrp = XFS_ALLOC_REC_ADDR(left, lrecs + 1, cur);
  493. rrp = XFS_ALLOC_REC_ADDR(right, 1, cur);
  494. memcpy(lrp, rrp, rrecs * sizeof(*lrp));
  495. xfs_alloc_log_recs(cur, lbp, lrecs + 1, lrecs + rrecs);
  496. }
  497. /*
  498. * If we joined with the left neighbor, set the buffer in the
  499. * cursor to the left block, and fix up the index.
  500. */
  501. if (bp != lbp) {
  502. xfs_btree_setbuf(cur, level, lbp);
  503. cur->bc_ptrs[level] += lrecs;
  504. }
  505. /*
  506. * If we joined with the right neighbor and there's a level above
  507. * us, increment the cursor at that level.
  508. */
  509. else if (level + 1 < cur->bc_nlevels &&
  510. (error = xfs_btree_increment(cur, level + 1, &i)))
  511. return error;
  512. /*
  513. * Fix up the number of records in the surviving block.
  514. */
  515. lrecs += rrecs;
  516. left->bb_numrecs = cpu_to_be16(lrecs);
  517. /*
  518. * Fix up the right block pointer in the surviving block, and log it.
  519. */
  520. left->bb_rightsib = right->bb_rightsib;
  521. xfs_alloc_log_block(cur->bc_tp, lbp, XFS_BB_NUMRECS | XFS_BB_RIGHTSIB);
  522. /*
  523. * If there is a right sibling now, make it point to the
  524. * remaining block.
  525. */
  526. if (be32_to_cpu(left->bb_rightsib) != NULLAGBLOCK) {
  527. xfs_alloc_block_t *rrblock;
  528. xfs_buf_t *rrbp;
  529. if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
  530. cur->bc_private.a.agno, be32_to_cpu(left->bb_rightsib), 0,
  531. &rrbp, XFS_ALLOC_BTREE_REF)))
  532. return error;
  533. rrblock = XFS_BUF_TO_ALLOC_BLOCK(rrbp);
  534. if ((error = xfs_btree_check_sblock(cur, rrblock, level, rrbp)))
  535. return error;
  536. rrblock->bb_leftsib = cpu_to_be32(lbno);
  537. xfs_alloc_log_block(cur->bc_tp, rrbp, XFS_BB_LEFTSIB);
  538. }
  539. /*
  540. * Free the deleting block by putting it on the freelist.
  541. */
  542. error = xfs_alloc_put_freelist(cur->bc_tp,
  543. cur->bc_private.a.agbp, NULL, rbno, 1);
  544. if (error)
  545. return error;
  546. /*
  547. * Since blocks move to the free list without the coordination
  548. * used in xfs_bmap_finish, we can't allow block to be available
  549. * for reallocation and non-transaction writing (user data)
  550. * until we know that the transaction that moved it to the free
  551. * list is permanently on disk. We track the blocks by declaring
  552. * these blocks as "busy"; the busy list is maintained on a
  553. * per-ag basis and each transaction records which entries
  554. * should be removed when the iclog commits to disk. If a
  555. * busy block is allocated, the iclog is pushed up to the
  556. * LSN that freed the block.
  557. */
  558. xfs_alloc_mark_busy(cur->bc_tp, be32_to_cpu(agf->agf_seqno), bno, 1);
  559. xfs_trans_agbtree_delta(cur->bc_tp, -1);
  560. /*
  561. * Adjust the current level's cursor so that we're left referring
  562. * to the right node, after we're done.
  563. * If this leaves the ptr value 0 our caller will fix it up.
  564. */
  565. if (level > 0)
  566. cur->bc_ptrs[level]--;
  567. /*
  568. * Return value means the next level up has something to do.
  569. */
  570. *stat = 2;
  571. return 0;
  572. error0:
  573. xfs_btree_del_cursor(tcur, XFS_BTREE_ERROR);
  574. return error;
  575. }
  576. /*
  577. * Insert one record/level. Return information to the caller
  578. * allowing the next level up to proceed if necessary.
  579. */
  580. STATIC int /* error */
  581. xfs_alloc_insrec(
  582. xfs_btree_cur_t *cur, /* btree cursor */
  583. int level, /* level to insert record at */
  584. xfs_agblock_t *bnop, /* i/o: block number inserted */
  585. xfs_alloc_rec_t *recp, /* i/o: record data inserted */
  586. xfs_btree_cur_t **curp, /* output: new cursor replacing cur */
  587. int *stat) /* output: success/failure */
  588. {
  589. xfs_agf_t *agf; /* allocation group freelist header */
  590. xfs_alloc_block_t *block; /* btree block record/key lives in */
  591. xfs_buf_t *bp; /* buffer for block */
  592. int error; /* error return value */
  593. int i; /* loop index */
  594. xfs_alloc_key_t key; /* key value being inserted */
  595. xfs_alloc_key_t *kp; /* pointer to btree keys */
  596. xfs_agblock_t nbno; /* block number of allocated block */
  597. xfs_btree_cur_t *ncur; /* new cursor to be used at next lvl */
  598. xfs_alloc_key_t nkey; /* new key value, from split */
  599. xfs_alloc_rec_t nrec; /* new record value, for caller */
  600. int numrecs;
  601. int optr; /* old ptr value */
  602. xfs_alloc_ptr_t *pp; /* pointer to btree addresses */
  603. int ptr; /* index in btree block for this rec */
  604. xfs_alloc_rec_t *rp; /* pointer to btree records */
  605. ASSERT(be32_to_cpu(recp->ar_blockcount) > 0);
  606. /*
  607. * GCC doesn't understand the (arguably complex) control flow in
  608. * this function and complains about uninitialized structure fields
  609. * without this.
  610. */
  611. memset(&nrec, 0, sizeof(nrec));
  612. /*
  613. * If we made it to the root level, allocate a new root block
  614. * and we're done.
  615. */
  616. if (level >= cur->bc_nlevels) {
  617. XFS_STATS_INC(xs_abt_insrec);
  618. if ((error = xfs_alloc_newroot(cur, &i)))
  619. return error;
  620. *bnop = NULLAGBLOCK;
  621. *stat = i;
  622. return 0;
  623. }
  624. /*
  625. * Make a key out of the record data to be inserted, and save it.
  626. */
  627. key.ar_startblock = recp->ar_startblock;
  628. key.ar_blockcount = recp->ar_blockcount;
  629. optr = ptr = cur->bc_ptrs[level];
  630. /*
  631. * If we're off the left edge, return failure.
  632. */
  633. if (ptr == 0) {
  634. *stat = 0;
  635. return 0;
  636. }
  637. XFS_STATS_INC(xs_abt_insrec);
  638. /*
  639. * Get pointers to the btree buffer and block.
  640. */
  641. bp = cur->bc_bufs[level];
  642. block = XFS_BUF_TO_ALLOC_BLOCK(bp);
  643. numrecs = be16_to_cpu(block->bb_numrecs);
  644. #ifdef DEBUG
  645. if ((error = xfs_btree_check_sblock(cur, block, level, bp)))
  646. return error;
  647. /*
  648. * Check that the new entry is being inserted in the right place.
  649. */
  650. if (ptr <= numrecs) {
  651. if (level == 0) {
  652. rp = XFS_ALLOC_REC_ADDR(block, ptr, cur);
  653. xfs_btree_check_rec(cur->bc_btnum, recp, rp);
  654. } else {
  655. kp = XFS_ALLOC_KEY_ADDR(block, ptr, cur);
  656. xfs_btree_check_key(cur->bc_btnum, &key, kp);
  657. }
  658. }
  659. #endif
  660. nbno = NULLAGBLOCK;
  661. ncur = NULL;
  662. /*
  663. * If the block is full, we can't insert the new entry until we
  664. * make the block un-full.
  665. */
  666. if (numrecs == XFS_ALLOC_BLOCK_MAXRECS(level, cur)) {
  667. /*
  668. * First, try shifting an entry to the right neighbor.
  669. */
  670. if ((error = xfs_btree_rshift(cur, level, &i)))
  671. return error;
  672. if (i) {
  673. /* nothing */
  674. }
  675. /*
  676. * Next, try shifting an entry to the left neighbor.
  677. */
  678. else {
  679. if ((error = xfs_btree_lshift(cur, level, &i)))
  680. return error;
  681. if (i)
  682. optr = ptr = cur->bc_ptrs[level];
  683. else {
  684. /*
  685. * Next, try splitting the current block in
  686. * half. If this works we have to re-set our
  687. * variables because we could be in a
  688. * different block now.
  689. */
  690. if ((error = xfs_alloc_split(cur, level, &nbno,
  691. &nkey, &ncur, &i)))
  692. return error;
  693. if (i) {
  694. bp = cur->bc_bufs[level];
  695. block = XFS_BUF_TO_ALLOC_BLOCK(bp);
  696. #ifdef DEBUG
  697. if ((error =
  698. xfs_btree_check_sblock(cur,
  699. block, level, bp)))
  700. return error;
  701. #endif
  702. ptr = cur->bc_ptrs[level];
  703. nrec.ar_startblock = nkey.ar_startblock;
  704. nrec.ar_blockcount = nkey.ar_blockcount;
  705. }
  706. /*
  707. * Otherwise the insert fails.
  708. */
  709. else {
  710. *stat = 0;
  711. return 0;
  712. }
  713. }
  714. }
  715. }
  716. /*
  717. * At this point we know there's room for our new entry in the block
  718. * we're pointing at.
  719. */
  720. numrecs = be16_to_cpu(block->bb_numrecs);
  721. if (level > 0) {
  722. /*
  723. * It's a non-leaf entry. Make a hole for the new data
  724. * in the key and ptr regions of the block.
  725. */
  726. kp = XFS_ALLOC_KEY_ADDR(block, 1, cur);
  727. pp = XFS_ALLOC_PTR_ADDR(block, 1, cur);
  728. #ifdef DEBUG
  729. for (i = numrecs; i >= ptr; i--) {
  730. if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(pp[i - 1]), level)))
  731. return error;
  732. }
  733. #endif
  734. memmove(&kp[ptr], &kp[ptr - 1],
  735. (numrecs - ptr + 1) * sizeof(*kp));
  736. memmove(&pp[ptr], &pp[ptr - 1],
  737. (numrecs - ptr + 1) * sizeof(*pp));
  738. #ifdef DEBUG
  739. if ((error = xfs_btree_check_sptr(cur, *bnop, level)))
  740. return error;
  741. #endif
  742. /*
  743. * Now stuff the new data in, bump numrecs and log the new data.
  744. */
  745. kp[ptr - 1] = key;
  746. pp[ptr - 1] = cpu_to_be32(*bnop);
  747. numrecs++;
  748. block->bb_numrecs = cpu_to_be16(numrecs);
  749. xfs_alloc_log_keys(cur, bp, ptr, numrecs);
  750. xfs_alloc_log_ptrs(cur, bp, ptr, numrecs);
  751. #ifdef DEBUG
  752. if (ptr < numrecs)
  753. xfs_btree_check_key(cur->bc_btnum, kp + ptr - 1,
  754. kp + ptr);
  755. #endif
  756. } else {
  757. /*
  758. * It's a leaf entry. Make a hole for the new record.
  759. */
  760. rp = XFS_ALLOC_REC_ADDR(block, 1, cur);
  761. memmove(&rp[ptr], &rp[ptr - 1],
  762. (numrecs - ptr + 1) * sizeof(*rp));
  763. /*
  764. * Now stuff the new record in, bump numrecs
  765. * and log the new data.
  766. */
  767. rp[ptr - 1] = *recp;
  768. numrecs++;
  769. block->bb_numrecs = cpu_to_be16(numrecs);
  770. xfs_alloc_log_recs(cur, bp, ptr, numrecs);
  771. #ifdef DEBUG
  772. if (ptr < numrecs)
  773. xfs_btree_check_rec(cur->bc_btnum, rp + ptr - 1,
  774. rp + ptr);
  775. #endif
  776. }
  777. /*
  778. * Log the new number of records in the btree header.
  779. */
  780. xfs_alloc_log_block(cur->bc_tp, bp, XFS_BB_NUMRECS);
  781. /*
  782. * If we inserted at the start of a block, update the parents' keys.
  783. */
  784. if (optr == 1 && (error = xfs_btree_updkey(cur, (union xfs_btree_key *)&key, level + 1)))
  785. return error;
  786. /*
  787. * Look to see if the longest extent in the allocation group
  788. * needs to be updated.
  789. */
  790. agf = XFS_BUF_TO_AGF(cur->bc_private.a.agbp);
  791. if (level == 0 &&
  792. cur->bc_btnum == XFS_BTNUM_CNT &&
  793. be32_to_cpu(block->bb_rightsib) == NULLAGBLOCK &&
  794. be32_to_cpu(recp->ar_blockcount) > be32_to_cpu(agf->agf_longest)) {
  795. /*
  796. * If this is a leaf in the by-size btree and there
  797. * is no right sibling block and this block is bigger
  798. * than the previous longest block, update it.
  799. */
  800. agf->agf_longest = recp->ar_blockcount;
  801. cur->bc_mp->m_perag[be32_to_cpu(agf->agf_seqno)].pagf_longest
  802. = be32_to_cpu(recp->ar_blockcount);
  803. xfs_alloc_log_agf(cur->bc_tp, cur->bc_private.a.agbp,
  804. XFS_AGF_LONGEST);
  805. }
  806. /*
  807. * Return the new block number, if any.
  808. * If there is one, give back a record value and a cursor too.
  809. */
  810. *bnop = nbno;
  811. if (nbno != NULLAGBLOCK) {
  812. *recp = nrec;
  813. *curp = ncur;
  814. }
  815. *stat = 1;
  816. return 0;
  817. }
  818. /*
  819. * Log header fields from a btree block.
  820. */
  821. STATIC void
  822. xfs_alloc_log_block(
  823. xfs_trans_t *tp, /* transaction pointer */
  824. xfs_buf_t *bp, /* buffer containing btree block */
  825. int fields) /* mask of fields: XFS_BB_... */
  826. {
  827. int first; /* first byte offset logged */
  828. int last; /* last byte offset logged */
  829. static const short offsets[] = { /* table of offsets */
  830. offsetof(xfs_alloc_block_t, bb_magic),
  831. offsetof(xfs_alloc_block_t, bb_level),
  832. offsetof(xfs_alloc_block_t, bb_numrecs),
  833. offsetof(xfs_alloc_block_t, bb_leftsib),
  834. offsetof(xfs_alloc_block_t, bb_rightsib),
  835. sizeof(xfs_alloc_block_t)
  836. };
  837. xfs_btree_offsets(fields, offsets, XFS_BB_NUM_BITS, &first, &last);
  838. xfs_trans_log_buf(tp, bp, first, last);
  839. }
  840. /*
  841. * Log keys from a btree block (nonleaf).
  842. */
  843. STATIC void
  844. xfs_alloc_log_keys(
  845. xfs_btree_cur_t *cur, /* btree cursor */
  846. xfs_buf_t *bp, /* buffer containing btree block */
  847. int kfirst, /* index of first key to log */
  848. int klast) /* index of last key to log */
  849. {
  850. xfs_alloc_block_t *block; /* btree block to log from */
  851. int first; /* first byte offset logged */
  852. xfs_alloc_key_t *kp; /* key pointer in btree block */
  853. int last; /* last byte offset logged */
  854. block = XFS_BUF_TO_ALLOC_BLOCK(bp);
  855. kp = XFS_ALLOC_KEY_ADDR(block, 1, cur);
  856. first = (int)((xfs_caddr_t)&kp[kfirst - 1] - (xfs_caddr_t)block);
  857. last = (int)(((xfs_caddr_t)&kp[klast] - 1) - (xfs_caddr_t)block);
  858. xfs_trans_log_buf(cur->bc_tp, bp, first, last);
  859. }
  860. /*
  861. * Log block pointer fields from a btree block (nonleaf).
  862. */
  863. STATIC void
  864. xfs_alloc_log_ptrs(
  865. xfs_btree_cur_t *cur, /* btree cursor */
  866. xfs_buf_t *bp, /* buffer containing btree block */
  867. int pfirst, /* index of first pointer to log */
  868. int plast) /* index of last pointer to log */
  869. {
  870. xfs_alloc_block_t *block; /* btree block to log from */
  871. int first; /* first byte offset logged */
  872. int last; /* last byte offset logged */
  873. xfs_alloc_ptr_t *pp; /* block-pointer pointer in btree blk */
  874. block = XFS_BUF_TO_ALLOC_BLOCK(bp);
  875. pp = XFS_ALLOC_PTR_ADDR(block, 1, cur);
  876. first = (int)((xfs_caddr_t)&pp[pfirst - 1] - (xfs_caddr_t)block);
  877. last = (int)(((xfs_caddr_t)&pp[plast] - 1) - (xfs_caddr_t)block);
  878. xfs_trans_log_buf(cur->bc_tp, bp, first, last);
  879. }
  880. /*
  881. * Log records from a btree block (leaf).
  882. */
  883. STATIC void
  884. xfs_alloc_log_recs(
  885. xfs_btree_cur_t *cur, /* btree cursor */
  886. xfs_buf_t *bp, /* buffer containing btree block */
  887. int rfirst, /* index of first record to log */
  888. int rlast) /* index of last record to log */
  889. {
  890. xfs_alloc_block_t *block; /* btree block to log from */
  891. int first; /* first byte offset logged */
  892. int last; /* last byte offset logged */
  893. xfs_alloc_rec_t *rp; /* record pointer for btree block */
  894. block = XFS_BUF_TO_ALLOC_BLOCK(bp);
  895. rp = XFS_ALLOC_REC_ADDR(block, 1, cur);
  896. #ifdef DEBUG
  897. {
  898. xfs_agf_t *agf;
  899. xfs_alloc_rec_t *p;
  900. agf = XFS_BUF_TO_AGF(cur->bc_private.a.agbp);
  901. for (p = &rp[rfirst - 1]; p <= &rp[rlast - 1]; p++)
  902. ASSERT(be32_to_cpu(p->ar_startblock) +
  903. be32_to_cpu(p->ar_blockcount) <=
  904. be32_to_cpu(agf->agf_length));
  905. }
  906. #endif
  907. first = (int)((xfs_caddr_t)&rp[rfirst - 1] - (xfs_caddr_t)block);
  908. last = (int)(((xfs_caddr_t)&rp[rlast] - 1) - (xfs_caddr_t)block);
  909. xfs_trans_log_buf(cur->bc_tp, bp, first, last);
  910. }
  911. /*
  912. * Allocate a new root block, fill it in.
  913. */
  914. STATIC int /* error */
  915. xfs_alloc_newroot(
  916. xfs_btree_cur_t *cur, /* btree cursor */
  917. int *stat) /* success/failure */
  918. {
  919. int error; /* error return value */
  920. xfs_agblock_t lbno; /* left block number */
  921. xfs_buf_t *lbp; /* left btree buffer */
  922. xfs_alloc_block_t *left; /* left btree block */
  923. xfs_mount_t *mp; /* mount structure */
  924. xfs_agblock_t nbno; /* new block number */
  925. xfs_buf_t *nbp; /* new (root) buffer */
  926. xfs_alloc_block_t *new; /* new (root) btree block */
  927. int nptr; /* new value for key index, 1 or 2 */
  928. xfs_agblock_t rbno; /* right block number */
  929. xfs_buf_t *rbp; /* right btree buffer */
  930. xfs_alloc_block_t *right; /* right btree block */
  931. mp = cur->bc_mp;
  932. ASSERT(cur->bc_nlevels < XFS_AG_MAXLEVELS(mp));
  933. /*
  934. * Get a buffer from the freelist blocks, for the new root.
  935. */
  936. error = xfs_alloc_get_freelist(cur->bc_tp,
  937. cur->bc_private.a.agbp, &nbno, 1);
  938. if (error)
  939. return error;
  940. /*
  941. * None available, we fail.
  942. */
  943. if (nbno == NULLAGBLOCK) {
  944. *stat = 0;
  945. return 0;
  946. }
  947. xfs_trans_agbtree_delta(cur->bc_tp, 1);
  948. nbp = xfs_btree_get_bufs(mp, cur->bc_tp, cur->bc_private.a.agno, nbno,
  949. 0);
  950. new = XFS_BUF_TO_ALLOC_BLOCK(nbp);
  951. /*
  952. * Set the root data in the a.g. freespace structure.
  953. */
  954. {
  955. xfs_agf_t *agf; /* a.g. freespace header */
  956. xfs_agnumber_t seqno;
  957. agf = XFS_BUF_TO_AGF(cur->bc_private.a.agbp);
  958. agf->agf_roots[cur->bc_btnum] = cpu_to_be32(nbno);
  959. be32_add_cpu(&agf->agf_levels[cur->bc_btnum], 1);
  960. seqno = be32_to_cpu(agf->agf_seqno);
  961. mp->m_perag[seqno].pagf_levels[cur->bc_btnum]++;
  962. xfs_alloc_log_agf(cur->bc_tp, cur->bc_private.a.agbp,
  963. XFS_AGF_ROOTS | XFS_AGF_LEVELS);
  964. }
  965. /*
  966. * At the previous root level there are now two blocks: the old
  967. * root, and the new block generated when it was split.
  968. * We don't know which one the cursor is pointing at, so we
  969. * set up variables "left" and "right" for each case.
  970. */
  971. lbp = cur->bc_bufs[cur->bc_nlevels - 1];
  972. left = XFS_BUF_TO_ALLOC_BLOCK(lbp);
  973. #ifdef DEBUG
  974. if ((error = xfs_btree_check_sblock(cur, left, cur->bc_nlevels - 1, lbp)))
  975. return error;
  976. #endif
  977. if (be32_to_cpu(left->bb_rightsib) != NULLAGBLOCK) {
  978. /*
  979. * Our block is left, pick up the right block.
  980. */
  981. lbno = XFS_DADDR_TO_AGBNO(mp, XFS_BUF_ADDR(lbp));
  982. rbno = be32_to_cpu(left->bb_rightsib);
  983. if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
  984. cur->bc_private.a.agno, rbno, 0, &rbp,
  985. XFS_ALLOC_BTREE_REF)))
  986. return error;
  987. right = XFS_BUF_TO_ALLOC_BLOCK(rbp);
  988. if ((error = xfs_btree_check_sblock(cur, right,
  989. cur->bc_nlevels - 1, rbp)))
  990. return error;
  991. nptr = 1;
  992. } else {
  993. /*
  994. * Our block is right, pick up the left block.
  995. */
  996. rbp = lbp;
  997. right = left;
  998. rbno = XFS_DADDR_TO_AGBNO(mp, XFS_BUF_ADDR(rbp));
  999. lbno = be32_to_cpu(right->bb_leftsib);
  1000. if ((error = xfs_btree_read_bufs(mp, cur->bc_tp,
  1001. cur->bc_private.a.agno, lbno, 0, &lbp,
  1002. XFS_ALLOC_BTREE_REF)))
  1003. return error;
  1004. left = XFS_BUF_TO_ALLOC_BLOCK(lbp);
  1005. if ((error = xfs_btree_check_sblock(cur, left,
  1006. cur->bc_nlevels - 1, lbp)))
  1007. return error;
  1008. nptr = 2;
  1009. }
  1010. /*
  1011. * Fill in the new block's btree header and log it.
  1012. */
  1013. new->bb_magic = cpu_to_be32(xfs_magics[cur->bc_btnum]);
  1014. new->bb_level = cpu_to_be16(cur->bc_nlevels);
  1015. new->bb_numrecs = cpu_to_be16(2);
  1016. new->bb_leftsib = cpu_to_be32(NULLAGBLOCK);
  1017. new->bb_rightsib = cpu_to_be32(NULLAGBLOCK);
  1018. xfs_alloc_log_block(cur->bc_tp, nbp, XFS_BB_ALL_BITS);
  1019. ASSERT(lbno != NULLAGBLOCK && rbno != NULLAGBLOCK);
  1020. /*
  1021. * Fill in the key data in the new root.
  1022. */
  1023. {
  1024. xfs_alloc_key_t *kp; /* btree key pointer */
  1025. kp = XFS_ALLOC_KEY_ADDR(new, 1, cur);
  1026. if (be16_to_cpu(left->bb_level) > 0) {
  1027. kp[0] = *XFS_ALLOC_KEY_ADDR(left, 1, cur);
  1028. kp[1] = *XFS_ALLOC_KEY_ADDR(right, 1, cur);
  1029. } else {
  1030. xfs_alloc_rec_t *rp; /* btree record pointer */
  1031. rp = XFS_ALLOC_REC_ADDR(left, 1, cur);
  1032. kp[0].ar_startblock = rp->ar_startblock;
  1033. kp[0].ar_blockcount = rp->ar_blockcount;
  1034. rp = XFS_ALLOC_REC_ADDR(right, 1, cur);
  1035. kp[1].ar_startblock = rp->ar_startblock;
  1036. kp[1].ar_blockcount = rp->ar_blockcount;
  1037. }
  1038. }
  1039. xfs_alloc_log_keys(cur, nbp, 1, 2);
  1040. /*
  1041. * Fill in the pointer data in the new root.
  1042. */
  1043. {
  1044. xfs_alloc_ptr_t *pp; /* btree address pointer */
  1045. pp = XFS_ALLOC_PTR_ADDR(new, 1, cur);
  1046. pp[0] = cpu_to_be32(lbno);
  1047. pp[1] = cpu_to_be32(rbno);
  1048. }
  1049. xfs_alloc_log_ptrs(cur, nbp, 1, 2);
  1050. /*
  1051. * Fix up the cursor.
  1052. */
  1053. xfs_btree_setbuf(cur, cur->bc_nlevels, nbp);
  1054. cur->bc_ptrs[cur->bc_nlevels] = nptr;
  1055. cur->bc_nlevels++;
  1056. *stat = 1;
  1057. return 0;
  1058. }
  1059. /*
  1060. * Split cur/level block in half.
  1061. * Return new block number and its first record (to be inserted into parent).
  1062. */
  1063. STATIC int /* error */
  1064. xfs_alloc_split(
  1065. xfs_btree_cur_t *cur, /* btree cursor */
  1066. int level, /* level to split */
  1067. xfs_agblock_t *bnop, /* output: block number allocated */
  1068. xfs_alloc_key_t *keyp, /* output: first key of new block */
  1069. xfs_btree_cur_t **curp, /* output: new cursor */
  1070. int *stat) /* success/failure */
  1071. {
  1072. int error; /* error return value */
  1073. int i; /* loop index/record number */
  1074. xfs_agblock_t lbno; /* left (current) block number */
  1075. xfs_buf_t *lbp; /* buffer for left block */
  1076. xfs_alloc_block_t *left; /* left (current) btree block */
  1077. xfs_agblock_t rbno; /* right (new) block number */
  1078. xfs_buf_t *rbp; /* buffer for right block */
  1079. xfs_alloc_block_t *right; /* right (new) btree block */
  1080. /*
  1081. * Allocate the new block from the freelist.
  1082. * If we can't do it, we're toast. Give up.
  1083. */
  1084. error = xfs_alloc_get_freelist(cur->bc_tp,
  1085. cur->bc_private.a.agbp, &rbno, 1);
  1086. if (error)
  1087. return error;
  1088. if (rbno == NULLAGBLOCK) {
  1089. *stat = 0;
  1090. return 0;
  1091. }
  1092. xfs_trans_agbtree_delta(cur->bc_tp, 1);
  1093. rbp = xfs_btree_get_bufs(cur->bc_mp, cur->bc_tp, cur->bc_private.a.agno,
  1094. rbno, 0);
  1095. /*
  1096. * Set up the new block as "right".
  1097. */
  1098. right = XFS_BUF_TO_ALLOC_BLOCK(rbp);
  1099. /*
  1100. * "Left" is the current (according to the cursor) block.
  1101. */
  1102. lbp = cur->bc_bufs[level];
  1103. left = XFS_BUF_TO_ALLOC_BLOCK(lbp);
  1104. #ifdef DEBUG
  1105. if ((error = xfs_btree_check_sblock(cur, left, level, lbp)))
  1106. return error;
  1107. #endif
  1108. /*
  1109. * Fill in the btree header for the new block.
  1110. */
  1111. right->bb_magic = cpu_to_be32(xfs_magics[cur->bc_btnum]);
  1112. right->bb_level = left->bb_level;
  1113. right->bb_numrecs = cpu_to_be16(be16_to_cpu(left->bb_numrecs) / 2);
  1114. /*
  1115. * Make sure that if there's an odd number of entries now, that
  1116. * each new block will have the same number of entries.
  1117. */
  1118. if ((be16_to_cpu(left->bb_numrecs) & 1) &&
  1119. cur->bc_ptrs[level] <= be16_to_cpu(right->bb_numrecs) + 1)
  1120. be16_add_cpu(&right->bb_numrecs, 1);
  1121. i = be16_to_cpu(left->bb_numrecs) - be16_to_cpu(right->bb_numrecs) + 1;
  1122. /*
  1123. * For non-leaf blocks, copy keys and addresses over to the new block.
  1124. */
  1125. if (level > 0) {
  1126. xfs_alloc_key_t *lkp; /* left btree key pointer */
  1127. xfs_alloc_ptr_t *lpp; /* left btree address pointer */
  1128. xfs_alloc_key_t *rkp; /* right btree key pointer */
  1129. xfs_alloc_ptr_t *rpp; /* right btree address pointer */
  1130. lkp = XFS_ALLOC_KEY_ADDR(left, i, cur);
  1131. lpp = XFS_ALLOC_PTR_ADDR(left, i, cur);
  1132. rkp = XFS_ALLOC_KEY_ADDR(right, 1, cur);
  1133. rpp = XFS_ALLOC_PTR_ADDR(right, 1, cur);
  1134. #ifdef DEBUG
  1135. for (i = 0; i < be16_to_cpu(right->bb_numrecs); i++) {
  1136. if ((error = xfs_btree_check_sptr(cur, be32_to_cpu(lpp[i]), level)))
  1137. return error;
  1138. }
  1139. #endif
  1140. memcpy(rkp, lkp, be16_to_cpu(right->bb_numrecs) * sizeof(*rkp));
  1141. memcpy(rpp, lpp, be16_to_cpu(right->bb_numrecs) * sizeof(*rpp));
  1142. xfs_alloc_log_keys(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
  1143. xfs_alloc_log_ptrs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
  1144. *keyp = *rkp;
  1145. }
  1146. /*
  1147. * For leaf blocks, copy records over to the new block.
  1148. */
  1149. else {
  1150. xfs_alloc_rec_t *lrp; /* left btree record pointer */
  1151. xfs_alloc_rec_t *rrp; /* right btree record pointer */
  1152. lrp = XFS_ALLOC_REC_ADDR(left, i, cur);
  1153. rrp = XFS_ALLOC_REC_ADDR(right, 1, cur);
  1154. memcpy(rrp, lrp, be16_to_cpu(right->bb_numrecs) * sizeof(*rrp));
  1155. xfs_alloc_log_recs(cur, rbp, 1, be16_to_cpu(right->bb_numrecs));
  1156. keyp->ar_startblock = rrp->ar_startblock;
  1157. keyp->ar_blockcount = rrp->ar_blockcount;
  1158. }
  1159. /*
  1160. * Find the left block number by looking in the buffer.
  1161. * Adjust numrecs, sibling pointers.
  1162. */
  1163. lbno = XFS_DADDR_TO_AGBNO(cur->bc_mp, XFS_BUF_ADDR(lbp));
  1164. be16_add_cpu(&left->bb_numrecs, -(be16_to_cpu(right->bb_numrecs)));
  1165. right->bb_rightsib = left->bb_rightsib;
  1166. left->bb_rightsib = cpu_to_be32(rbno);
  1167. right->bb_leftsib = cpu_to_be32(lbno);
  1168. xfs_alloc_log_block(cur->bc_tp, rbp, XFS_BB_ALL_BITS);
  1169. xfs_alloc_log_block(cur->bc_tp, lbp, XFS_BB_NUMRECS | XFS_BB_RIGHTSIB);
  1170. /*
  1171. * If there's a block to the new block's right, make that block
  1172. * point back to right instead of to left.
  1173. */
  1174. if (be32_to_cpu(right->bb_rightsib) != NULLAGBLOCK) {
  1175. xfs_alloc_block_t *rrblock; /* rr btree block */
  1176. xfs_buf_t *rrbp; /* buffer for rrblock */
  1177. if ((error = xfs_btree_read_bufs(cur->bc_mp, cur->bc_tp,
  1178. cur->bc_private.a.agno, be32_to_cpu(right->bb_rightsib), 0,
  1179. &rrbp, XFS_ALLOC_BTREE_REF)))
  1180. return error;
  1181. rrblock = XFS_BUF_TO_ALLOC_BLOCK(rrbp);
  1182. if ((error = xfs_btree_check_sblock(cur, rrblock, level, rrbp)))
  1183. return error;
  1184. rrblock->bb_leftsib = cpu_to_be32(rbno);
  1185. xfs_alloc_log_block(cur->bc_tp, rrbp, XFS_BB_LEFTSIB);
  1186. }
  1187. /*
  1188. * If the cursor is really in the right block, move it there.
  1189. * If it's just pointing past the last entry in left, then we'll
  1190. * insert there, so don't change anything in that case.
  1191. */
  1192. if (cur->bc_ptrs[level] > be16_to_cpu(left->bb_numrecs) + 1) {
  1193. xfs_btree_setbuf(cur, level, rbp);
  1194. cur->bc_ptrs[level] -= be16_to_cpu(left->bb_numrecs);
  1195. }
  1196. /*
  1197. * If there are more levels, we'll need another cursor which refers to
  1198. * the right block, no matter where this cursor was.
  1199. */
  1200. if (level + 1 < cur->bc_nlevels) {
  1201. if ((error = xfs_btree_dup_cursor(cur, curp)))
  1202. return error;
  1203. (*curp)->bc_ptrs[level + 1]++;
  1204. }
  1205. *bnop = rbno;
  1206. *stat = 1;
  1207. return 0;
  1208. }
  1209. /*
  1210. * Externally visible routines.
  1211. */
  1212. /*
  1213. * Delete the record pointed to by cur.
  1214. * The cursor refers to the place where the record was (could be inserted)
  1215. * when the operation returns.
  1216. */
  1217. int /* error */
  1218. xfs_alloc_delete(
  1219. xfs_btree_cur_t *cur, /* btree cursor */
  1220. int *stat) /* success/failure */
  1221. {
  1222. int error; /* error return value */
  1223. int i; /* result code */
  1224. int level; /* btree level */
  1225. /*
  1226. * Go up the tree, starting at leaf level.
  1227. * If 2 is returned then a join was done; go to the next level.
  1228. * Otherwise we are done.
  1229. */
  1230. for (level = 0, i = 2; i == 2; level++) {
  1231. if ((error = xfs_alloc_delrec(cur, level, &i)))
  1232. return error;
  1233. }
  1234. if (i == 0) {
  1235. for (level = 1; level < cur->bc_nlevels; level++) {
  1236. if (cur->bc_ptrs[level] == 0) {
  1237. if ((error = xfs_btree_decrement(cur, level, &i)))
  1238. return error;
  1239. break;
  1240. }
  1241. }
  1242. }
  1243. *stat = i;
  1244. return 0;
  1245. }
  1246. /*
  1247. * Get the data from the pointed-to record.
  1248. */
  1249. int /* error */
  1250. xfs_alloc_get_rec(
  1251. xfs_btree_cur_t *cur, /* btree cursor */
  1252. xfs_agblock_t *bno, /* output: starting block of extent */
  1253. xfs_extlen_t *len, /* output: length of extent */
  1254. int *stat) /* output: success/failure */
  1255. {
  1256. xfs_alloc_block_t *block; /* btree block */
  1257. #ifdef DEBUG
  1258. int error; /* error return value */
  1259. #endif
  1260. int ptr; /* record number */
  1261. ptr = cur->bc_ptrs[0];
  1262. block = XFS_BUF_TO_ALLOC_BLOCK(cur->bc_bufs[0]);
  1263. #ifdef DEBUG
  1264. if ((error = xfs_btree_check_sblock(cur, block, 0, cur->bc_bufs[0])))
  1265. return error;
  1266. #endif
  1267. /*
  1268. * Off the right end or left end, return failure.
  1269. */
  1270. if (ptr > be16_to_cpu(block->bb_numrecs) || ptr <= 0) {
  1271. *stat = 0;
  1272. return 0;
  1273. }
  1274. /*
  1275. * Point to the record and extract its data.
  1276. */
  1277. {
  1278. xfs_alloc_rec_t *rec; /* record data */
  1279. rec = XFS_ALLOC_REC_ADDR(block, ptr, cur);
  1280. *bno = be32_to_cpu(rec->ar_startblock);
  1281. *len = be32_to_cpu(rec->ar_blockcount);
  1282. }
  1283. *stat = 1;
  1284. return 0;
  1285. }
  1286. /*
  1287. * Insert the current record at the point referenced by cur.
  1288. * The cursor may be inconsistent on return if splits have been done.
  1289. */
  1290. int /* error */
  1291. xfs_alloc_insert(
  1292. xfs_btree_cur_t *cur, /* btree cursor */
  1293. int *stat) /* success/failure */
  1294. {
  1295. int error; /* error return value */
  1296. int i; /* result value, 0 for failure */
  1297. int level; /* current level number in btree */
  1298. xfs_agblock_t nbno; /* new block number (split result) */
  1299. xfs_btree_cur_t *ncur; /* new cursor (split result) */
  1300. xfs_alloc_rec_t nrec; /* record being inserted this level */
  1301. xfs_btree_cur_t *pcur; /* previous level's cursor */
  1302. level = 0;
  1303. nbno = NULLAGBLOCK;
  1304. nrec.ar_startblock = cpu_to_be32(cur->bc_rec.a.ar_startblock);
  1305. nrec.ar_blockcount = cpu_to_be32(cur->bc_rec.a.ar_blockcount);
  1306. ncur = NULL;
  1307. pcur = cur;
  1308. /*
  1309. * Loop going up the tree, starting at the leaf level.
  1310. * Stop when we don't get a split block, that must mean that
  1311. * the insert is finished with this level.
  1312. */
  1313. do {
  1314. /*
  1315. * Insert nrec/nbno into this level of the tree.
  1316. * Note if we fail, nbno will be null.
  1317. */
  1318. if ((error = xfs_alloc_insrec(pcur, level++, &nbno, &nrec, &ncur,
  1319. &i))) {
  1320. if (pcur != cur)
  1321. xfs_btree_del_cursor(pcur, XFS_BTREE_ERROR);
  1322. return error;
  1323. }
  1324. /*
  1325. * See if the cursor we just used is trash.
  1326. * Can't trash the caller's cursor, but otherwise we should
  1327. * if ncur is a new cursor or we're about to be done.
  1328. */
  1329. if (pcur != cur && (ncur || nbno == NULLAGBLOCK)) {
  1330. cur->bc_nlevels = pcur->bc_nlevels;
  1331. xfs_btree_del_cursor(pcur, XFS_BTREE_NOERROR);
  1332. }
  1333. /*
  1334. * If we got a new cursor, switch to it.
  1335. */
  1336. if (ncur) {
  1337. pcur = ncur;
  1338. ncur = NULL;
  1339. }
  1340. } while (nbno != NULLAGBLOCK);
  1341. *stat = i;
  1342. return 0;
  1343. }
  1344. STATIC struct xfs_btree_cur *
  1345. xfs_allocbt_dup_cursor(
  1346. struct xfs_btree_cur *cur)
  1347. {
  1348. return xfs_allocbt_init_cursor(cur->bc_mp, cur->bc_tp,
  1349. cur->bc_private.a.agbp, cur->bc_private.a.agno,
  1350. cur->bc_btnum);
  1351. }
  1352. /*
  1353. * Update the longest extent in the AGF
  1354. */
  1355. STATIC void
  1356. xfs_allocbt_update_lastrec(
  1357. struct xfs_btree_cur *cur,
  1358. struct xfs_btree_block *block,
  1359. union xfs_btree_rec *rec,
  1360. int ptr,
  1361. int reason)
  1362. {
  1363. struct xfs_agf *agf = XFS_BUF_TO_AGF(cur->bc_private.a.agbp);
  1364. xfs_agnumber_t seqno = be32_to_cpu(agf->agf_seqno);
  1365. __be32 len;
  1366. ASSERT(cur->bc_btnum == XFS_BTNUM_CNT);
  1367. switch (reason) {
  1368. case LASTREC_UPDATE:
  1369. /*
  1370. * If this is the last leaf block and it's the last record,
  1371. * then update the size of the longest extent in the AG.
  1372. */
  1373. if (ptr != xfs_btree_get_numrecs(block))
  1374. return;
  1375. len = rec->alloc.ar_blockcount;
  1376. break;
  1377. default:
  1378. ASSERT(0);
  1379. return;
  1380. }
  1381. agf->agf_longest = len;
  1382. cur->bc_mp->m_perag[seqno].pagf_longest = be32_to_cpu(len);
  1383. xfs_alloc_log_agf(cur->bc_tp, cur->bc_private.a.agbp, XFS_AGF_LONGEST);
  1384. }
  1385. STATIC int
  1386. xfs_allocbt_get_maxrecs(
  1387. struct xfs_btree_cur *cur,
  1388. int level)
  1389. {
  1390. return cur->bc_mp->m_alloc_mxr[level != 0];
  1391. }
  1392. STATIC void
  1393. xfs_allocbt_init_key_from_rec(
  1394. union xfs_btree_key *key,
  1395. union xfs_btree_rec *rec)
  1396. {
  1397. ASSERT(rec->alloc.ar_startblock != 0);
  1398. key->alloc.ar_startblock = rec->alloc.ar_startblock;
  1399. key->alloc.ar_blockcount = rec->alloc.ar_blockcount;
  1400. }
  1401. STATIC void
  1402. xfs_allocbt_init_ptr_from_cur(
  1403. struct xfs_btree_cur *cur,
  1404. union xfs_btree_ptr *ptr)
  1405. {
  1406. struct xfs_agf *agf = XFS_BUF_TO_AGF(cur->bc_private.a.agbp);
  1407. ASSERT(cur->bc_private.a.agno == be32_to_cpu(agf->agf_seqno));
  1408. ASSERT(agf->agf_roots[cur->bc_btnum] != 0);
  1409. ptr->s = agf->agf_roots[cur->bc_btnum];
  1410. }
  1411. STATIC __int64_t
  1412. xfs_allocbt_key_diff(
  1413. struct xfs_btree_cur *cur,
  1414. union xfs_btree_key *key)
  1415. {
  1416. xfs_alloc_rec_incore_t *rec = &cur->bc_rec.a;
  1417. xfs_alloc_key_t *kp = &key->alloc;
  1418. __int64_t diff;
  1419. if (cur->bc_btnum == XFS_BTNUM_BNO) {
  1420. return (__int64_t)be32_to_cpu(kp->ar_startblock) -
  1421. rec->ar_startblock;
  1422. }
  1423. diff = (__int64_t)be32_to_cpu(kp->ar_blockcount) - rec->ar_blockcount;
  1424. if (diff)
  1425. return diff;
  1426. return (__int64_t)be32_to_cpu(kp->ar_startblock) - rec->ar_startblock;
  1427. }
  1428. #ifdef XFS_BTREE_TRACE
  1429. ktrace_t *xfs_allocbt_trace_buf;
  1430. STATIC void
  1431. xfs_allocbt_trace_enter(
  1432. struct xfs_btree_cur *cur,
  1433. const char *func,
  1434. char *s,
  1435. int type,
  1436. int line,
  1437. __psunsigned_t a0,
  1438. __psunsigned_t a1,
  1439. __psunsigned_t a2,
  1440. __psunsigned_t a3,
  1441. __psunsigned_t a4,
  1442. __psunsigned_t a5,
  1443. __psunsigned_t a6,
  1444. __psunsigned_t a7,
  1445. __psunsigned_t a8,
  1446. __psunsigned_t a9,
  1447. __psunsigned_t a10)
  1448. {
  1449. ktrace_enter(xfs_allocbt_trace_buf, (void *)(__psint_t)type,
  1450. (void *)func, (void *)s, NULL, (void *)cur,
  1451. (void *)a0, (void *)a1, (void *)a2, (void *)a3,
  1452. (void *)a4, (void *)a5, (void *)a6, (void *)a7,
  1453. (void *)a8, (void *)a9, (void *)a10);
  1454. }
  1455. STATIC void
  1456. xfs_allocbt_trace_cursor(
  1457. struct xfs_btree_cur *cur,
  1458. __uint32_t *s0,
  1459. __uint64_t *l0,
  1460. __uint64_t *l1)
  1461. {
  1462. *s0 = cur->bc_private.a.agno;
  1463. *l0 = cur->bc_rec.a.ar_startblock;
  1464. *l1 = cur->bc_rec.a.ar_blockcount;
  1465. }
  1466. STATIC void
  1467. xfs_allocbt_trace_key(
  1468. struct xfs_btree_cur *cur,
  1469. union xfs_btree_key *key,
  1470. __uint64_t *l0,
  1471. __uint64_t *l1)
  1472. {
  1473. *l0 = be32_to_cpu(key->alloc.ar_startblock);
  1474. *l1 = be32_to_cpu(key->alloc.ar_blockcount);
  1475. }
  1476. STATIC void
  1477. xfs_allocbt_trace_record(
  1478. struct xfs_btree_cur *cur,
  1479. union xfs_btree_rec *rec,
  1480. __uint64_t *l0,
  1481. __uint64_t *l1,
  1482. __uint64_t *l2)
  1483. {
  1484. *l0 = be32_to_cpu(rec->alloc.ar_startblock);
  1485. *l1 = be32_to_cpu(rec->alloc.ar_blockcount);
  1486. *l2 = 0;
  1487. }
  1488. #endif /* XFS_BTREE_TRACE */
  1489. static const struct xfs_btree_ops xfs_allocbt_ops = {
  1490. .rec_len = sizeof(xfs_alloc_rec_t),
  1491. .key_len = sizeof(xfs_alloc_key_t),
  1492. .dup_cursor = xfs_allocbt_dup_cursor,
  1493. .update_lastrec = xfs_allocbt_update_lastrec,
  1494. .get_maxrecs = xfs_allocbt_get_maxrecs,
  1495. .init_key_from_rec = xfs_allocbt_init_key_from_rec,
  1496. .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur,
  1497. .key_diff = xfs_allocbt_key_diff,
  1498. #ifdef XFS_BTREE_TRACE
  1499. .trace_enter = xfs_allocbt_trace_enter,
  1500. .trace_cursor = xfs_allocbt_trace_cursor,
  1501. .trace_key = xfs_allocbt_trace_key,
  1502. .trace_record = xfs_allocbt_trace_record,
  1503. #endif
  1504. };
  1505. /*
  1506. * Allocate a new allocation btree cursor.
  1507. */
  1508. struct xfs_btree_cur * /* new alloc btree cursor */
  1509. xfs_allocbt_init_cursor(
  1510. struct xfs_mount *mp, /* file system mount point */
  1511. struct xfs_trans *tp, /* transaction pointer */
  1512. struct xfs_buf *agbp, /* buffer for agf structure */
  1513. xfs_agnumber_t agno, /* allocation group number */
  1514. xfs_btnum_t btnum) /* btree identifier */
  1515. {
  1516. struct xfs_agf *agf = XFS_BUF_TO_AGF(agbp);
  1517. struct xfs_btree_cur *cur;
  1518. ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT);
  1519. cur = kmem_zone_zalloc(xfs_btree_cur_zone, KM_SLEEP);
  1520. cur->bc_tp = tp;
  1521. cur->bc_mp = mp;
  1522. cur->bc_nlevels = be32_to_cpu(agf->agf_levels[btnum]);
  1523. cur->bc_btnum = btnum;
  1524. cur->bc_blocklog = mp->m_sb.sb_blocklog;
  1525. cur->bc_ops = &xfs_allocbt_ops;
  1526. if (btnum == XFS_BTNUM_CNT)
  1527. cur->bc_flags = XFS_BTREE_LASTREC_UPDATE;
  1528. cur->bc_private.a.agbp = agbp;
  1529. cur->bc_private.a.agno = agno;
  1530. return cur;
  1531. }