hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/xfs/libxfs/xfs_bmap_btree.c
....@@ -11,10 +11,8 @@
1111 #include "xfs_trans_resv.h"
1212 #include "xfs_bit.h"
1313 #include "xfs_mount.h"
14
-#include "xfs_defer.h"
1514 #include "xfs_inode.h"
1615 #include "xfs_trans.h"
17
-#include "xfs_inode_item.h"
1816 #include "xfs_alloc.h"
1917 #include "xfs_btree.h"
2018 #include "xfs_bmap_btree.h"
....@@ -22,7 +20,6 @@
2220 #include "xfs_error.h"
2321 #include "xfs_quota.h"
2422 #include "xfs_trace.h"
25
-#include "xfs_cksum.h"
2623 #include "xfs_rmap.h"
2724
2825 /*
....@@ -169,13 +166,13 @@
169166 struct xfs_btree_cur *new;
170167
171168 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);
173170
174171 /*
175172 * Copy the firstblock, dfops, and flags values,
176173 * since init cursor doesn't get them.
177174 */
178
- new->bc_private.b.flags = cur->bc_private.b.flags;
175
+ new->bc_ino.flags = cur->bc_ino.flags;
179176
180177 return new;
181178 }
....@@ -186,12 +183,12 @@
186183 struct xfs_btree_cur *dst)
187184 {
188185 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));
190187
191
- dst->bc_private.b.allocated += src->bc_private.b.allocated;
188
+ dst->bc_ino.allocated += src->bc_ino.allocated;
192189 dst->bc_tp->t_firstblock = src->bc_tp->t_firstblock;
193190
194
- src->bc_private.b.allocated = 0;
191
+ src->bc_ino.allocated = 0;
195192 }
196193
197194 STATIC int
....@@ -208,8 +205,8 @@
208205 args.tp = cur->bc_tp;
209206 args.mp = cur->bc_mp;
210207 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);
213210
214211 if (args.fsbno == NULLFSBLOCK) {
215212 args.fsbno = be64_to_cpu(start->l);
....@@ -233,7 +230,7 @@
233230 }
234231
235232 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;
237234 if (!args.wasdel && args.tp->t_blk_res == 0) {
238235 error = -ENOSPC;
239236 goto error0;
....@@ -262,10 +259,10 @@
262259
263260 ASSERT(args.len == 1);
264261 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,
269266 XFS_TRANS_DQ_BCOUNT, 1L);
270267
271268 new->l = cpu_to_be64(args.fsbno);
....@@ -283,12 +280,12 @@
283280 struct xfs_buf *bp)
284281 {
285282 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;
287284 struct xfs_trans *tp = cur->bc_tp;
288285 xfs_fsblock_t fsbno = XFS_DADDR_TO_FSB(mp, XFS_BUF_ADDR(bp));
289286 struct xfs_owner_info oinfo;
290287
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);
292289 xfs_bmap_add_free(cur->bc_tp, fsbno, 1, &oinfo);
293290 ip->i_d.di_nblocks--;
294291
....@@ -305,8 +302,8 @@
305302 if (level == cur->bc_nlevels - 1) {
306303 struct xfs_ifork *ifp;
307304
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);
310307
311308 return xfs_bmbt_maxrecs(cur->bc_mp,
312309 ifp->if_broot_bytes, level == 0) / 2;
....@@ -323,8 +320,8 @@
323320 if (level == cur->bc_nlevels - 1) {
324321 struct xfs_ifork *ifp;
325322
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);
328325
329326 return xfs_bmbt_maxrecs(cur->bc_mp,
330327 ifp->if_broot_bytes, level == 0);
....@@ -350,7 +347,7 @@
350347 {
351348 if (level != cur->bc_nlevels - 1)
352349 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);
354351 }
355352
356353 STATIC void
....@@ -403,21 +400,35 @@
403400 union xfs_btree_key *k1,
404401 union xfs_btree_key *k2)
405402 {
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;
408417 }
409418
410419 static xfs_failaddr_t
411420 xfs_bmbt_verify(
412421 struct xfs_buf *bp)
413422 {
414
- struct xfs_mount *mp = bp->b_target->bt_mount;
423
+ struct xfs_mount *mp = bp->b_mount;
415424 struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
416425 xfs_failaddr_t fa;
417426 unsigned int level;
418427
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)) {
421432 /*
422433 * XXX: need a better way of verifying the owner here. Right now
423434 * just make sure there has been one set.
....@@ -425,11 +436,6 @@
425436 fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN);
426437 if (fa)
427438 return fa;
428
- /* fall through */
429
- case cpu_to_be32(XFS_BMAP_MAGIC):
430
- break;
431
- default:
432
- return __this_address;
433439 }
434440
435441 /*
....@@ -481,6 +487,8 @@
481487
482488 const struct xfs_buf_ops xfs_bmbt_buf_ops = {
483489 .name = "xfs_bmbt",
490
+ .magic = { cpu_to_be32(XFS_BMAP_MAGIC),
491
+ cpu_to_be32(XFS_BMAP_CRC_MAGIC) },
484492 .verify_read = xfs_bmbt_read_verify,
485493 .verify_write = xfs_bmbt_write_verify,
486494 .verify_struct = xfs_bmbt_verify,
....@@ -544,7 +552,7 @@
544552 struct xfs_btree_cur *cur;
545553 ASSERT(whichfork != XFS_COW_FORK);
546554
547
- cur = kmem_zone_zalloc(xfs_btree_cur_zone, KM_NOFS);
555
+ cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL);
548556
549557 cur->bc_tp = tp;
550558 cur->bc_mp = mp;
....@@ -558,11 +566,11 @@
558566 if (xfs_sb_version_hascrc(&mp->m_sb))
559567 cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
560568
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;
566574
567575 return cur;
568576 }
....@@ -628,15 +636,12 @@
628636
629637 ASSERT(tp || buffer_list);
630638 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);
635640
636641 cur = xfs_bmbt_init_cursor(ip->i_mount, tp, ip, whichfork);
637642 if (!cur)
638643 return -ENOMEM;
639
- cur->bc_private.b.flags |= XFS_BTCUR_BPRV_INVALID_OWNER;
644
+ cur->bc_ino.flags |= XFS_BTCUR_BMBT_INVALID_OWNER;
640645
641646 error = xfs_btree_change_owner(cur, new_owner, buffer_list);
642647 xfs_btree_del_cursor(cur, error);