Skip to content

Commit 3de4eb1

Browse files
author
Darrick J. Wong
committed
xfs: allow reservation of rtblocks with xfs_trans_alloc_inode
Make it so that we can reserve rt blocks with the xfs_trans_alloc_inode wrapper function, then convert a few more callsites. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Brian Foster <[email protected]>
1 parent 3a1af6c commit 3de4eb1

File tree

6 files changed

+18
-46
lines changed

6 files changed

+18
-46
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ xfs_attr_set(
458458
* Root fork attributes can use reserved data blocks for this
459459
* operation if necessary
460460
*/
461-
error = xfs_trans_alloc_inode(dp, &tres, total, rsvd, &args->trans);
461+
error = xfs_trans_alloc_inode(dp, &tres, total, 0, rsvd, &args->trans);
462462
if (error)
463463
return error;
464464

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ xfs_bmap_add_attrfork(
10791079

10801080
blks = XFS_ADDAFORK_SPACE_RES(mp);
10811081

1082-
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks,
1082+
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, 0,
10831083
rsvd, &tp);
10841084
if (error)
10851085
return error;

fs/xfs/xfs_bmap_util.c

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,6 @@ xfs_alloc_file_space(
730730
int rt;
731731
xfs_trans_t *tp;
732732
xfs_bmbt_irec_t imaps[1], *imapp;
733-
uint resblks, resrtextents;
734733
int error;
735734

736735
trace_xfs_alloc_file_space(ip);
@@ -760,7 +759,7 @@ xfs_alloc_file_space(
760759
*/
761760
while (allocatesize_fsb && !error) {
762761
xfs_fileoff_t s, e;
763-
unsigned int dblocks, rblocks;
762+
unsigned int dblocks, rblocks, resblks;
764763

765764
/*
766765
* Determine space reservations for data/realtime.
@@ -790,8 +789,6 @@ xfs_alloc_file_space(
790789
*/
791790
resblks = min_t(xfs_fileoff_t, (e - s), (MAXEXTLEN * nimaps));
792791
if (unlikely(rt)) {
793-
resrtextents = resblks;
794-
resrtextents /= mp->m_sb.sb_rextsize;
795792
dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
796793
rblocks = resblks;
797794
} else {
@@ -802,32 +799,16 @@ xfs_alloc_file_space(
802799
/*
803800
* Allocate and setup the transaction.
804801
*/
805-
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, dblocks,
806-
resrtextents, 0, &tp);
807-
808-
/*
809-
* Check for running out of space
810-
*/
811-
if (error) {
812-
/*
813-
* Free the transaction structure.
814-
*/
815-
ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp));
816-
break;
817-
}
818-
xfs_ilock(ip, XFS_ILOCK_EXCL);
819-
error = xfs_trans_reserve_quota_nblks(tp, ip, dblocks, rblocks,
820-
false);
802+
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write,
803+
dblocks, rblocks, false, &tp);
821804
if (error)
822-
goto error;
805+
break;
823806

824807
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
825808
XFS_IEXT_ADD_NOSPLIT_CNT);
826809
if (error)
827810
goto error;
828811

829-
xfs_trans_ijoin(tp, ip, 0);
830-
831812
error = xfs_bmapi_write(tp, ip, startoffset_fsb,
832813
allocatesize_fsb, alloc_type, 0, imapp,
833814
&nimaps);
@@ -873,7 +854,7 @@ xfs_unmap_extent(
873854
uint resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
874855
int error;
875856

876-
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks,
857+
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, 0,
877858
false, &tp);
878859
if (error)
879860
return error;

fs/xfs/xfs_iomap.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,15 @@ xfs_iomap_write_direct(
195195
xfs_filblks_t resaligned;
196196
int nimaps;
197197
unsigned int dblocks, rblocks;
198-
unsigned int resrtextents = 0;
198+
bool force = false;
199199
int error;
200200
int bmapi_flags = XFS_BMAPI_PREALLOC;
201-
int tflags = 0;
202-
bool force = false;
203201

204202
ASSERT(count_fsb > 0);
205203

206204
resaligned = xfs_aligned_fsb_count(offset_fsb, count_fsb,
207205
xfs_get_extsz_hint(ip));
208206
if (unlikely(XFS_IS_REALTIME_INODE(ip))) {
209-
resrtextents = resaligned;
210-
resrtextents /= mp->m_sb.sb_rextsize;
211207
dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
212208
rblocks = resaligned;
213209
} else {
@@ -236,28 +232,20 @@ xfs_iomap_write_direct(
236232
bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
237233
if (imap->br_state == XFS_EXT_UNWRITTEN) {
238234
force = true;
239-
tflags |= XFS_TRANS_RESERVE;
240235
dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
241236
}
242237
}
243-
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, dblocks, resrtextents,
244-
tflags, &tp);
245-
if (error)
246-
return error;
247238

248-
xfs_ilock(ip, XFS_ILOCK_EXCL);
249-
250-
error = xfs_trans_reserve_quota_nblks(tp, ip, dblocks, rblocks, force);
239+
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, dblocks,
240+
rblocks, force, &tp);
251241
if (error)
252-
goto out_trans_cancel;
242+
return error;
253243

254244
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
255245
XFS_IEXT_ADD_NOSPLIT_CNT);
256246
if (error)
257247
goto out_trans_cancel;
258248

259-
xfs_trans_ijoin(tp, ip, 0);
260-
261249
/*
262250
* From this point onwards we overwrite the imap pointer that the
263251
* caller gave to us.
@@ -553,7 +541,7 @@ xfs_iomap_write_unwritten(
553541
* complete here and might deadlock on the iolock.
554542
*/
555543
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks,
556-
true, &tp);
544+
0, true, &tp);
557545
if (error)
558546
return error;
559547

fs/xfs/xfs_trans.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,14 +1038,16 @@ xfs_trans_alloc_inode(
10381038
struct xfs_inode *ip,
10391039
struct xfs_trans_res *resv,
10401040
unsigned int dblocks,
1041+
unsigned int rblocks,
10411042
bool force,
10421043
struct xfs_trans **tpp)
10431044
{
10441045
struct xfs_trans *tp;
10451046
struct xfs_mount *mp = ip->i_mount;
10461047
int error;
10471048

1048-
error = xfs_trans_alloc(mp, resv, dblocks, 0,
1049+
error = xfs_trans_alloc(mp, resv, dblocks,
1050+
rblocks / mp->m_sb.sb_rextsize,
10491051
force ? XFS_TRANS_RESERVE : 0, &tp);
10501052
if (error)
10511053
return error;
@@ -1060,7 +1062,7 @@ xfs_trans_alloc_inode(
10601062
goto out_cancel;
10611063
}
10621064

1063-
error = xfs_trans_reserve_quota_nblks(tp, ip, dblocks, 0, force);
1065+
error = xfs_trans_reserve_quota_nblks(tp, ip, dblocks, rblocks, force);
10641066
if (error)
10651067
goto out_cancel;
10661068

fs/xfs/xfs_trans.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ xfs_trans_item_relog(
269269
}
270270

271271
int xfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv,
272-
unsigned int dblocks, bool force, struct xfs_trans **tpp);
272+
unsigned int dblocks, unsigned int rblocks, bool force,
273+
struct xfs_trans **tpp);
273274

274275
#endif /* __XFS_TRANS_H__ */

0 commit comments

Comments
 (0)