1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-02-04 17:15:50 +00:00

- Add support for referencing quota structures without needing the inode

pointer for softupdates.

Submitted by:	mckusick
This commit is contained in:
Jeff Roberson 2011-06-10 22:19:44 +00:00
parent 5aa336ed20
commit e84fa3ba71
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=222955
2 changed files with 101 additions and 0 deletions

View File

@ -239,6 +239,12 @@ int setuse(struct thread *, struct mount *, u_long, int, void *);
int getquotasize(struct thread *, struct mount *, u_long, int, void *);
vfs_quotactl_t ufs_quotactl;
#ifdef SOFTUPDATES
int quotaref(struct vnode *, struct dquot **);
void quotarele(struct dquot **);
void quotaadj(struct dquot **, struct ufsmount *, int64_t);
#endif /* SOFTUPDATES */
#else /* !_KERNEL */
#include <sys/cdefs.h>

View File

@ -1612,6 +1612,101 @@ dqflush(struct vnode *vp)
DQH_UNLOCK();
}
/*
* The following three functions are provided for the adjustment of
* quotas by the soft updates code.
*/
#ifdef SOFTUPDATES
/*
* Acquire a reference to the quota structures associated with a vnode.
* Return count of number of quota structures found.
*/
int
quotaref(vp, qrp)
struct vnode *vp;
struct dquot **qrp;
{
struct inode *ip;
struct dquot *dq;
int i, found;
for (i = 0; i < MAXQUOTAS; i++)
qrp[i] = NODQUOT;
/*
* Disk quotas must be turned off for system files. Currently
* snapshot and quota files.
*/
if ((vp->v_vflag & VV_SYSTEM) != 0)
return (0);
/*
* Iterate through and copy active quotas.
*/
found = 0;
ip = VTOI(vp);
for (i = 0; i < MAXQUOTAS; i++) {
if ((dq = ip->i_dquot[i]) == NODQUOT)
continue;
DQREF(dq);
qrp[i] = dq;
found++;
}
return (found);
}
/*
* Release a set of quota structures obtained from a vnode.
*/
void
quotarele(qrp)
struct dquot **qrp;
{
struct dquot *dq;
int i;
for (i = 0; i < MAXQUOTAS; i++) {
if ((dq = qrp[i]) == NODQUOT)
continue;
dqrele(NULL, dq);
}
}
/*
* Adjust the number of blocks associated with a quota.
* Positive numbers when adding blocks; negative numbers when freeing blocks.
*/
void
quotaadj(qrp, ump, blkcount)
struct dquot **qrp;
struct ufsmount *ump;
int64_t blkcount;
{
struct dquot *dq;
ufs2_daddr_t ncurblocks;
int i;
if (blkcount == 0)
return;
for (i = 0; i < MAXQUOTAS; i++) {
if ((dq = qrp[i]) == NODQUOT)
continue;
DQI_LOCK(dq);
DQI_WAIT(dq, PINOD+1, "adjqta");
ncurblocks = dq->dq_curblocks + blkcount;
if (ncurblocks >= 0)
dq->dq_curblocks = ncurblocks;
else
dq->dq_curblocks = 0;
if (blkcount < 0)
dq->dq_flags &= ~DQ_BLKS;
else if (dq->dq_curblocks + blkcount >= dq->dq_bsoftlimit &&
dq->dq_curblocks < dq->dq_bsoftlimit)
dq->dq_btime = time_second + ump->um_btime[i];
dq->dq_flags |= DQ_MOD;
DQI_UNLOCK(dq);
}
}
#endif /* SOFTUPDATES */
/*
* 32-bit / 64-bit conversion functions.
*