From: Darrick J. Wong <djwong@xxxxxxxxxx> Attach dquots to the realtime metadata files when starting up quotas, since the resources used by them are charged to the root dquot. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- fs/xfs/xfs_mount.c | 4 +++- fs/xfs/xfs_qm.c | 20 +++++++++++++++++--- fs/xfs/xfs_qm_bhv.c | 2 +- fs/xfs/xfs_quota.h | 4 ++-- fs/xfs/xfs_rtalloc.c | 22 ++++++++++++++++++++++ fs/xfs/xfs_rtalloc.h | 3 +++ 6 files changed, 48 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index b20e0e6410512..879945c305da4 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1024,7 +1024,9 @@ xfs_mountfs( ASSERT(mp->m_qflags == 0); mp->m_qflags = quotaflags; - xfs_qm_mount_quotas(mp); + error = xfs_qm_mount_quotas(mp); + if (error) + goto out_rtunmount; } /* diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index a6b5193190c4c..2771aef361a25 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -30,6 +30,7 @@ #include "xfs_imeta.h" #include "xfs_imeta_utils.h" #include "xfs_da_format.h" +#include "xfs_rtalloc.h" /* * The global quota manager. There is only one of these for the entire @@ -1525,7 +1526,7 @@ xfs_qm_quotacheck( * If we fail here, the mount will continue with quota turned off. We don't * need to inidicate success or failure at all. */ -void +int xfs_qm_mount_quotas( struct xfs_mount *mp) { @@ -1564,7 +1565,7 @@ xfs_qm_mount_quotas( error = xfs_qm_quotacheck(mp); if (error) { /* Quotacheck failed and disabled quotas. */ - return; + return 0; } } /* @@ -1605,8 +1606,21 @@ xfs_qm_mount_quotas( if (error) { xfs_warn(mp, "Failed to initialize disk quotas."); - return; + return 0; } + + /* + * Attach dquots to realtime metadata files before we do anything that + * could alter the resource usage of rt metadata (log recovery, normal + * operation, etc). + */ + error = xfs_rtmount_dqattach(mp); + if (error) { + xfs_qm_unmount_quotas(mp); + return error; + } + + return 0; } /* diff --git a/fs/xfs/xfs_qm_bhv.c b/fs/xfs/xfs_qm_bhv.c index 271c1021c7335..df569a839d3f9 100644 --- a/fs/xfs/xfs_qm_bhv.c +++ b/fs/xfs/xfs_qm_bhv.c @@ -119,7 +119,7 @@ xfs_qm_newmount( * mounting, and get on with the boring life * without disk quotas. */ - xfs_qm_mount_quotas(mp); + return xfs_qm_mount_quotas(mp); } else { /* * Clear the quota flags, but remember them. This diff --git a/fs/xfs/xfs_quota.h b/fs/xfs/xfs_quota.h index 165013f03db9e..b0cdbe1f1f275 100644 --- a/fs/xfs/xfs_quota.h +++ b/fs/xfs/xfs_quota.h @@ -125,7 +125,7 @@ extern void xfs_qm_dqdetach(struct xfs_inode *); extern void xfs_qm_dqrele(struct xfs_dquot *); extern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *); extern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *); -extern void xfs_qm_mount_quotas(struct xfs_mount *); +int xfs_qm_mount_quotas(struct xfs_mount *mp); extern void xfs_qm_unmount(struct xfs_mount *); extern void xfs_qm_unmount_quotas(struct xfs_mount *); @@ -206,7 +206,7 @@ xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp, #define xfs_qm_dqrele(d) do { (d) = (d); } while(0) #define xfs_qm_statvfs(ip, s) do { } while(0) #define xfs_qm_newmount(mp, a, b) (0) -#define xfs_qm_mount_quotas(mp) +#define xfs_qm_mount_quotas(mp) (0) #define xfs_qm_unmount(mp) #define xfs_qm_unmount_quotas(mp) #define xfs_inode_near_dquot_enforcement(ip, type) (false) diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 7917eaef911f6..cc83651636ecb 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -32,6 +32,7 @@ #include "xfs_rtrmap_btree.h" #include "xfs_trace.h" #include "xfs_rtrefcount_btree.h" +#include "xfs_quota.h" /* * Realtime metadata files are not quite regular files because userspace can't @@ -2039,6 +2040,27 @@ xfs_rtmount_inodes( return error; } +/* + * Attach dquots for realtime metadata files. Prior to the introduction of the + * metadata directory tree, the rtbitmap and rtsummary inodes were counted in + * the root dquot icount, so we must dqattach them to maintain correct counts. + */ +int +xfs_rtmount_dqattach( + struct xfs_mount *mp) +{ + int error; + + if (xfs_has_metadir(mp)) + return 0; + + error = xfs_qm_dqattach(mp->m_rbmip); + if (error) + return error; + + return xfs_qm_dqattach(mp->m_rsumip); +} + void xfs_rtunmount_inodes( struct xfs_mount *mp) diff --git a/fs/xfs/xfs_rtalloc.h b/fs/xfs/xfs_rtalloc.h index 8a7b6cfa13cf0..a03796ea90eaf 100644 --- a/fs/xfs/xfs_rtalloc.h +++ b/fs/xfs/xfs_rtalloc.h @@ -46,6 +46,8 @@ void xfs_rtunmount_inodes( struct xfs_mount *mp); +int xfs_rtmount_dqattach(struct xfs_mount *mp); + /* * Get the bitmap and summary inodes into the mount structure * at mount time. @@ -106,6 +108,7 @@ xfs_rtmount_init( # define xfs_rt_resv_free(mp) ((void)0) # define xfs_rt_resv_init(mp) (0) # define xfs_growfs_check_rtgeom(mp, d, r, rs, rx, rb, rl) (0) +# define xfs_rtmount_dqattach(mp) (0) #endif /* CONFIG_XFS_RT */ #endif /* __XFS_RTALLOC_H__ */