162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2000-2005 Silicon Graphics, Inc. 462306a36Sopenharmony_ci * All Rights Reserved. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#ifndef __XFS_QUOTA_H__ 762306a36Sopenharmony_ci#define __XFS_QUOTA_H__ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include "xfs_quota_defs.h" 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/* 1262306a36Sopenharmony_ci * Kernel only quota definitions and functions 1362306a36Sopenharmony_ci */ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cistruct xfs_trans; 1662306a36Sopenharmony_cistruct xfs_buf; 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* 1962306a36Sopenharmony_ci * This check is done typically without holding the inode lock; 2062306a36Sopenharmony_ci * that may seem racy, but it is harmless in the context that it is used. 2162306a36Sopenharmony_ci * The inode cannot go inactive as long a reference is kept, and 2262306a36Sopenharmony_ci * therefore if dquot(s) were attached, they'll stay consistent. 2362306a36Sopenharmony_ci * If, for example, the ownership of the inode changes while 2462306a36Sopenharmony_ci * we didn't have the inode locked, the appropriate dquot(s) will be 2562306a36Sopenharmony_ci * attached atomically. 2662306a36Sopenharmony_ci */ 2762306a36Sopenharmony_ci#define XFS_NOT_DQATTACHED(mp, ip) \ 2862306a36Sopenharmony_ci ((XFS_IS_UQUOTA_ON(mp) && (ip)->i_udquot == NULL) || \ 2962306a36Sopenharmony_ci (XFS_IS_GQUOTA_ON(mp) && (ip)->i_gdquot == NULL) || \ 3062306a36Sopenharmony_ci (XFS_IS_PQUOTA_ON(mp) && (ip)->i_pdquot == NULL)) 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#define XFS_QM_NEED_QUOTACHECK(mp) \ 3362306a36Sopenharmony_ci ((XFS_IS_UQUOTA_ON(mp) && \ 3462306a36Sopenharmony_ci (mp->m_sb.sb_qflags & XFS_UQUOTA_CHKD) == 0) || \ 3562306a36Sopenharmony_ci (XFS_IS_GQUOTA_ON(mp) && \ 3662306a36Sopenharmony_ci (mp->m_sb.sb_qflags & XFS_GQUOTA_CHKD) == 0) || \ 3762306a36Sopenharmony_ci (XFS_IS_PQUOTA_ON(mp) && \ 3862306a36Sopenharmony_ci (mp->m_sb.sb_qflags & XFS_PQUOTA_CHKD) == 0)) 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cistatic inline uint 4162306a36Sopenharmony_cixfs_quota_chkd_flag( 4262306a36Sopenharmony_ci xfs_dqtype_t type) 4362306a36Sopenharmony_ci{ 4462306a36Sopenharmony_ci switch (type) { 4562306a36Sopenharmony_ci case XFS_DQTYPE_USER: 4662306a36Sopenharmony_ci return XFS_UQUOTA_CHKD; 4762306a36Sopenharmony_ci case XFS_DQTYPE_GROUP: 4862306a36Sopenharmony_ci return XFS_GQUOTA_CHKD; 4962306a36Sopenharmony_ci case XFS_DQTYPE_PROJ: 5062306a36Sopenharmony_ci return XFS_PQUOTA_CHKD; 5162306a36Sopenharmony_ci default: 5262306a36Sopenharmony_ci return 0; 5362306a36Sopenharmony_ci } 5462306a36Sopenharmony_ci} 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/* 5762306a36Sopenharmony_ci * The structure kept inside the xfs_trans_t keep track of dquot changes 5862306a36Sopenharmony_ci * within a transaction and apply them later. 5962306a36Sopenharmony_ci */ 6062306a36Sopenharmony_cistruct xfs_dqtrx { 6162306a36Sopenharmony_ci struct xfs_dquot *qt_dquot; /* the dquot this refers to */ 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci uint64_t qt_blk_res; /* blks reserved on a dquot */ 6462306a36Sopenharmony_ci int64_t qt_bcount_delta; /* dquot blk count changes */ 6562306a36Sopenharmony_ci int64_t qt_delbcnt_delta; /* delayed dquot blk count changes */ 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci uint64_t qt_rtblk_res; /* # blks reserved on a dquot */ 6862306a36Sopenharmony_ci uint64_t qt_rtblk_res_used;/* # blks used from reservation */ 6962306a36Sopenharmony_ci int64_t qt_rtbcount_delta;/* dquot realtime blk changes */ 7062306a36Sopenharmony_ci int64_t qt_delrtb_delta; /* delayed RT blk count changes */ 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci uint64_t qt_ino_res; /* inode reserved on a dquot */ 7362306a36Sopenharmony_ci uint64_t qt_ino_res_used; /* inodes used from the reservation */ 7462306a36Sopenharmony_ci int64_t qt_icount_delta; /* dquot inode count changes */ 7562306a36Sopenharmony_ci}; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci#ifdef CONFIG_XFS_QUOTA 7862306a36Sopenharmony_ciextern void xfs_trans_dup_dqinfo(struct xfs_trans *, struct xfs_trans *); 7962306a36Sopenharmony_ciextern void xfs_trans_free_dqinfo(struct xfs_trans *); 8062306a36Sopenharmony_ciextern void xfs_trans_mod_dquot_byino(struct xfs_trans *, struct xfs_inode *, 8162306a36Sopenharmony_ci uint, int64_t); 8262306a36Sopenharmony_ciextern void xfs_trans_apply_dquot_deltas(struct xfs_trans *); 8362306a36Sopenharmony_ciextern void xfs_trans_unreserve_and_mod_dquots(struct xfs_trans *); 8462306a36Sopenharmony_ciint xfs_trans_reserve_quota_nblks(struct xfs_trans *tp, struct xfs_inode *ip, 8562306a36Sopenharmony_ci int64_t dblocks, int64_t rblocks, bool force); 8662306a36Sopenharmony_ciextern int xfs_trans_reserve_quota_bydquots(struct xfs_trans *, 8762306a36Sopenharmony_ci struct xfs_mount *, struct xfs_dquot *, 8862306a36Sopenharmony_ci struct xfs_dquot *, struct xfs_dquot *, int64_t, long, uint); 8962306a36Sopenharmony_ciint xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, 9062306a36Sopenharmony_ci struct xfs_dquot *udqp, struct xfs_dquot *gdqp, 9162306a36Sopenharmony_ci struct xfs_dquot *pdqp, int64_t dblocks); 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ciextern int xfs_qm_vop_dqalloc(struct xfs_inode *, kuid_t, kgid_t, 9462306a36Sopenharmony_ci prid_t, uint, struct xfs_dquot **, struct xfs_dquot **, 9562306a36Sopenharmony_ci struct xfs_dquot **); 9662306a36Sopenharmony_ciextern void xfs_qm_vop_create_dqattach(struct xfs_trans *, struct xfs_inode *, 9762306a36Sopenharmony_ci struct xfs_dquot *, struct xfs_dquot *, struct xfs_dquot *); 9862306a36Sopenharmony_ciextern int xfs_qm_vop_rename_dqattach(struct xfs_inode **); 9962306a36Sopenharmony_ciextern struct xfs_dquot *xfs_qm_vop_chown(struct xfs_trans *, 10062306a36Sopenharmony_ci struct xfs_inode *, struct xfs_dquot **, struct xfs_dquot *); 10162306a36Sopenharmony_ciextern int xfs_qm_dqattach(struct xfs_inode *); 10262306a36Sopenharmony_ciextern int xfs_qm_dqattach_locked(struct xfs_inode *ip, bool doalloc); 10362306a36Sopenharmony_ciextern void xfs_qm_dqdetach(struct xfs_inode *); 10462306a36Sopenharmony_ciextern void xfs_qm_dqrele(struct xfs_dquot *); 10562306a36Sopenharmony_ciextern void xfs_qm_statvfs(struct xfs_inode *, struct kstatfs *); 10662306a36Sopenharmony_ciextern int xfs_qm_newmount(struct xfs_mount *, uint *, uint *); 10762306a36Sopenharmony_ciextern void xfs_qm_mount_quotas(struct xfs_mount *); 10862306a36Sopenharmony_ciextern void xfs_qm_unmount(struct xfs_mount *); 10962306a36Sopenharmony_ciextern void xfs_qm_unmount_quotas(struct xfs_mount *); 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_cistatic inline int 11262306a36Sopenharmony_cixfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks) 11362306a36Sopenharmony_ci{ 11462306a36Sopenharmony_ci return xfs_trans_reserve_quota_nblks(NULL, ip, blocks, 0, false); 11562306a36Sopenharmony_ci} 11662306a36Sopenharmony_cibool xfs_inode_near_dquot_enforcement(struct xfs_inode *ip, xfs_dqtype_t type); 11762306a36Sopenharmony_ci#else 11862306a36Sopenharmony_cistatic inline int 11962306a36Sopenharmony_cixfs_qm_vop_dqalloc(struct xfs_inode *ip, kuid_t kuid, kgid_t kgid, 12062306a36Sopenharmony_ci prid_t prid, uint flags, struct xfs_dquot **udqp, 12162306a36Sopenharmony_ci struct xfs_dquot **gdqp, struct xfs_dquot **pdqp) 12262306a36Sopenharmony_ci{ 12362306a36Sopenharmony_ci *udqp = NULL; 12462306a36Sopenharmony_ci *gdqp = NULL; 12562306a36Sopenharmony_ci *pdqp = NULL; 12662306a36Sopenharmony_ci return 0; 12762306a36Sopenharmony_ci} 12862306a36Sopenharmony_ci#define xfs_trans_dup_dqinfo(tp, tp2) 12962306a36Sopenharmony_ci#define xfs_trans_free_dqinfo(tp) 13062306a36Sopenharmony_ci#define xfs_trans_mod_dquot_byino(tp, ip, fields, delta) do { } while (0) 13162306a36Sopenharmony_ci#define xfs_trans_apply_dquot_deltas(tp) 13262306a36Sopenharmony_ci#define xfs_trans_unreserve_and_mod_dquots(tp) 13362306a36Sopenharmony_cistatic inline int xfs_trans_reserve_quota_nblks(struct xfs_trans *tp, 13462306a36Sopenharmony_ci struct xfs_inode *ip, int64_t dblocks, int64_t rblocks, 13562306a36Sopenharmony_ci bool force) 13662306a36Sopenharmony_ci{ 13762306a36Sopenharmony_ci return 0; 13862306a36Sopenharmony_ci} 13962306a36Sopenharmony_cistatic inline int xfs_trans_reserve_quota_bydquots(struct xfs_trans *tp, 14062306a36Sopenharmony_ci struct xfs_mount *mp, struct xfs_dquot *udqp, 14162306a36Sopenharmony_ci struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, 14262306a36Sopenharmony_ci int64_t nblks, long nions, uint flags) 14362306a36Sopenharmony_ci{ 14462306a36Sopenharmony_ci return 0; 14562306a36Sopenharmony_ci} 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_cistatic inline int 14862306a36Sopenharmony_cixfs_quota_reserve_blkres(struct xfs_inode *ip, int64_t blocks) 14962306a36Sopenharmony_ci{ 15062306a36Sopenharmony_ci return 0; 15162306a36Sopenharmony_ci} 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_cistatic inline int 15462306a36Sopenharmony_cixfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp, 15562306a36Sopenharmony_ci struct xfs_dquot *gdqp, struct xfs_dquot *pdqp, int64_t dblocks) 15662306a36Sopenharmony_ci{ 15762306a36Sopenharmony_ci return 0; 15862306a36Sopenharmony_ci} 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci#define xfs_qm_vop_create_dqattach(tp, ip, u, g, p) 16162306a36Sopenharmony_ci#define xfs_qm_vop_rename_dqattach(it) (0) 16262306a36Sopenharmony_ci#define xfs_qm_vop_chown(tp, ip, old, new) (NULL) 16362306a36Sopenharmony_ci#define xfs_qm_dqattach(ip) (0) 16462306a36Sopenharmony_ci#define xfs_qm_dqattach_locked(ip, fl) (0) 16562306a36Sopenharmony_ci#define xfs_qm_dqdetach(ip) 16662306a36Sopenharmony_ci#define xfs_qm_dqrele(d) do { (d) = (d); } while(0) 16762306a36Sopenharmony_ci#define xfs_qm_statvfs(ip, s) do { } while(0) 16862306a36Sopenharmony_ci#define xfs_qm_newmount(mp, a, b) (0) 16962306a36Sopenharmony_ci#define xfs_qm_mount_quotas(mp) 17062306a36Sopenharmony_ci#define xfs_qm_unmount(mp) 17162306a36Sopenharmony_ci#define xfs_qm_unmount_quotas(mp) 17262306a36Sopenharmony_ci#define xfs_inode_near_dquot_enforcement(ip, type) (false) 17362306a36Sopenharmony_ci#endif /* CONFIG_XFS_QUOTA */ 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_cistatic inline int 17662306a36Sopenharmony_cixfs_quota_unreserve_blkres(struct xfs_inode *ip, int64_t blocks) 17762306a36Sopenharmony_ci{ 17862306a36Sopenharmony_ci return xfs_quota_reserve_blkres(ip, -blocks); 17962306a36Sopenharmony_ci} 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ciextern int xfs_mount_reset_sbqflags(struct xfs_mount *); 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci#endif /* __XFS_QUOTA_H__ */ 184