Skip to content

Commit dcf1ccc

Browse files
Eric Sandeendjwong
authored andcommitted
xfs: always return -ENOSPC on project quota reservation failure
XFS project quota treats project hierarchies as "mini filesysems" and so rather than -EDQUOT, the intent is to return -ENOSPC when a quota reservation fails, but this behavior is not consistent. The only place we make a decision between -EDQUOT and -ENOSPC returns based on quota type is in xfs_trans_dqresv(). This behavior is currently controlled by whether or not the XFS_QMOPT_ENOSPC flag gets passed into the quota reservation. However, its use is not consistent; paths such as xfs_create() and xfs_symlink() don't set the flag, so a reservation failure will return -EDQUOT for project quota reservation failures rather than -ENOSPC for these sorts of operations, even for project quota: # mkdir mnt/project # xfs_quota -x -c "project -s -p mnt/project 42" mnt # xfs_quota -x -c 'limit -p isoft=2 ihard=3 42' mnt # touch mnt/project/file{1,2,3} touch: cannot touch ‘mnt/project/file3’: Disk quota exceeded We can make this consistent by not requiring the flag to be set at the top of the callchain; instead we can simply test whether we are reserving a project quota with XFS_QM_ISPDQ in xfs_trans_dqresv and if so, return -ENOSPC for that failure. This removes the need for the XFS_QMOPT_ENOSPC altogether and simplifies the code a fair bit. Signed-off-by: Eric Sandeen <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent c8d329f commit dcf1ccc

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

fs/xfs/libxfs/xfs_quota_defs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ typedef uint16_t xfs_qwarncnt_t;
100100
#define XFS_QMOPT_FORCE_RES 0x0000010 /* ignore quota limits */
101101
#define XFS_QMOPT_SBVERSION 0x0000040 /* change superblock version num */
102102
#define XFS_QMOPT_GQUOTA 0x0002000 /* group dquot requested */
103-
#define XFS_QMOPT_ENOSPC 0x0004000 /* enospc instead of edquot (prj) */
104103

105104
/*
106105
* flags to xfs_trans_mod_dquot to indicate which field needs to be

fs/xfs/xfs_qm.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,7 @@ xfs_qm_vop_chown_reserve(
18081808
{
18091809
struct xfs_mount *mp = ip->i_mount;
18101810
uint64_t delblks;
1811-
unsigned int blkflags, prjflags = 0;
1811+
unsigned int blkflags;
18121812
struct xfs_dquot *udq_unres = NULL;
18131813
struct xfs_dquot *gdq_unres = NULL;
18141814
struct xfs_dquot *pdq_unres = NULL;
@@ -1849,7 +1849,6 @@ xfs_qm_vop_chown_reserve(
18491849

18501850
if (XFS_IS_PQUOTA_ON(ip->i_mount) && pdqp &&
18511851
ip->i_d.di_projid != be32_to_cpu(pdqp->q_core.d_id)) {
1852-
prjflags = XFS_QMOPT_ENOSPC;
18531852
pdq_delblks = pdqp;
18541853
if (delblks) {
18551854
ASSERT(ip->i_pdquot);
@@ -1859,8 +1858,7 @@ xfs_qm_vop_chown_reserve(
18591858

18601859
error = xfs_trans_reserve_quota_bydquots(tp, ip->i_mount,
18611860
udq_delblks, gdq_delblks, pdq_delblks,
1862-
ip->i_d.di_nblocks, 1,
1863-
flags | blkflags | prjflags);
1861+
ip->i_d.di_nblocks, 1, flags | blkflags);
18641862
if (error)
18651863
return error;
18661864

@@ -1878,8 +1876,7 @@ xfs_qm_vop_chown_reserve(
18781876
ASSERT(udq_unres || gdq_unres || pdq_unres);
18791877
error = xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,
18801878
udq_delblks, gdq_delblks, pdq_delblks,
1881-
(xfs_qcnt_t)delblks, 0,
1882-
flags | blkflags | prjflags);
1879+
(xfs_qcnt_t)delblks, 0, flags | blkflags);
18831880
if (error)
18841881
return error;
18851882
xfs_trans_reserve_quota_bydquots(NULL, ip->i_mount,

fs/xfs/xfs_trans_dquot.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ xfs_trans_dqresv(
711711

712712
error_return:
713713
xfs_dqunlock(dqp);
714-
if (flags & XFS_QMOPT_ENOSPC)
714+
if (XFS_QM_ISPDQ(dqp))
715715
return -ENOSPC;
716716
return -EDQUOT;
717717
}
@@ -751,15 +751,13 @@ xfs_trans_reserve_quota_bydquots(
751751
ASSERT(flags & XFS_QMOPT_RESBLK_MASK);
752752

753753
if (udqp) {
754-
error = xfs_trans_dqresv(tp, mp, udqp, nblks, ninos,
755-
(flags & ~XFS_QMOPT_ENOSPC));
754+
error = xfs_trans_dqresv(tp, mp, udqp, nblks, ninos, flags);
756755
if (error)
757756
return error;
758757
}
759758

760759
if (gdqp) {
761-
error = xfs_trans_dqresv(tp, mp, gdqp, nblks, ninos,
762-
(flags & ~XFS_QMOPT_ENOSPC));
760+
error = xfs_trans_dqresv(tp, mp, gdqp, nblks, ninos, flags);
763761
if (error)
764762
goto unwind_usr;
765763
}
@@ -804,16 +802,12 @@ xfs_trans_reserve_quota_nblks(
804802

805803
if (!XFS_IS_QUOTA_RUNNING(mp) || !XFS_IS_QUOTA_ON(mp))
806804
return 0;
807-
if (XFS_IS_PQUOTA_ON(mp))
808-
flags |= XFS_QMOPT_ENOSPC;
809805

810806
ASSERT(!xfs_is_quota_inode(&mp->m_sb, ip->i_ino));
811807

812808
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
813-
ASSERT((flags & ~(XFS_QMOPT_FORCE_RES | XFS_QMOPT_ENOSPC)) ==
814-
XFS_TRANS_DQ_RES_RTBLKS ||
815-
(flags & ~(XFS_QMOPT_FORCE_RES | XFS_QMOPT_ENOSPC)) ==
816-
XFS_TRANS_DQ_RES_BLKS);
809+
ASSERT((flags & ~(XFS_QMOPT_FORCE_RES)) == XFS_TRANS_DQ_RES_RTBLKS ||
810+
(flags & ~(XFS_QMOPT_FORCE_RES)) == XFS_TRANS_DQ_RES_BLKS);
817811

818812
/*
819813
* Reserve nblks against these dquots, with trans as the mediator.

0 commit comments

Comments
 (0)