Skip to content

Commit

Permalink
xfs: create xfs_dqtype_t to represent quota types
Browse files Browse the repository at this point in the history
Create a new type (xfs_dqtype_t) to represent the type of an incore
dquot (user, group, project, or none).  Rename the incore dquot's
dq_flags field to q_type.

This allows us to replace all the "uint type" arguments to the quota
functions with "xfs_dqtype_t type", to make it obvious when we're
passing a quota type argument into a function.

Signed-off-by: Darrick J. Wong <[email protected]>
Reviewed-by: Dave Chinner <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
  • Loading branch information
djwong committed Jul 29, 2020
1 parent 74ddd6b commit 1a7ed27
Show file tree
Hide file tree
Showing 15 changed files with 126 additions and 101 deletions.
2 changes: 1 addition & 1 deletion fs/xfs/libxfs/xfs_dquot_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ xfs_dqblk_repair(
struct xfs_mount *mp,
struct xfs_dqblk *dqb,
xfs_dqid_t id,
uint type)
xfs_dqtype_t type)
{
/*
* Typically, a repair is only requested by quotacheck.
Expand Down
9 changes: 9 additions & 0 deletions fs/xfs/libxfs/xfs_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,15 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
#define XFS_DQUOT_MAGIC 0x4451 /* 'DQ' */
#define XFS_DQUOT_VERSION (uint8_t)0x01 /* latest version number */

#define XFS_DQTYPE_USER 0x01 /* user dquot record */
#define XFS_DQTYPE_PROJ 0x02 /* project dquot record */
#define XFS_DQTYPE_GROUP 0x04 /* group dquot record */

/* bitmask to determine if this is a user/group/project dquot */
#define XFS_DQTYPE_REC_MASK (XFS_DQTYPE_USER | \
XFS_DQTYPE_PROJ | \
XFS_DQTYPE_GROUP)

/*
* This is the main portion of the on-disk representation of quota information
* for a user. We pad this with some more expansion room to construct the on
Expand Down
23 changes: 10 additions & 13 deletions fs/xfs/libxfs/xfs_quota_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,20 @@
typedef uint64_t xfs_qcnt_t;
typedef uint16_t xfs_qwarncnt_t;

typedef uint8_t xfs_dqtype_t;

#define XFS_DQTYPE_STRINGS \
{ XFS_DQTYPE_USER, "USER" }, \
{ XFS_DQTYPE_PROJ, "PROJ" }, \
{ XFS_DQTYPE_GROUP, "GROUP" }

/*
* flags for q_flags field in the dquot.
*/
#define XFS_DQTYPE_USER 0x0001 /* a user quota */
#define XFS_DQTYPE_PROJ 0x0002 /* project quota */
#define XFS_DQTYPE_GROUP 0x0004 /* a group quota */
#define XFS_DQFLAG_DIRTY 0x0008 /* dquot is dirty */
#define XFS_DQFLAG_FREEING 0x0010 /* dquot is being torn down */

#define XFS_DQTYPE_REC_MASK (XFS_DQTYPE_USER | \
XFS_DQTYPE_PROJ | \
XFS_DQTYPE_GROUP)
#define XFS_DQFLAG_DIRTY (1 << 0) /* dquot is dirty */
#define XFS_DQFLAG_FREEING (1 << 1) /* dquot is being torn down */

#define XFS_DQFLAG_STRINGS \
{ XFS_DQTYPE_USER, "USER" }, \
{ XFS_DQTYPE_PROJ, "PROJ" }, \
{ XFS_DQTYPE_GROUP, "GROUP" }, \
{ XFS_DQFLAG_DIRTY, "DIRTY" }, \
{ XFS_DQFLAG_FREEING, "FREEING" }

Expand Down Expand Up @@ -144,6 +141,6 @@ extern xfs_failaddr_t xfs_dqblk_verify(struct xfs_mount *mp,
struct xfs_dqblk *dqb, xfs_dqid_t id);
extern int xfs_calc_dquots_per_chunk(unsigned int nbblks);
extern void xfs_dqblk_repair(struct xfs_mount *mp, struct xfs_dqblk *dqb,
xfs_dqid_t id, uint type);
xfs_dqid_t id, xfs_dqtype_t type);

#endif /* __XFS_QUOTA_H__ */
8 changes: 4 additions & 4 deletions fs/xfs/scrub/quota.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "scrub/common.h"

/* Convert a scrub type code to a DQ flag, or return 0 if error. */
static inline uint
static inline xfs_dqtype_t
xchk_quota_to_dqtype(
struct xfs_scrub *sc)
{
Expand All @@ -40,7 +40,7 @@ xchk_setup_quota(
struct xfs_scrub *sc,
struct xfs_inode *ip)
{
uint dqtype;
xfs_dqtype_t dqtype;
int error;

if (!XFS_IS_QUOTA_RUNNING(sc->mp) || !XFS_IS_QUOTA_ON(sc->mp))
Expand Down Expand Up @@ -73,7 +73,7 @@ struct xchk_quota_info {
STATIC int
xchk_quota_item(
struct xfs_dquot *dq,
uint dqtype,
xfs_dqtype_t dqtype,
void *priv)
{
struct xchk_quota_info *sqi = priv;
Expand Down Expand Up @@ -214,7 +214,7 @@ xchk_quota(
struct xchk_quota_info sqi;
struct xfs_mount *mp = sc->mp;
struct xfs_quotainfo *qi = mp->m_quotainfo;
uint dqtype;
xfs_dqtype_t dqtype;
int error = 0;

dqtype = xchk_quota_to_dqtype(sc);
Expand Down
4 changes: 2 additions & 2 deletions fs/xfs/scrub/repair.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,11 @@ xrep_find_ag_btree_roots(
void
xrep_force_quotacheck(
struct xfs_scrub *sc,
uint dqtype)
xfs_dqtype_t type)
{
uint flag;

flag = xfs_quota_chkd_flag(dqtype);
flag = xfs_quota_chkd_flag(type);
if (!(flag & sc->mp->m_qflags))
return;

Expand Down
4 changes: 3 additions & 1 deletion fs/xfs/scrub/repair.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef __XFS_SCRUB_REPAIR_H__
#define __XFS_SCRUB_REPAIR_H__

#include "xfs_quota_defs.h"

static inline int xrep_notsupported(struct xfs_scrub *sc)
{
return -EOPNOTSUPP;
Expand Down Expand Up @@ -49,7 +51,7 @@ struct xrep_find_ag_btree {

int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp,
struct xrep_find_ag_btree *btree_info, struct xfs_buf *agfl_bp);
void xrep_force_quotacheck(struct xfs_scrub *sc, uint dqtype);
void xrep_force_quotacheck(struct xfs_scrub *sc, xfs_dqtype_t type);
int xrep_ino_dqattach(struct xfs_scrub *sc);

/* Metadata repairers */
Expand Down
37 changes: 19 additions & 18 deletions fs/xfs/xfs_dquot.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ xfs_qm_init_dquot_blk(
struct xfs_trans *tp,
struct xfs_mount *mp,
xfs_dqid_t id,
uint type,
xfs_dqtype_t type,
struct xfs_buf *bp)
{
struct xfs_quotainfo *q = mp->m_quotainfo;
Expand Down Expand Up @@ -273,7 +273,7 @@ xfs_dquot_disk_alloc(
struct xfs_trans *tp = *tpp;
struct xfs_mount *mp = tp->t_mountp;
struct xfs_buf *bp;
uint qtype = xfs_dquot_type(dqp);
xfs_dqtype_t qtype = xfs_dquot_type(dqp);
struct xfs_inode *quotip = xfs_quota_inode(mp, qtype);
int nmaps = 1;
int error;
Expand Down Expand Up @@ -365,7 +365,7 @@ xfs_dquot_disk_read(
{
struct xfs_bmbt_irec map;
struct xfs_buf *bp;
uint qtype = xfs_dquot_type(dqp);
xfs_dqtype_t qtype = xfs_dquot_type(dqp);
struct xfs_inode *quotip = xfs_quota_inode(mp, qtype);
uint lock_mode;
int nmaps = 1;
Expand Down Expand Up @@ -424,13 +424,13 @@ STATIC struct xfs_dquot *
xfs_dquot_alloc(
struct xfs_mount *mp,
xfs_dqid_t id,
uint type)
xfs_dqtype_t type)
{
struct xfs_dquot *dqp;

dqp = kmem_zone_zalloc(xfs_qm_dqzone, 0);

dqp->dq_flags = type;
dqp->q_type = type;
dqp->q_id = id;
dqp->q_mount = mp;
INIT_LIST_HEAD(&dqp->q_lru);
Expand Down Expand Up @@ -498,6 +498,7 @@ xfs_dquot_from_disk(
}

/* copy everything from disk dquot to the incore dquot */
dqp->q_type = ddqp->d_flags;
dqp->q_blk.hardlimit = be64_to_cpu(ddqp->d_blk_hardlimit);
dqp->q_blk.softlimit = be64_to_cpu(ddqp->d_blk_softlimit);
dqp->q_ino.hardlimit = be64_to_cpu(ddqp->d_ino_hardlimit);
Expand Down Expand Up @@ -538,7 +539,7 @@ xfs_dquot_to_disk(
{
ddqp->d_magic = cpu_to_be16(XFS_DQUOT_MAGIC);
ddqp->d_version = XFS_DQUOT_VERSION;
ddqp->d_flags = dqp->dq_flags & XFS_DQTYPE_REC_MASK;
ddqp->d_flags = dqp->q_type;
ddqp->d_id = cpu_to_be32(dqp->q_id);
ddqp->d_pad0 = 0;
ddqp->d_pad = 0;
Expand Down Expand Up @@ -609,7 +610,7 @@ static int
xfs_qm_dqread(
struct xfs_mount *mp,
xfs_dqid_t id,
uint type,
xfs_dqtype_t type,
bool can_alloc,
struct xfs_dquot **dqpp)
{
Expand Down Expand Up @@ -657,7 +658,7 @@ xfs_qm_dqread(
static int
xfs_dq_get_next_id(
struct xfs_mount *mp,
uint type,
xfs_dqtype_t type,
xfs_dqid_t *id)
{
struct xfs_inode *quotip = xfs_quota_inode(mp, type);
Expand Down Expand Up @@ -781,7 +782,7 @@ xfs_qm_dqget_cache_insert(
static int
xfs_qm_dqget_checks(
struct xfs_mount *mp,
uint type)
xfs_dqtype_t type)
{
if (WARN_ON_ONCE(!XFS_IS_QUOTA_RUNNING(mp)))
return -ESRCH;
Expand Down Expand Up @@ -813,7 +814,7 @@ int
xfs_qm_dqget(
struct xfs_mount *mp,
xfs_dqid_t id,
uint type,
xfs_dqtype_t type,
bool can_alloc,
struct xfs_dquot **O_dqpp)
{
Expand Down Expand Up @@ -863,7 +864,7 @@ int
xfs_qm_dqget_uncached(
struct xfs_mount *mp,
xfs_dqid_t id,
uint type,
xfs_dqtype_t type,
struct xfs_dquot **dqpp)
{
int error;
Expand All @@ -879,7 +880,7 @@ xfs_qm_dqget_uncached(
xfs_dqid_t
xfs_qm_id_for_quotatype(
struct xfs_inode *ip,
uint type)
xfs_dqtype_t type)
{
switch (type) {
case XFS_DQTYPE_USER:
Expand All @@ -901,7 +902,7 @@ xfs_qm_id_for_quotatype(
int
xfs_qm_dqget_inode(
struct xfs_inode *ip,
uint type,
xfs_dqtype_t type,
bool can_alloc,
struct xfs_dquot **O_dqpp)
{
Expand Down Expand Up @@ -987,7 +988,7 @@ int
xfs_qm_dqget_next(
struct xfs_mount *mp,
xfs_dqid_t id,
uint type,
xfs_dqtype_t type,
struct xfs_dquot **dqpp)
{
struct xfs_dquot *dqp;
Expand Down Expand Up @@ -1122,7 +1123,7 @@ static xfs_failaddr_t
xfs_qm_dqflush_check(
struct xfs_dquot *dqp)
{
__u8 type = dqp->dq_flags & XFS_DQTYPE_REC_MASK;
xfs_dqtype_t type = xfs_dquot_type(dqp);

if (type != XFS_DQTYPE_USER &&
type != XFS_DQTYPE_GROUP &&
Expand Down Expand Up @@ -1317,7 +1318,7 @@ xfs_qm_exit(void)
int
xfs_qm_dqiterate(
struct xfs_mount *mp,
uint dqtype,
xfs_dqtype_t type,
xfs_qm_dqiterate_fn iter_fn,
void *priv)
{
Expand All @@ -1326,13 +1327,13 @@ xfs_qm_dqiterate(
int error;

do {
error = xfs_qm_dqget_next(mp, id, dqtype, &dq);
error = xfs_qm_dqget_next(mp, id, type, &dq);
if (error == -ENOENT)
return 0;
if (error)
return error;

error = iter_fn(dq, dqtype, priv);
error = iter_fn(dq, type, priv);
id = dq->q_id;
xfs_qm_dqput(dq);
} while (error == 0 && id != 0);
Expand Down
33 changes: 17 additions & 16 deletions fs/xfs/xfs_dquot.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct xfs_dquot_res {
struct xfs_dquot {
struct list_head q_lru;
struct xfs_mount *q_mount;
uint8_t dq_flags;
xfs_dqtype_t q_type;
uint16_t q_flags;
xfs_dqid_t q_id;
uint q_nrefs;
Expand Down Expand Up @@ -131,10 +131,10 @@ static inline void xfs_dqunlock(struct xfs_dquot *dqp)
static inline int
xfs_dquot_type(const struct xfs_dquot *dqp)
{
return dqp->dq_flags & XFS_DQTYPE_REC_MASK;
return dqp->q_type & XFS_DQTYPE_REC_MASK;
}

static inline int xfs_this_quota_on(struct xfs_mount *mp, int type)
static inline int xfs_this_quota_on(struct xfs_mount *mp, xfs_dqtype_t type)
{
switch (type) {
case XFS_DQTYPE_USER:
Expand All @@ -148,7 +148,9 @@ static inline int xfs_this_quota_on(struct xfs_mount *mp, int type)
}
}

static inline struct xfs_dquot *xfs_inode_dquot(struct xfs_inode *ip, int type)
static inline struct xfs_dquot *xfs_inode_dquot(
struct xfs_inode *ip,
xfs_dqtype_t type)
{
switch (type) {
case XFS_DQTYPE_USER:
Expand Down Expand Up @@ -205,18 +207,17 @@ void xfs_qm_dqunpin_wait(struct xfs_dquot *dqp);
void xfs_qm_adjust_dqtimers(struct xfs_dquot *d);
void xfs_qm_adjust_dqlimits(struct xfs_dquot *d);
xfs_dqid_t xfs_qm_id_for_quotatype(struct xfs_inode *ip,
uint type);
xfs_dqtype_t type);
int xfs_qm_dqget(struct xfs_mount *mp, xfs_dqid_t id,
uint type, bool can_alloc,
struct xfs_dquot **dqpp);
int xfs_qm_dqget_inode(struct xfs_inode *ip, uint type,
bool can_alloc,
struct xfs_dquot **dqpp);
xfs_dqtype_t type, bool can_alloc,
struct xfs_dquot **dqpp);
int xfs_qm_dqget_inode(struct xfs_inode *ip, xfs_dqtype_t type,
bool can_alloc, struct xfs_dquot **dqpp);
int xfs_qm_dqget_next(struct xfs_mount *mp, xfs_dqid_t id,
uint type, struct xfs_dquot **dqpp);
xfs_dqtype_t type, struct xfs_dquot **dqpp);
int xfs_qm_dqget_uncached(struct xfs_mount *mp,
xfs_dqid_t id, uint type,
struct xfs_dquot **dqpp);
xfs_dqid_t id, xfs_dqtype_t type,
struct xfs_dquot **dqpp);
void xfs_qm_dqput(struct xfs_dquot *dqp);

void xfs_dqlock2(struct xfs_dquot *, struct xfs_dquot *);
Expand All @@ -231,9 +232,9 @@ static inline struct xfs_dquot *xfs_qm_dqhold(struct xfs_dquot *dqp)
return dqp;
}

typedef int (*xfs_qm_dqiterate_fn)(struct xfs_dquot *dq, uint dqtype,
void *priv);
int xfs_qm_dqiterate(struct xfs_mount *mp, uint dqtype,
typedef int (*xfs_qm_dqiterate_fn)(struct xfs_dquot *dq,
xfs_dqtype_t type, void *priv);
int xfs_qm_dqiterate(struct xfs_mount *mp, xfs_dqtype_t type,
xfs_qm_dqiterate_fn iter_fn, void *priv);

#endif /* __XFS_DQUOT_H__ */
Loading

0 comments on commit 1a7ed27

Please sign in to comment.