提交 ad1f1189 编写于 作者: D Darrick J. Wong 提交者: Zheng Zengkai

xfs: allow reservation of rtblocks with xfs_trans_alloc_inode

mainline-inclusion
from mainline-v5.11-rc4
commit 3de4eb10
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I4KIAO
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3de4eb106fcc97f086b78bd17a0c3529691e8259

-------------------------------------------------

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: NDarrick J. Wong <djwong@kernel.org>
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NBrian Foster <bfoster@redhat.com>
Signed-off-by: NLihong Kou <koulihong@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 1d83fbbb
...@@ -453,7 +453,7 @@ xfs_attr_set( ...@@ -453,7 +453,7 @@ xfs_attr_set(
* Root fork attributes can use reserved data blocks for this * Root fork attributes can use reserved data blocks for this
* operation if necessary * operation if necessary
*/ */
error = xfs_trans_alloc_inode(dp, &tres, total, rsvd, &args->trans); error = xfs_trans_alloc_inode(dp, &tres, total, 0, rsvd, &args->trans);
if (error) if (error)
return error; return error;
......
...@@ -1078,7 +1078,7 @@ xfs_bmap_add_attrfork( ...@@ -1078,7 +1078,7 @@ xfs_bmap_add_attrfork(
blks = XFS_ADDAFORK_SPACE_RES(mp); blks = XFS_ADDAFORK_SPACE_RES(mp);
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, 0,
rsvd, &tp); rsvd, &tp);
if (error) if (error)
return error; return error;
......
...@@ -730,7 +730,6 @@ xfs_alloc_file_space( ...@@ -730,7 +730,6 @@ xfs_alloc_file_space(
int rt; int rt;
xfs_trans_t *tp; xfs_trans_t *tp;
xfs_bmbt_irec_t imaps[1], *imapp; xfs_bmbt_irec_t imaps[1], *imapp;
uint resblks, resrtextents;
int error; int error;
trace_xfs_alloc_file_space(ip); trace_xfs_alloc_file_space(ip);
...@@ -760,7 +759,7 @@ xfs_alloc_file_space( ...@@ -760,7 +759,7 @@ xfs_alloc_file_space(
*/ */
while (allocatesize_fsb && !error) { while (allocatesize_fsb && !error) {
xfs_fileoff_t s, e; xfs_fileoff_t s, e;
unsigned int dblocks, rblocks; unsigned int dblocks, rblocks, resblks;
/* /*
* Determine space reservations for data/realtime. * Determine space reservations for data/realtime.
...@@ -790,8 +789,6 @@ xfs_alloc_file_space( ...@@ -790,8 +789,6 @@ xfs_alloc_file_space(
*/ */
resblks = min_t(xfs_fileoff_t, (e - s), (MAXEXTLEN * nimaps)); resblks = min_t(xfs_fileoff_t, (e - s), (MAXEXTLEN * nimaps));
if (unlikely(rt)) { if (unlikely(rt)) {
resrtextents = resblks;
resrtextents /= mp->m_sb.sb_rextsize;
dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0); dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
rblocks = resblks; rblocks = resblks;
} else { } else {
...@@ -802,26 +799,11 @@ xfs_alloc_file_space( ...@@ -802,26 +799,11 @@ xfs_alloc_file_space(
/* /*
* Allocate and setup the transaction. * Allocate and setup the transaction.
*/ */
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, dblocks, error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write,
resrtextents, 0, &tp); dblocks, rblocks, false, &tp);
/*
* Check for running out of space
*/
if (error) {
/*
* Free the transaction structure.
*/
ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp));
break;
}
xfs_ilock(ip, XFS_ILOCK_EXCL);
error = xfs_trans_reserve_quota_nblks(tp, ip, dblocks, rblocks,
false);
if (error) if (error)
goto error; break;
xfs_trans_ijoin(tp, ip, 0);
error = xfs_bmapi_write(tp, ip, startoffset_fsb, error = xfs_bmapi_write(tp, ip, startoffset_fsb,
allocatesize_fsb, alloc_type, 0, imapp, allocatesize_fsb, alloc_type, 0, imapp,
...@@ -868,7 +850,7 @@ xfs_unmap_extent( ...@@ -868,7 +850,7 @@ xfs_unmap_extent(
uint resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0); uint resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
int error; int error;
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, 0,
false, &tp); false, &tp);
if (error) if (error)
return error; return error;
......
...@@ -195,19 +195,15 @@ xfs_iomap_write_direct( ...@@ -195,19 +195,15 @@ xfs_iomap_write_direct(
xfs_filblks_t resaligned; xfs_filblks_t resaligned;
int nimaps; int nimaps;
unsigned int dblocks, rblocks; unsigned int dblocks, rblocks;
unsigned int resrtextents = 0; bool force = false;
int error; int error;
int bmapi_flags = XFS_BMAPI_PREALLOC; int bmapi_flags = XFS_BMAPI_PREALLOC;
int tflags = 0;
bool force = false;
ASSERT(count_fsb > 0); ASSERT(count_fsb > 0);
resaligned = xfs_aligned_fsb_count(offset_fsb, count_fsb, resaligned = xfs_aligned_fsb_count(offset_fsb, count_fsb,
xfs_get_extsz_hint(ip)); xfs_get_extsz_hint(ip));
if (unlikely(XFS_IS_REALTIME_INODE(ip))) { if (unlikely(XFS_IS_REALTIME_INODE(ip))) {
resrtextents = resaligned;
resrtextents /= mp->m_sb.sb_rextsize;
dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0); dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
rblocks = resaligned; rblocks = resaligned;
} else { } else {
...@@ -236,22 +232,14 @@ xfs_iomap_write_direct( ...@@ -236,22 +232,14 @@ xfs_iomap_write_direct(
bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO; bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
if (imap->br_state == XFS_EXT_UNWRITTEN) { if (imap->br_state == XFS_EXT_UNWRITTEN) {
force = true; force = true;
tflags |= XFS_TRANS_RESERVE;
dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1; dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
} }
} }
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, dblocks, resrtextents,
tflags, &tp);
if (error)
return error;
xfs_ilock(ip, XFS_ILOCK_EXCL); error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, dblocks,
rblocks, force, &tp);
error = xfs_trans_reserve_quota_nblks(tp, ip, dblocks, rblocks, force);
if (error) if (error)
goto out_trans_cancel; return error;
xfs_trans_ijoin(tp, ip, 0);
/* /*
* From this point onwards we overwrite the imap pointer that the * From this point onwards we overwrite the imap pointer that the
...@@ -548,7 +536,7 @@ xfs_iomap_write_unwritten( ...@@ -548,7 +536,7 @@ xfs_iomap_write_unwritten(
* complete here and might deadlock on the iolock. * complete here and might deadlock on the iolock.
*/ */
error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks,
true, &tp); 0, true, &tp);
if (error) if (error)
return error; return error;
......
...@@ -1034,6 +1034,7 @@ xfs_trans_alloc_inode( ...@@ -1034,6 +1034,7 @@ xfs_trans_alloc_inode(
struct xfs_inode *ip, struct xfs_inode *ip,
struct xfs_trans_res *resv, struct xfs_trans_res *resv,
unsigned int dblocks, unsigned int dblocks,
unsigned int rblocks,
bool force, bool force,
struct xfs_trans **tpp) struct xfs_trans **tpp)
{ {
...@@ -1041,7 +1042,8 @@ xfs_trans_alloc_inode( ...@@ -1041,7 +1042,8 @@ xfs_trans_alloc_inode(
struct xfs_mount *mp = ip->i_mount; struct xfs_mount *mp = ip->i_mount;
int error; int error;
error = xfs_trans_alloc(mp, resv, dblocks, 0, error = xfs_trans_alloc(mp, resv, dblocks,
rblocks / mp->m_sb.sb_rextsize,
force ? XFS_TRANS_RESERVE : 0, &tp); force ? XFS_TRANS_RESERVE : 0, &tp);
if (error) if (error)
return error; return error;
...@@ -1056,7 +1058,7 @@ xfs_trans_alloc_inode( ...@@ -1056,7 +1058,7 @@ xfs_trans_alloc_inode(
goto out_cancel; goto out_cancel;
} }
error = xfs_trans_reserve_quota_nblks(tp, ip, dblocks, 0, force); error = xfs_trans_reserve_quota_nblks(tp, ip, dblocks, rblocks, force);
if (error) if (error)
goto out_cancel; goto out_cancel;
......
...@@ -254,6 +254,7 @@ xfs_trans_item_relog( ...@@ -254,6 +254,7 @@ xfs_trans_item_relog(
} }
int xfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv, int xfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv,
unsigned int dblocks, bool force, struct xfs_trans **tpp); unsigned int dblocks, unsigned int rblocks, bool force,
struct xfs_trans **tpp);
#endif /* __XFS_TRANS_H__ */ #endif /* __XFS_TRANS_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册