| .. | .. |
|---|
| 11 | 11 | #include "xfs_trans_resv.h" |
|---|
| 12 | 12 | #include "xfs_bit.h" |
|---|
| 13 | 13 | #include "xfs_mount.h" |
|---|
| 14 | | -#include "xfs_defer.h" |
|---|
| 15 | 14 | #include "xfs_inode.h" |
|---|
| 16 | 15 | #include "xfs_trans.h" |
|---|
| 17 | | -#include "xfs_inode_item.h" |
|---|
| 18 | 16 | #include "xfs_alloc.h" |
|---|
| 19 | 17 | #include "xfs_btree.h" |
|---|
| 20 | 18 | #include "xfs_bmap_btree.h" |
|---|
| .. | .. |
|---|
| 22 | 20 | #include "xfs_error.h" |
|---|
| 23 | 21 | #include "xfs_quota.h" |
|---|
| 24 | 22 | #include "xfs_trace.h" |
|---|
| 25 | | -#include "xfs_cksum.h" |
|---|
| 26 | 23 | #include "xfs_rmap.h" |
|---|
| 27 | 24 | |
|---|
| 28 | 25 | /* |
|---|
| .. | .. |
|---|
| 169 | 166 | struct xfs_btree_cur *new; |
|---|
| 170 | 167 | |
|---|
| 171 | 168 | new = xfs_bmbt_init_cursor(cur->bc_mp, cur->bc_tp, |
|---|
| 172 | | - cur->bc_private.b.ip, cur->bc_private.b.whichfork); |
|---|
| 169 | + cur->bc_ino.ip, cur->bc_ino.whichfork); |
|---|
| 173 | 170 | |
|---|
| 174 | 171 | /* |
|---|
| 175 | 172 | * Copy the firstblock, dfops, and flags values, |
|---|
| 176 | 173 | * since init cursor doesn't get them. |
|---|
| 177 | 174 | */ |
|---|
| 178 | | - new->bc_private.b.flags = cur->bc_private.b.flags; |
|---|
| 175 | + new->bc_ino.flags = cur->bc_ino.flags; |
|---|
| 179 | 176 | |
|---|
| 180 | 177 | return new; |
|---|
| 181 | 178 | } |
|---|
| .. | .. |
|---|
| 186 | 183 | struct xfs_btree_cur *dst) |
|---|
| 187 | 184 | { |
|---|
| 188 | 185 | ASSERT((dst->bc_tp->t_firstblock != NULLFSBLOCK) || |
|---|
| 189 | | - (dst->bc_private.b.ip->i_d.di_flags & XFS_DIFLAG_REALTIME)); |
|---|
| 186 | + (dst->bc_ino.ip->i_d.di_flags & XFS_DIFLAG_REALTIME)); |
|---|
| 190 | 187 | |
|---|
| 191 | | - dst->bc_private.b.allocated += src->bc_private.b.allocated; |
|---|
| 188 | + dst->bc_ino.allocated += src->bc_ino.allocated; |
|---|
| 192 | 189 | dst->bc_tp->t_firstblock = src->bc_tp->t_firstblock; |
|---|
| 193 | 190 | |
|---|
| 194 | | - src->bc_private.b.allocated = 0; |
|---|
| 191 | + src->bc_ino.allocated = 0; |
|---|
| 195 | 192 | } |
|---|
| 196 | 193 | |
|---|
| 197 | 194 | STATIC int |
|---|
| .. | .. |
|---|
| 208 | 205 | args.tp = cur->bc_tp; |
|---|
| 209 | 206 | args.mp = cur->bc_mp; |
|---|
| 210 | 207 | args.fsbno = cur->bc_tp->t_firstblock; |
|---|
| 211 | | - xfs_rmap_ino_bmbt_owner(&args.oinfo, cur->bc_private.b.ip->i_ino, |
|---|
| 212 | | - cur->bc_private.b.whichfork); |
|---|
| 208 | + xfs_rmap_ino_bmbt_owner(&args.oinfo, cur->bc_ino.ip->i_ino, |
|---|
| 209 | + cur->bc_ino.whichfork); |
|---|
| 213 | 210 | |
|---|
| 214 | 211 | if (args.fsbno == NULLFSBLOCK) { |
|---|
| 215 | 212 | args.fsbno = be64_to_cpu(start->l); |
|---|
| .. | .. |
|---|
| 233 | 230 | } |
|---|
| 234 | 231 | |
|---|
| 235 | 232 | args.minlen = args.maxlen = args.prod = 1; |
|---|
| 236 | | - args.wasdel = cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL; |
|---|
| 233 | + args.wasdel = cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL; |
|---|
| 237 | 234 | if (!args.wasdel && args.tp->t_blk_res == 0) { |
|---|
| 238 | 235 | error = -ENOSPC; |
|---|
| 239 | 236 | goto error0; |
|---|
| .. | .. |
|---|
| 262 | 259 | |
|---|
| 263 | 260 | ASSERT(args.len == 1); |
|---|
| 264 | 261 | cur->bc_tp->t_firstblock = args.fsbno; |
|---|
| 265 | | - cur->bc_private.b.allocated++; |
|---|
| 266 | | - cur->bc_private.b.ip->i_d.di_nblocks++; |
|---|
| 267 | | - xfs_trans_log_inode(args.tp, cur->bc_private.b.ip, XFS_ILOG_CORE); |
|---|
| 268 | | - xfs_trans_mod_dquot_byino(args.tp, cur->bc_private.b.ip, |
|---|
| 262 | + cur->bc_ino.allocated++; |
|---|
| 263 | + cur->bc_ino.ip->i_d.di_nblocks++; |
|---|
| 264 | + xfs_trans_log_inode(args.tp, cur->bc_ino.ip, XFS_ILOG_CORE); |
|---|
| 265 | + xfs_trans_mod_dquot_byino(args.tp, cur->bc_ino.ip, |
|---|
| 269 | 266 | XFS_TRANS_DQ_BCOUNT, 1L); |
|---|
| 270 | 267 | |
|---|
| 271 | 268 | new->l = cpu_to_be64(args.fsbno); |
|---|
| .. | .. |
|---|
| 283 | 280 | struct xfs_buf *bp) |
|---|
| 284 | 281 | { |
|---|
| 285 | 282 | struct xfs_mount *mp = cur->bc_mp; |
|---|
| 286 | | - struct xfs_inode *ip = cur->bc_private.b.ip; |
|---|
| 283 | + struct xfs_inode *ip = cur->bc_ino.ip; |
|---|
| 287 | 284 | struct xfs_trans *tp = cur->bc_tp; |
|---|
| 288 | 285 | xfs_fsblock_t fsbno = XFS_DADDR_TO_FSB(mp, XFS_BUF_ADDR(bp)); |
|---|
| 289 | 286 | struct xfs_owner_info oinfo; |
|---|
| 290 | 287 | |
|---|
| 291 | | - xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, cur->bc_private.b.whichfork); |
|---|
| 288 | + xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, cur->bc_ino.whichfork); |
|---|
| 292 | 289 | xfs_bmap_add_free(cur->bc_tp, fsbno, 1, &oinfo); |
|---|
| 293 | 290 | ip->i_d.di_nblocks--; |
|---|
| 294 | 291 | |
|---|
| .. | .. |
|---|
| 305 | 302 | if (level == cur->bc_nlevels - 1) { |
|---|
| 306 | 303 | struct xfs_ifork *ifp; |
|---|
| 307 | 304 | |
|---|
| 308 | | - ifp = XFS_IFORK_PTR(cur->bc_private.b.ip, |
|---|
| 309 | | - cur->bc_private.b.whichfork); |
|---|
| 305 | + ifp = XFS_IFORK_PTR(cur->bc_ino.ip, |
|---|
| 306 | + cur->bc_ino.whichfork); |
|---|
| 310 | 307 | |
|---|
| 311 | 308 | return xfs_bmbt_maxrecs(cur->bc_mp, |
|---|
| 312 | 309 | ifp->if_broot_bytes, level == 0) / 2; |
|---|
| .. | .. |
|---|
| 323 | 320 | if (level == cur->bc_nlevels - 1) { |
|---|
| 324 | 321 | struct xfs_ifork *ifp; |
|---|
| 325 | 322 | |
|---|
| 326 | | - ifp = XFS_IFORK_PTR(cur->bc_private.b.ip, |
|---|
| 327 | | - cur->bc_private.b.whichfork); |
|---|
| 323 | + ifp = XFS_IFORK_PTR(cur->bc_ino.ip, |
|---|
| 324 | + cur->bc_ino.whichfork); |
|---|
| 328 | 325 | |
|---|
| 329 | 326 | return xfs_bmbt_maxrecs(cur->bc_mp, |
|---|
| 330 | 327 | ifp->if_broot_bytes, level == 0); |
|---|
| .. | .. |
|---|
| 350 | 347 | { |
|---|
| 351 | 348 | if (level != cur->bc_nlevels - 1) |
|---|
| 352 | 349 | return cur->bc_mp->m_bmap_dmxr[level != 0]; |
|---|
| 353 | | - return xfs_bmdr_maxrecs(cur->bc_private.b.forksize, level == 0); |
|---|
| 350 | + return xfs_bmdr_maxrecs(cur->bc_ino.forksize, level == 0); |
|---|
| 354 | 351 | } |
|---|
| 355 | 352 | |
|---|
| 356 | 353 | STATIC void |
|---|
| .. | .. |
|---|
| 403 | 400 | union xfs_btree_key *k1, |
|---|
| 404 | 401 | union xfs_btree_key *k2) |
|---|
| 405 | 402 | { |
|---|
| 406 | | - return (int64_t)be64_to_cpu(k1->bmbt.br_startoff) - |
|---|
| 407 | | - be64_to_cpu(k2->bmbt.br_startoff); |
|---|
| 403 | + uint64_t a = be64_to_cpu(k1->bmbt.br_startoff); |
|---|
| 404 | + uint64_t b = be64_to_cpu(k2->bmbt.br_startoff); |
|---|
| 405 | + |
|---|
| 406 | + /* |
|---|
| 407 | + * Note: This routine previously casted a and b to int64 and subtracted |
|---|
| 408 | + * them to generate a result. This lead to problems if b was the |
|---|
| 409 | + * "maximum" key value (all ones) being signed incorrectly, hence this |
|---|
| 410 | + * somewhat less efficient version. |
|---|
| 411 | + */ |
|---|
| 412 | + if (a > b) |
|---|
| 413 | + return 1; |
|---|
| 414 | + if (b > a) |
|---|
| 415 | + return -1; |
|---|
| 416 | + return 0; |
|---|
| 408 | 417 | } |
|---|
| 409 | 418 | |
|---|
| 410 | 419 | static xfs_failaddr_t |
|---|
| 411 | 420 | xfs_bmbt_verify( |
|---|
| 412 | 421 | struct xfs_buf *bp) |
|---|
| 413 | 422 | { |
|---|
| 414 | | - struct xfs_mount *mp = bp->b_target->bt_mount; |
|---|
| 423 | + struct xfs_mount *mp = bp->b_mount; |
|---|
| 415 | 424 | struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp); |
|---|
| 416 | 425 | xfs_failaddr_t fa; |
|---|
| 417 | 426 | unsigned int level; |
|---|
| 418 | 427 | |
|---|
| 419 | | - switch (block->bb_magic) { |
|---|
| 420 | | - case cpu_to_be32(XFS_BMAP_CRC_MAGIC): |
|---|
| 428 | + if (!xfs_verify_magic(bp, block->bb_magic)) |
|---|
| 429 | + return __this_address; |
|---|
| 430 | + |
|---|
| 431 | + if (xfs_sb_version_hascrc(&mp->m_sb)) { |
|---|
| 421 | 432 | /* |
|---|
| 422 | 433 | * XXX: need a better way of verifying the owner here. Right now |
|---|
| 423 | 434 | * just make sure there has been one set. |
|---|
| .. | .. |
|---|
| 425 | 436 | fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN); |
|---|
| 426 | 437 | if (fa) |
|---|
| 427 | 438 | return fa; |
|---|
| 428 | | - /* fall through */ |
|---|
| 429 | | - case cpu_to_be32(XFS_BMAP_MAGIC): |
|---|
| 430 | | - break; |
|---|
| 431 | | - default: |
|---|
| 432 | | - return __this_address; |
|---|
| 433 | 439 | } |
|---|
| 434 | 440 | |
|---|
| 435 | 441 | /* |
|---|
| .. | .. |
|---|
| 481 | 487 | |
|---|
| 482 | 488 | const struct xfs_buf_ops xfs_bmbt_buf_ops = { |
|---|
| 483 | 489 | .name = "xfs_bmbt", |
|---|
| 490 | + .magic = { cpu_to_be32(XFS_BMAP_MAGIC), |
|---|
| 491 | + cpu_to_be32(XFS_BMAP_CRC_MAGIC) }, |
|---|
| 484 | 492 | .verify_read = xfs_bmbt_read_verify, |
|---|
| 485 | 493 | .verify_write = xfs_bmbt_write_verify, |
|---|
| 486 | 494 | .verify_struct = xfs_bmbt_verify, |
|---|
| .. | .. |
|---|
| 544 | 552 | struct xfs_btree_cur *cur; |
|---|
| 545 | 553 | ASSERT(whichfork != XFS_COW_FORK); |
|---|
| 546 | 554 | |
|---|
| 547 | | - cur = kmem_zone_zalloc(xfs_btree_cur_zone, KM_NOFS); |
|---|
| 555 | + cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL); |
|---|
| 548 | 556 | |
|---|
| 549 | 557 | cur->bc_tp = tp; |
|---|
| 550 | 558 | cur->bc_mp = mp; |
|---|
| .. | .. |
|---|
| 558 | 566 | if (xfs_sb_version_hascrc(&mp->m_sb)) |
|---|
| 559 | 567 | cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; |
|---|
| 560 | 568 | |
|---|
| 561 | | - cur->bc_private.b.forksize = XFS_IFORK_SIZE(ip, whichfork); |
|---|
| 562 | | - cur->bc_private.b.ip = ip; |
|---|
| 563 | | - cur->bc_private.b.allocated = 0; |
|---|
| 564 | | - cur->bc_private.b.flags = 0; |
|---|
| 565 | | - cur->bc_private.b.whichfork = whichfork; |
|---|
| 569 | + cur->bc_ino.forksize = XFS_IFORK_SIZE(ip, whichfork); |
|---|
| 570 | + cur->bc_ino.ip = ip; |
|---|
| 571 | + cur->bc_ino.allocated = 0; |
|---|
| 572 | + cur->bc_ino.flags = 0; |
|---|
| 573 | + cur->bc_ino.whichfork = whichfork; |
|---|
| 566 | 574 | |
|---|
| 567 | 575 | return cur; |
|---|
| 568 | 576 | } |
|---|
| .. | .. |
|---|
| 628 | 636 | |
|---|
| 629 | 637 | ASSERT(tp || buffer_list); |
|---|
| 630 | 638 | ASSERT(!(tp && buffer_list)); |
|---|
| 631 | | - if (whichfork == XFS_DATA_FORK) |
|---|
| 632 | | - ASSERT(ip->i_d.di_format == XFS_DINODE_FMT_BTREE); |
|---|
| 633 | | - else |
|---|
| 634 | | - ASSERT(ip->i_d.di_aformat == XFS_DINODE_FMT_BTREE); |
|---|
| 639 | + ASSERT(XFS_IFORK_PTR(ip, whichfork)->if_format == XFS_DINODE_FMT_BTREE); |
|---|
| 635 | 640 | |
|---|
| 636 | 641 | cur = xfs_bmbt_init_cursor(ip->i_mount, tp, ip, whichfork); |
|---|
| 637 | 642 | if (!cur) |
|---|
| 638 | 643 | return -ENOMEM; |
|---|
| 639 | | - cur->bc_private.b.flags |= XFS_BTCUR_BPRV_INVALID_OWNER; |
|---|
| 644 | + cur->bc_ino.flags |= XFS_BTCUR_BMBT_INVALID_OWNER; |
|---|
| 640 | 645 | |
|---|
| 641 | 646 | error = xfs_btree_change_owner(cur, new_owner, buffer_list); |
|---|
| 642 | 647 | xfs_btree_del_cursor(cur, error); |
|---|