@@ -376,16 +376,14 @@ xfs_reflink_allocate_cow(
376376 resblks = XFS_DIOSTRAT_SPACE_RES (mp , resaligned );
377377
378378 xfs_iunlock (ip , * lockmode );
379- error = xfs_trans_alloc (mp , & M_RES (mp )-> tr_write , resblks , 0 , 0 , & tp );
380- * lockmode = XFS_ILOCK_EXCL ;
381- xfs_ilock (ip , * lockmode );
379+ * lockmode = 0 ;
382380
381+ error = xfs_trans_alloc_inode (ip , & M_RES (mp )-> tr_write , resblks , 0 ,
382+ false, & tp );
383383 if (error )
384384 return error ;
385385
386- error = xfs_qm_dqattach_locked (ip , false);
387- if (error )
388- goto out_trans_cancel ;
386+ * lockmode = XFS_ILOCK_EXCL ;
389387
390388 /*
391389 * Check for an overlapping extent again now that we dropped the ilock.
@@ -398,12 +396,6 @@ xfs_reflink_allocate_cow(
398396 goto convert ;
399397 }
400398
401- error = xfs_trans_reserve_quota_nblks (tp , ip , resblks , 0 , false);
402- if (error )
403- goto out_trans_cancel ;
404-
405- xfs_trans_ijoin (tp , ip , 0 );
406-
407399 /* Allocate the entire reservation as unwritten blocks. */
408400 nimaps = 1 ;
409401 error = xfs_bmapi_write (tp , ip , imap -> br_startoff , imap -> br_blockcount ,
@@ -997,23 +989,30 @@ xfs_reflink_remap_extent(
997989 struct xfs_mount * mp = ip -> i_mount ;
998990 struct xfs_trans * tp ;
999991 xfs_off_t newlen ;
1000- int64_t qres , qdelta ;
992+ int64_t qdelta = 0 ;
1001993 unsigned int resblks ;
1002994 bool smap_real ;
1003995 bool dmap_written = xfs_bmap_is_written_extent (dmap );
1004996 int iext_delta = 0 ;
1005997 int nimaps ;
1006998 int error ;
1007999
1008- /* Start a rolling transaction to switch the mappings */
1000+ /*
1001+ * Start a rolling transaction to switch the mappings.
1002+ *
1003+ * Adding a written extent to the extent map can cause a bmbt split,
1004+ * and removing a mapped extent from the extent can cause a bmbt split.
1005+ * The two operations cannot both cause a split since they operate on
1006+ * the same index in the bmap btree, so we only need a reservation for
1007+ * one bmbt split if either thing is happening. However, we haven't
1008+ * locked the inode yet, so we reserve assuming this is the case.
1009+ */
10091010 resblks = XFS_EXTENTADD_SPACE_RES (mp , XFS_DATA_FORK );
1010- error = xfs_trans_alloc (mp , & M_RES (mp )-> tr_write , resblks , 0 , 0 , & tp );
1011+ error = xfs_trans_alloc_inode (ip , & M_RES (mp )-> tr_write , resblks , 0 ,
1012+ false, & tp );
10111013 if (error )
10121014 goto out ;
10131015
1014- xfs_ilock (ip , XFS_ILOCK_EXCL );
1015- xfs_trans_ijoin (tp , ip , 0 );
1016-
10171016 /*
10181017 * Read what's currently mapped in the destination file into smap.
10191018 * If smap isn't a hole, we will have to remove it before we can add
@@ -1061,15 +1060,9 @@ xfs_reflink_remap_extent(
10611060 }
10621061
10631062 /*
1064- * Compute quota reservation if we think the quota block counter for
1063+ * Increase quota reservation if we think the quota block counter for
10651064 * this file could increase.
10661065 *
1067- * Adding a written extent to the extent map can cause a bmbt split,
1068- * and removing a mapped extent from the extent can cause a bmbt split.
1069- * The two operations cannot both cause a split since they operate on
1070- * the same index in the bmap btree, so we only need a reservation for
1071- * one bmbt split if either thing is happening.
1072- *
10731066 * If we are mapping a written extent into the file, we need to have
10741067 * enough quota block count reservation to handle the blocks in that
10751068 * extent. We log only the delta to the quota block counts, so if the
@@ -1083,13 +1076,9 @@ xfs_reflink_remap_extent(
10831076 * before we started. That should have removed all the delalloc
10841077 * reservations, but we code defensively.
10851078 */
1086- qres = qdelta = 0 ;
1087- if (smap_real || dmap_written )
1088- qres = XFS_EXTENTADD_SPACE_RES (mp , XFS_DATA_FORK );
1089- if (!smap_real && dmap_written )
1090- qres += dmap -> br_blockcount ;
1091- if (qres > 0 ) {
1092- error = xfs_trans_reserve_quota_nblks (tp , ip , qres , 0 , false);
1079+ if (!smap_real && dmap_written ) {
1080+ error = xfs_trans_reserve_quota_nblks (tp , ip ,
1081+ dmap -> br_blockcount , 0 , false);
10931082 if (error )
10941083 goto out_cancel ;
10951084 }
0 commit comments