aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_bmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_bmap.c')
-rw-r--r--fs/xfs/xfs_bmap.c101
1 files changed, 27 insertions, 74 deletions
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index 498ad50d1f45..87795188cedf 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -185,16 +185,6 @@ xfs_bmap_btree_to_extents(
185 int *logflagsp, /* inode logging flags */ 185 int *logflagsp, /* inode logging flags */
186 int whichfork); /* data or attr fork */ 186 int whichfork); /* data or attr fork */
187 187
188#ifdef DEBUG
189/*
190 * Check that the extents list for the inode ip is in the right order.
191 */
192STATIC void
193xfs_bmap_check_extents(
194 xfs_inode_t *ip, /* incore inode pointer */
195 int whichfork); /* data or attr fork */
196#endif
197
198/* 188/*
199 * Called by xfs_bmapi to update file extent records and the btree 189 * Called by xfs_bmapi to update file extent records and the btree
200 * after removing space (or undoing a delayed allocation). 190 * after removing space (or undoing a delayed allocation).
@@ -410,7 +400,6 @@ xfs_bmap_count_leaves(
410STATIC int 400STATIC int
411xfs_bmap_disk_count_leaves( 401xfs_bmap_disk_count_leaves(
412 xfs_ifork_t *ifp, 402 xfs_ifork_t *ifp,
413 xfs_mount_t *mp,
414 xfs_extnum_t idx, 403 xfs_extnum_t idx,
415 xfs_bmbt_block_t *block, 404 xfs_bmbt_block_t *block,
416 int numrecs, 405 int numrecs,
@@ -684,7 +673,7 @@ xfs_bmap_add_extent(
684 ASSERT(nblks <= da_old); 673 ASSERT(nblks <= da_old);
685 if (nblks < da_old) 674 if (nblks < da_old)
686 xfs_mod_incore_sb(ip->i_mount, XFS_SBS_FDBLOCKS, 675 xfs_mod_incore_sb(ip->i_mount, XFS_SBS_FDBLOCKS,
687 (int)(da_old - nblks), rsvd); 676 (int64_t)(da_old - nblks), rsvd);
688 } 677 }
689 /* 678 /*
690 * Clear out the allocated field, done with it now in any case. 679 * Clear out the allocated field, done with it now in any case.
@@ -1209,7 +1198,7 @@ xfs_bmap_add_extent_delay_real(
1209 diff = (int)(temp + temp2 - STARTBLOCKVAL(PREV.br_startblock) - 1198 diff = (int)(temp + temp2 - STARTBLOCKVAL(PREV.br_startblock) -
1210 (cur ? cur->bc_private.b.allocated : 0)); 1199 (cur ? cur->bc_private.b.allocated : 0));
1211 if (diff > 0 && 1200 if (diff > 0 &&
1212 xfs_mod_incore_sb(ip->i_mount, XFS_SBS_FDBLOCKS, -diff, rsvd)) { 1201 xfs_mod_incore_sb(ip->i_mount, XFS_SBS_FDBLOCKS, -((int64_t)diff), rsvd)) {
1213 /* 1202 /*
1214 * Ick gross gag me with a spoon. 1203 * Ick gross gag me with a spoon.
1215 */ 1204 */
@@ -1220,7 +1209,7 @@ xfs_bmap_add_extent_delay_real(
1220 diff--; 1209 diff--;
1221 if (!diff || 1210 if (!diff ||
1222 !xfs_mod_incore_sb(ip->i_mount, 1211 !xfs_mod_incore_sb(ip->i_mount,
1223 XFS_SBS_FDBLOCKS, -diff, rsvd)) 1212 XFS_SBS_FDBLOCKS, -((int64_t)diff), rsvd))
1224 break; 1213 break;
1225 } 1214 }
1226 if (temp2) { 1215 if (temp2) {
@@ -1228,7 +1217,7 @@ xfs_bmap_add_extent_delay_real(
1228 diff--; 1217 diff--;
1229 if (!diff || 1218 if (!diff ||
1230 !xfs_mod_incore_sb(ip->i_mount, 1219 !xfs_mod_incore_sb(ip->i_mount,
1231 XFS_SBS_FDBLOCKS, -diff, rsvd)) 1220 XFS_SBS_FDBLOCKS, -((int64_t)diff), rsvd))
1232 break; 1221 break;
1233 } 1222 }
1234 } 1223 }
@@ -2015,7 +2004,7 @@ xfs_bmap_add_extent_hole_delay(
2015 if (oldlen != newlen) { 2004 if (oldlen != newlen) {
2016 ASSERT(oldlen > newlen); 2005 ASSERT(oldlen > newlen);
2017 xfs_mod_incore_sb(ip->i_mount, XFS_SBS_FDBLOCKS, 2006 xfs_mod_incore_sb(ip->i_mount, XFS_SBS_FDBLOCKS,
2018 (int)(oldlen - newlen), rsvd); 2007 (int64_t)(oldlen - newlen), rsvd);
2019 /* 2008 /*
2020 * Nothing to do for disk quota accounting here. 2009 * Nothing to do for disk quota accounting here.
2021 */ 2010 */
@@ -3359,7 +3348,7 @@ xfs_bmap_del_extent(
3359 */ 3348 */
3360 ASSERT(da_old >= da_new); 3349 ASSERT(da_old >= da_new);
3361 if (da_old > da_new) 3350 if (da_old > da_new)
3362 xfs_mod_incore_sb(mp, XFS_SBS_FDBLOCKS, (int)(da_old - da_new), 3351 xfs_mod_incore_sb(mp, XFS_SBS_FDBLOCKS, (int64_t)(da_old - da_new),
3363 rsvd); 3352 rsvd);
3364 if (delta) { 3353 if (delta) {
3365 /* DELTA: report the original extent. */ 3354 /* DELTA: report the original extent. */
@@ -3543,6 +3532,7 @@ xfs_bmap_forkoff_reset(
3543 if (whichfork == XFS_ATTR_FORK && 3532 if (whichfork == XFS_ATTR_FORK &&
3544 (ip->i_d.di_format != XFS_DINODE_FMT_DEV) && 3533 (ip->i_d.di_format != XFS_DINODE_FMT_DEV) &&
3545 (ip->i_d.di_format != XFS_DINODE_FMT_UUID) && 3534 (ip->i_d.di_format != XFS_DINODE_FMT_UUID) &&
3535 (ip->i_d.di_format != XFS_DINODE_FMT_BTREE) &&
3546 ((mp->m_attroffset >> 3) > ip->i_d.di_forkoff)) { 3536 ((mp->m_attroffset >> 3) > ip->i_d.di_forkoff)) {
3547 ip->i_d.di_forkoff = mp->m_attroffset >> 3; 3537 ip->i_d.di_forkoff = mp->m_attroffset >> 3;
3548 ip->i_df.if_ext_max = XFS_IFORK_DSIZE(ip) / 3538 ip->i_df.if_ext_max = XFS_IFORK_DSIZE(ip) /
@@ -4079,7 +4069,7 @@ xfs_bmap_add_attrfork(
4079 } else 4069 } else
4080 XFS_SB_UNLOCK(mp, s); 4070 XFS_SB_UNLOCK(mp, s);
4081 } 4071 }
4082 if ((error = xfs_bmap_finish(&tp, &flist, firstblock, &committed))) 4072 if ((error = xfs_bmap_finish(&tp, &flist, &committed)))
4083 goto error2; 4073 goto error2;
4084 error = xfs_trans_commit(tp, XFS_TRANS_PERM_LOG_RES, NULL); 4074 error = xfs_trans_commit(tp, XFS_TRANS_PERM_LOG_RES, NULL);
4085 ASSERT(ip->i_df.if_ext_max == 4075 ASSERT(ip->i_df.if_ext_max ==
@@ -4212,7 +4202,6 @@ int /* error */
4212xfs_bmap_finish( 4202xfs_bmap_finish(
4213 xfs_trans_t **tp, /* transaction pointer addr */ 4203 xfs_trans_t **tp, /* transaction pointer addr */
4214 xfs_bmap_free_t *flist, /* i/o: list extents to free */ 4204 xfs_bmap_free_t *flist, /* i/o: list extents to free */
4215 xfs_fsblock_t firstblock, /* controlled ag for allocs */
4216 int *committed) /* xact committed or not */ 4205 int *committed) /* xact committed or not */
4217{ 4206{
4218 xfs_efd_log_item_t *efd; /* extent free data */ 4207 xfs_efd_log_item_t *efd; /* extent free data */
@@ -4533,8 +4522,7 @@ xfs_bmap_read_extents(
4533 error0); 4522 error0);
4534 if (level == 0) 4523 if (level == 0)
4535 break; 4524 break;
4536 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, 4525 pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, 1, mp->m_bmap_dmxr[1]);
4537 1, mp->m_bmap_dmxr[1]);
4538 bno = be64_to_cpu(*pp); 4526 bno = be64_to_cpu(*pp);
4539 XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0); 4527 XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0);
4540 xfs_trans_brelse(tp, bp); 4528 xfs_trans_brelse(tp, bp);
@@ -4577,8 +4565,7 @@ xfs_bmap_read_extents(
4577 /* 4565 /*
4578 * Copy records into the extent records. 4566 * Copy records into the extent records.
4579 */ 4567 */
4580 frp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, 4568 frp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, 1);
4581 block, 1, mp->m_bmap_dmxr[0]);
4582 start = i; 4569 start = i;
4583 for (j = 0; j < num_recs; j++, i++, frp++) { 4570 for (j = 0; j < num_recs; j++, i++, frp++) {
4584 trp = xfs_iext_get_ext(ifp, i); 4571 trp = xfs_iext_get_ext(ifp, i);
@@ -4929,28 +4916,28 @@ xfs_bmapi(
4929 if (rt) { 4916 if (rt) {
4930 error = xfs_mod_incore_sb(mp, 4917 error = xfs_mod_incore_sb(mp,
4931 XFS_SBS_FREXTENTS, 4918 XFS_SBS_FREXTENTS,
4932 -(extsz), (flags & 4919 -((int64_t)extsz), (flags &
4933 XFS_BMAPI_RSVBLOCKS)); 4920 XFS_BMAPI_RSVBLOCKS));
4934 } else { 4921 } else {
4935 error = xfs_mod_incore_sb(mp, 4922 error = xfs_mod_incore_sb(mp,
4936 XFS_SBS_FDBLOCKS, 4923 XFS_SBS_FDBLOCKS,
4937 -(alen), (flags & 4924 -((int64_t)alen), (flags &
4938 XFS_BMAPI_RSVBLOCKS)); 4925 XFS_BMAPI_RSVBLOCKS));
4939 } 4926 }
4940 if (!error) { 4927 if (!error) {
4941 error = xfs_mod_incore_sb(mp, 4928 error = xfs_mod_incore_sb(mp,
4942 XFS_SBS_FDBLOCKS, 4929 XFS_SBS_FDBLOCKS,
4943 -(indlen), (flags & 4930 -((int64_t)indlen), (flags &
4944 XFS_BMAPI_RSVBLOCKS)); 4931 XFS_BMAPI_RSVBLOCKS));
4945 if (error && rt) 4932 if (error && rt)
4946 xfs_mod_incore_sb(mp, 4933 xfs_mod_incore_sb(mp,
4947 XFS_SBS_FREXTENTS, 4934 XFS_SBS_FREXTENTS,
4948 extsz, (flags & 4935 (int64_t)extsz, (flags &
4949 XFS_BMAPI_RSVBLOCKS)); 4936 XFS_BMAPI_RSVBLOCKS));
4950 else if (error) 4937 else if (error)
4951 xfs_mod_incore_sb(mp, 4938 xfs_mod_incore_sb(mp,
4952 XFS_SBS_FDBLOCKS, 4939 XFS_SBS_FDBLOCKS,
4953 alen, (flags & 4940 (int64_t)alen, (flags &
4954 XFS_BMAPI_RSVBLOCKS)); 4941 XFS_BMAPI_RSVBLOCKS));
4955 } 4942 }
4956 4943
@@ -5616,13 +5603,13 @@ xfs_bunmapi(
5616 rtexts = XFS_FSB_TO_B(mp, del.br_blockcount); 5603 rtexts = XFS_FSB_TO_B(mp, del.br_blockcount);
5617 do_div(rtexts, mp->m_sb.sb_rextsize); 5604 do_div(rtexts, mp->m_sb.sb_rextsize);
5618 xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS, 5605 xfs_mod_incore_sb(mp, XFS_SBS_FREXTENTS,
5619 (int)rtexts, rsvd); 5606 (int64_t)rtexts, rsvd);
5620 (void)XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, 5607 (void)XFS_TRANS_RESERVE_QUOTA_NBLKS(mp,
5621 NULL, ip, -((long)del.br_blockcount), 0, 5608 NULL, ip, -((long)del.br_blockcount), 0,
5622 XFS_QMOPT_RES_RTBLKS); 5609 XFS_QMOPT_RES_RTBLKS);
5623 } else { 5610 } else {
5624 xfs_mod_incore_sb(mp, XFS_SBS_FDBLOCKS, 5611 xfs_mod_incore_sb(mp, XFS_SBS_FDBLOCKS,
5625 (int)del.br_blockcount, rsvd); 5612 (int64_t)del.br_blockcount, rsvd);
5626 (void)XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, 5613 (void)XFS_TRANS_RESERVE_QUOTA_NBLKS(mp,
5627 NULL, ip, -((long)del.br_blockcount), 0, 5614 NULL, ip, -((long)del.br_blockcount), 0,
5628 XFS_QMOPT_RES_REGBLKS); 5615 XFS_QMOPT_RES_REGBLKS);
@@ -6048,32 +6035,6 @@ xfs_bmap_eof(
6048} 6035}
6049 6036
6050#ifdef DEBUG 6037#ifdef DEBUG
6051/*
6052 * Check that the extents list for the inode ip is in the right order.
6053 */
6054STATIC void
6055xfs_bmap_check_extents(
6056 xfs_inode_t *ip, /* incore inode pointer */
6057 int whichfork) /* data or attr fork */
6058{
6059 xfs_bmbt_rec_t *ep; /* current extent entry */
6060 xfs_extnum_t idx; /* extent record index */
6061 xfs_ifork_t *ifp; /* inode fork pointer */
6062 xfs_extnum_t nextents; /* number of extents in list */
6063 xfs_bmbt_rec_t *nextp; /* next extent entry */
6064
6065 ifp = XFS_IFORK_PTR(ip, whichfork);
6066 ASSERT(ifp->if_flags & XFS_IFEXTENTS);
6067 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
6068 ep = xfs_iext_get_ext(ifp, 0);
6069 for (idx = 0; idx < nextents - 1; idx++) {
6070 nextp = xfs_iext_get_ext(ifp, idx + 1);
6071 xfs_btree_check_rec(XFS_BTNUM_BMAP, (void *)ep,
6072 (void *)(nextp));
6073 ep = nextp;
6074 }
6075}
6076
6077STATIC 6038STATIC
6078xfs_buf_t * 6039xfs_buf_t *
6079xfs_bmap_get_bp( 6040xfs_bmap_get_bp(
@@ -6156,8 +6117,7 @@ xfs_check_block(
6156 if (root) { 6117 if (root) {
6157 keyp = XFS_BMAP_BROOT_KEY_ADDR(block, i, sz); 6118 keyp = XFS_BMAP_BROOT_KEY_ADDR(block, i, sz);
6158 } else { 6119 } else {
6159 keyp = XFS_BTREE_KEY_ADDR(mp->m_sb.sb_blocksize, 6120 keyp = XFS_BTREE_KEY_ADDR(xfs_bmbt, block, i);
6160 xfs_bmbt, block, i, dmxr);
6161 } 6121 }
6162 6122
6163 if (prevp) { 6123 if (prevp) {
@@ -6172,15 +6132,14 @@ xfs_check_block(
6172 if (root) { 6132 if (root) {
6173 pp = XFS_BMAP_BROOT_PTR_ADDR(block, i, sz); 6133 pp = XFS_BMAP_BROOT_PTR_ADDR(block, i, sz);
6174 } else { 6134 } else {
6175 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, 6135 pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, i, dmxr);
6176 xfs_bmbt, block, i, dmxr);
6177 } 6136 }
6178 for (j = i+1; j <= be16_to_cpu(block->bb_numrecs); j++) { 6137 for (j = i+1; j <= be16_to_cpu(block->bb_numrecs); j++) {
6179 if (root) { 6138 if (root) {
6180 thispa = XFS_BMAP_BROOT_PTR_ADDR(block, j, sz); 6139 thispa = XFS_BMAP_BROOT_PTR_ADDR(block, j, sz);
6181 } else { 6140 } else {
6182 thispa = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, 6141 thispa = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, j,
6183 xfs_bmbt, block, j, dmxr); 6142 dmxr);
6184 } 6143 }
6185 if (*thispa == *pp) { 6144 if (*thispa == *pp) {
6186 cmn_err(CE_WARN, "%s: thispa(%d) == pp(%d) %Ld", 6145 cmn_err(CE_WARN, "%s: thispa(%d) == pp(%d) %Ld",
@@ -6267,8 +6226,7 @@ xfs_bmap_check_leaf_extents(
6267 */ 6226 */
6268 6227
6269 xfs_check_block(block, mp, 0, 0); 6228 xfs_check_block(block, mp, 0, 0);
6270 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, block, 6229 pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, 1, mp->m_bmap_dmxr[1]);
6271 1, mp->m_bmap_dmxr[1]);
6272 bno = be64_to_cpu(*pp); 6230 bno = be64_to_cpu(*pp);
6273 XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0); 6231 XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0);
6274 if (bp_release) { 6232 if (bp_release) {
@@ -6305,11 +6263,9 @@ xfs_bmap_check_leaf_extents(
6305 * conform with the first entry in this one. 6263 * conform with the first entry in this one.
6306 */ 6264 */
6307 6265
6308 ep = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, 6266 ep = XFS_BTREE_REC_ADDR(xfs_bmbt, block, 1);
6309 block, 1, mp->m_bmap_dmxr[0]);
6310 for (j = 1; j < num_recs; j++) { 6267 for (j = 1; j < num_recs; j++) {
6311 nextp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_bmbt, 6268 nextp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, j + 1);
6312 block, j + 1, mp->m_bmap_dmxr[0]);
6313 if (lastp) { 6269 if (lastp) {
6314 xfs_btree_check_rec(XFS_BTNUM_BMAP, 6270 xfs_btree_check_rec(XFS_BTNUM_BMAP,
6315 (void *)lastp, (void *)ep); 6271 (void *)lastp, (void *)ep);
@@ -6454,8 +6410,7 @@ xfs_bmap_count_tree(
6454 } 6410 }
6455 6411
6456 /* Dive to the next level */ 6412 /* Dive to the next level */
6457 pp = XFS_BTREE_PTR_ADDR(mp->m_sb.sb_blocksize, 6413 pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, 1, mp->m_bmap_dmxr[1]);
6458 xfs_bmbt, block, 1, mp->m_bmap_dmxr[1]);
6459 bno = be64_to_cpu(*pp); 6414 bno = be64_to_cpu(*pp);
6460 if (unlikely((error = 6415 if (unlikely((error =
6461 xfs_bmap_count_tree(mp, tp, ifp, bno, level, count)) < 0)) { 6416 xfs_bmap_count_tree(mp, tp, ifp, bno, level, count)) < 0)) {
@@ -6470,7 +6425,7 @@ xfs_bmap_count_tree(
6470 for (;;) { 6425 for (;;) {
6471 nextbno = be64_to_cpu(block->bb_rightsib); 6426 nextbno = be64_to_cpu(block->bb_rightsib);
6472 numrecs = be16_to_cpu(block->bb_numrecs); 6427 numrecs = be16_to_cpu(block->bb_numrecs);
6473 if (unlikely(xfs_bmap_disk_count_leaves(ifp, mp, 6428 if (unlikely(xfs_bmap_disk_count_leaves(ifp,
6474 0, block, numrecs, count) < 0)) { 6429 0, block, numrecs, count) < 0)) {
6475 xfs_trans_brelse(tp, bp); 6430 xfs_trans_brelse(tp, bp);
6476 XFS_ERROR_REPORT("xfs_bmap_count_tree(2)", 6431 XFS_ERROR_REPORT("xfs_bmap_count_tree(2)",
@@ -6518,7 +6473,6 @@ xfs_bmap_count_leaves(
6518int 6473int
6519xfs_bmap_disk_count_leaves( 6474xfs_bmap_disk_count_leaves(
6520 xfs_ifork_t *ifp, 6475 xfs_ifork_t *ifp,
6521 xfs_mount_t *mp,
6522 xfs_extnum_t idx, 6476 xfs_extnum_t idx,
6523 xfs_bmbt_block_t *block, 6477 xfs_bmbt_block_t *block,
6524 int numrecs, 6478 int numrecs,
@@ -6528,8 +6482,7 @@ xfs_bmap_disk_count_leaves(
6528 xfs_bmbt_rec_t *frp; 6482 xfs_bmbt_rec_t *frp;
6529 6483
6530 for (b = 1; b <= numrecs; b++) { 6484 for (b = 1; b <= numrecs; b++) {
6531 frp = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, 6485 frp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, idx + b);
6532 xfs_bmbt, block, idx + b, mp->m_bmap_dmxr[0]);
6533 *count += xfs_bmbt_disk_get_blockcount(frp); 6486 *count += xfs_bmbt_disk_get_blockcount(frp);
6534 } 6487 }
6535 return 0; 6488 return 0;