aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2018-07-12 01:26:29 -0400
committerDarrick J. Wong <darrick.wong@oracle.com>2018-07-12 01:26:29 -0400
commitcf612de732cb6ef626019ca085406d183f0a055a (patch)
treef95e717e594fba97786d2233f24753c349b4792d
parent280253d213fb735b565532be2836f94cf574260d (diff)
xfs: remove xfs_btree_cur private firstblock field
The bmbt cursor private structure has a firstblock field that is used to maintain locking order on bmbt allocations. The field holds an actual firstblock value (as opposed to a pointer), so it is initialized on cursor creation, updated on allocation and then the value is transferred back to the source before the cursor is destroyed. This value is always transferred from and back to the ->t_firstblock field. Since xfs_btree_cur already carries a reference to the transaction, we can remove this field from xfs_btree_cur and the associated copying. The bmbt allocations will update the value in the transaction directly. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c28
-rw-r--r--fs/xfs/libxfs/xfs_bmap_btree.c10
-rw-r--r--fs/xfs/libxfs/xfs_btree.h1
3 files changed, 7 insertions, 32 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 183450f1df19..8a1e6890a64b 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -688,7 +688,6 @@ xfs_bmap_extents_to_btree(
688 * Need a cursor. Can't allocate until bb_level is filled in. 688 * Need a cursor. Can't allocate until bb_level is filled in.
689 */ 689 */
690 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); 690 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
691 cur->bc_private.b.firstblock = tp->t_firstblock;
692 cur->bc_private.b.flags = wasdel ? XFS_BTCUR_BPRV_WASDEL : 0; 691 cur->bc_private.b.flags = wasdel ? XFS_BTCUR_BPRV_WASDEL : 0;
693 /* 692 /*
694 * Convert to a btree with two levels, one record in root. 693 * Convert to a btree with two levels, one record in root.
@@ -732,7 +731,7 @@ xfs_bmap_extents_to_btree(
732 */ 731 */
733 ASSERT(tp->t_firstblock == NULLFSBLOCK || 732 ASSERT(tp->t_firstblock == NULLFSBLOCK ||
734 args.agno >= XFS_FSB_TO_AGNO(mp, tp->t_firstblock)); 733 args.agno >= XFS_FSB_TO_AGNO(mp, tp->t_firstblock));
735 tp->t_firstblock = cur->bc_private.b.firstblock = args.fsbno; 734 tp->t_firstblock = args.fsbno;
736 cur->bc_private.b.allocated++; 735 cur->bc_private.b.allocated++;
737 ip->i_d.di_nblocks++; 736 ip->i_d.di_nblocks++;
738 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L); 737 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L);
@@ -925,7 +924,6 @@ xfs_bmap_add_attrfork_btree(
925 *flags |= XFS_ILOG_DBROOT; 924 *flags |= XFS_ILOG_DBROOT;
926 else { 925 else {
927 cur = xfs_bmbt_init_cursor(mp, tp, ip, XFS_DATA_FORK); 926 cur = xfs_bmbt_init_cursor(mp, tp, ip, XFS_DATA_FORK);
928 cur->bc_private.b.firstblock = tp->t_firstblock;
929 error = xfs_bmbt_lookup_first(cur, &stat); 927 error = xfs_bmbt_lookup_first(cur, &stat);
930 if (error) 928 if (error)
931 goto error0; 929 goto error0;
@@ -937,7 +935,6 @@ xfs_bmap_add_attrfork_btree(
937 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); 935 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
938 return -ENOSPC; 936 return -ENOSPC;
939 } 937 }
940 tp->t_firstblock = cur->bc_private.b.firstblock;
941 cur->bc_private.b.allocated = 0; 938 cur->bc_private.b.allocated = 0;
942 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); 939 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
943 } 940 }
@@ -4058,14 +4055,10 @@ xfs_bmapi_allocate(
4058 if (error) 4055 if (error)
4059 return error; 4056 return error;
4060 4057
4061 if (bma->cur)
4062 bma->cur->bc_private.b.firstblock = bma->tp->t_firstblock;
4063 if (bma->blkno == NULLFSBLOCK) 4058 if (bma->blkno == NULLFSBLOCK)
4064 return 0; 4059 return 0;
4065 if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur) { 4060 if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur)
4066 bma->cur = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork); 4061 bma->cur = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork);
4067 bma->cur->bc_private.b.firstblock = bma->tp->t_firstblock;
4068 }
4069 /* 4062 /*
4070 * Bump the number of extents we've allocated 4063 * Bump the number of extents we've allocated
4071 * in this call. 4064 * in this call.
@@ -4151,7 +4144,6 @@ xfs_bmapi_convert_unwritten(
4151 if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur) { 4144 if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur) {
4152 bma->cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp, 4145 bma->cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp,
4153 bma->ip, whichfork); 4146 bma->ip, whichfork);
4154 bma->cur->bc_private.b.firstblock = bma->tp->t_firstblock;
4155 } 4147 }
4156 mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN) 4148 mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN)
4157 ? XFS_EXT_NORM : XFS_EXT_UNWRITTEN; 4149 ? XFS_EXT_NORM : XFS_EXT_UNWRITTEN;
@@ -4458,13 +4450,6 @@ error0:
4458 xfs_trans_log_inode(tp, ip, bma.logflags); 4450 xfs_trans_log_inode(tp, ip, bma.logflags);
4459 4451
4460 if (bma.cur) { 4452 if (bma.cur) {
4461 if (!error) {
4462 ASSERT(tp->t_firstblock == NULLFSBLOCK ||
4463 XFS_FSB_TO_AGNO(mp, tp->t_firstblock) <=
4464 XFS_FSB_TO_AGNO(mp,
4465 bma.cur->bc_private.b.firstblock));
4466 tp->t_firstblock = bma.cur->bc_private.b.firstblock;
4467 }
4468 xfs_btree_del_cursor(bma.cur, 4453 xfs_btree_del_cursor(bma.cur,
4469 error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR); 4454 error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
4470 } 4455 }
@@ -4528,7 +4513,6 @@ xfs_bmapi_remap(
4528 4513
4529 if (ifp->if_flags & XFS_IFBROOT) { 4514 if (ifp->if_flags & XFS_IFBROOT) {
4530 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); 4515 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
4531 cur->bc_private.b.firstblock = tp->t_firstblock;
4532 cur->bc_private.b.flags = 0; 4516 cur->bc_private.b.flags = 0;
4533 } 4517 }
4534 4518
@@ -5189,7 +5173,6 @@ __xfs_bunmapi(
5189 if (ifp->if_flags & XFS_IFBROOT) { 5173 if (ifp->if_flags & XFS_IFBROOT) {
5190 ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE); 5174 ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE);
5191 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); 5175 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
5192 cur->bc_private.b.firstblock = tp->t_firstblock;
5193 cur->bc_private.b.flags = 0; 5176 cur->bc_private.b.flags = 0;
5194 } else 5177 } else
5195 cur = NULL; 5178 cur = NULL;
@@ -5457,10 +5440,8 @@ error0:
5457 if (logflags) 5440 if (logflags)
5458 xfs_trans_log_inode(tp, ip, logflags); 5441 xfs_trans_log_inode(tp, ip, logflags);
5459 if (cur) { 5442 if (cur) {
5460 if (!error) { 5443 if (!error)
5461 tp->t_firstblock = cur->bc_private.b.firstblock;
5462 cur->bc_private.b.allocated = 0; 5444 cur->bc_private.b.allocated = 0;
5463 }
5464 xfs_btree_del_cursor(cur, 5445 xfs_btree_del_cursor(cur,
5465 error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR); 5446 error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
5466 } 5447 }
@@ -5676,7 +5657,6 @@ xfs_bmap_collapse_extents(
5676 5657
5677 if (ifp->if_flags & XFS_IFBROOT) { 5658 if (ifp->if_flags & XFS_IFBROOT) {
5678 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); 5659 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
5679 cur->bc_private.b.firstblock = tp->t_firstblock;
5680 cur->bc_private.b.flags = 0; 5660 cur->bc_private.b.flags = 0;
5681 } 5661 }
5682 5662
@@ -5796,7 +5776,6 @@ xfs_bmap_insert_extents(
5796 5776
5797 if (ifp->if_flags & XFS_IFBROOT) { 5777 if (ifp->if_flags & XFS_IFBROOT) {
5798 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); 5778 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
5799 cur->bc_private.b.firstblock = tp->t_firstblock;
5800 cur->bc_private.b.flags = 0; 5779 cur->bc_private.b.flags = 0;
5801 } 5780 }
5802 5781
@@ -5918,7 +5897,6 @@ xfs_bmap_split_extent_at(
5918 5897
5919 if (ifp->if_flags & XFS_IFBROOT) { 5898 if (ifp->if_flags & XFS_IFBROOT) {
5920 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); 5899 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
5921 cur->bc_private.b.firstblock = tp->t_firstblock;
5922 cur->bc_private.b.flags = 0; 5900 cur->bc_private.b.flags = 0;
5923 error = xfs_bmbt_lookup_eq(cur, &got, &i); 5901 error = xfs_bmbt_lookup_eq(cur, &got, &i);
5924 if (error) 5902 if (error)
diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c
index e8b01af09db5..8a9b98b11e34 100644
--- a/fs/xfs/libxfs/xfs_bmap_btree.c
+++ b/fs/xfs/libxfs/xfs_bmap_btree.c
@@ -175,7 +175,6 @@ xfs_bmbt_dup_cursor(
175 * Copy the firstblock, dfops, and flags values, 175 * Copy the firstblock, dfops, and flags values,
176 * since init cursor doesn't get them. 176 * since init cursor doesn't get them.
177 */ 177 */
178 new->bc_private.b.firstblock = cur->bc_private.b.firstblock;
179 new->bc_private.b.flags = cur->bc_private.b.flags; 178 new->bc_private.b.flags = cur->bc_private.b.flags;
180 179
181 return new; 180 return new;
@@ -186,11 +185,11 @@ xfs_bmbt_update_cursor(
186 struct xfs_btree_cur *src, 185 struct xfs_btree_cur *src,
187 struct xfs_btree_cur *dst) 186 struct xfs_btree_cur *dst)
188{ 187{
189 ASSERT((dst->bc_private.b.firstblock != NULLFSBLOCK) || 188 ASSERT((dst->bc_tp->t_firstblock != NULLFSBLOCK) ||
190 (dst->bc_private.b.ip->i_d.di_flags & XFS_DIFLAG_REALTIME)); 189 (dst->bc_private.b.ip->i_d.di_flags & XFS_DIFLAG_REALTIME));
191 190
192 dst->bc_private.b.allocated += src->bc_private.b.allocated; 191 dst->bc_private.b.allocated += src->bc_private.b.allocated;
193 dst->bc_private.b.firstblock = src->bc_private.b.firstblock; 192 dst->bc_tp->t_firstblock = src->bc_tp->t_firstblock;
194 193
195 src->bc_private.b.allocated = 0; 194 src->bc_private.b.allocated = 0;
196} 195}
@@ -208,7 +207,7 @@ xfs_bmbt_alloc_block(
208 memset(&args, 0, sizeof(args)); 207 memset(&args, 0, sizeof(args));
209 args.tp = cur->bc_tp; 208 args.tp = cur->bc_tp;
210 args.mp = cur->bc_mp; 209 args.mp = cur->bc_mp;
211 args.fsbno = cur->bc_private.b.firstblock; 210 args.fsbno = cur->bc_tp->t_firstblock;
212 args.firstblock = args.fsbno; 211 args.firstblock = args.fsbno;
213 xfs_rmap_ino_bmbt_owner(&args.oinfo, cur->bc_private.b.ip->i_ino, 212 xfs_rmap_ino_bmbt_owner(&args.oinfo, cur->bc_private.b.ip->i_ino,
214 cur->bc_private.b.whichfork); 213 cur->bc_private.b.whichfork);
@@ -263,7 +262,7 @@ xfs_bmbt_alloc_block(
263 } 262 }
264 263
265 ASSERT(args.len == 1); 264 ASSERT(args.len == 1);
266 cur->bc_private.b.firstblock = args.fsbno; 265 cur->bc_tp->t_firstblock = args.fsbno;
267 cur->bc_private.b.allocated++; 266 cur->bc_private.b.allocated++;
268 cur->bc_private.b.ip->i_d.di_nblocks++; 267 cur->bc_private.b.ip->i_d.di_nblocks++;
269 xfs_trans_log_inode(args.tp, cur->bc_private.b.ip, XFS_ILOG_CORE); 268 xfs_trans_log_inode(args.tp, cur->bc_private.b.ip, XFS_ILOG_CORE);
@@ -562,7 +561,6 @@ xfs_bmbt_init_cursor(
562 561
563 cur->bc_private.b.forksize = XFS_IFORK_SIZE(ip, whichfork); 562 cur->bc_private.b.forksize = XFS_IFORK_SIZE(ip, whichfork);
564 cur->bc_private.b.ip = ip; 563 cur->bc_private.b.ip = ip;
565 cur->bc_private.b.firstblock = NULLFSBLOCK;
566 cur->bc_private.b.allocated = 0; 564 cur->bc_private.b.allocated = 0;
567 cur->bc_private.b.flags = 0; 565 cur->bc_private.b.flags = 0;
568 cur->bc_private.b.whichfork = whichfork; 566 cur->bc_private.b.whichfork = whichfork;
diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h
index b986a8fc8d40..503615f4d729 100644
--- a/fs/xfs/libxfs/xfs_btree.h
+++ b/fs/xfs/libxfs/xfs_btree.h
@@ -214,7 +214,6 @@ typedef struct xfs_btree_cur
214 } a; 214 } a;
215 struct { /* needed for BMAP */ 215 struct { /* needed for BMAP */
216 struct xfs_inode *ip; /* pointer to our inode */ 216 struct xfs_inode *ip; /* pointer to our inode */
217 xfs_fsblock_t firstblock; /* 1st blk allocated */
218 int allocated; /* count of alloced */ 217 int allocated; /* count of alloced */
219 short forksize; /* fork's inode space */ 218 short forksize; /* fork's inode space */
220 char whichfork; /* data or attr fork */ 219 char whichfork; /* data or attr fork */