[14/18] xfs: refactor quota exceeded test
diff mbox series

Message ID 159353180004.2864738.3571543752803090361.stgit@magnolia
State Superseded
Headers show
Series
  • xfs: remove xfs_disk_quot from incore dquot
Related show

Commit Message

Darrick J. Wong June 30, 2020, 3:43 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Refactor the open-coded test for whether or not we're over quota.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_dquot.c |   95 ++++++++++++++++------------------------------------
 1 file changed, 30 insertions(+), 65 deletions(-)

Comments

hch@infradead.org July 1, 2020, 8:56 a.m. UTC | #1
On Tue, Jun 30, 2020 at 08:43:20AM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Refactor the open-coded test for whether or not we're over quota.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/xfs_dquot.c |   95 ++++++++++++++++------------------------------------
>  1 file changed, 30 insertions(+), 65 deletions(-)
> 
> 
> diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
> index 35a113d1b42b..ef34c82c28a0 100644
> --- a/fs/xfs/xfs_dquot.c
> +++ b/fs/xfs/xfs_dquot.c
> @@ -97,6 +97,33 @@ xfs_qm_adjust_dqlimits(
>  		xfs_dquot_set_prealloc_limits(dq);
>  }
>  
> +/*
> + * Determine if this quota counter is over either limit and set the quota
> + * timers as appropriate.
> + */
> +static inline void
> +xfs_qm_adjust_res_timer(
> +	struct xfs_dquot_res	*res,
> +	struct xfs_def_qres	*dres)
> +{
> +	bool			over;
> +
> +#ifdef DEBUG
> +	if (res->hardlimit)
> +		ASSERT(res->softlimit <= res->hardlimit);
> +#endif

Maybe:
	ASSERRT(!res->hardlimit || res->softlimit <= res->hardlimit);

> +
> +	over = (res->softlimit && res->count > res->softlimit) ||
> +	       (res->hardlimit && res->count > res->hardlimit);
> +
> +	if (over && res->timer == 0)
> +		res->timer = ktime_get_real_seconds() + dres->timelimit;
> +	else if (!over && res->timer != 0)
> +		res->timer = 0;
> +	else if (!over && res->timer == 0)
> +		res->warnings = 0;

What about:

	if ((res->softlimit && res->count > res->softlimit) ||
	    (res->hardlimit && res->count > res->hardlimit)) {
		if (res->timer == 0)	
			res->timer = ktime_get_real_seconds() + dres->timelimit;
	} else {
		if (res->timer)
			res->timer = 0;
		else
			res->warnings = 0;
	}
Chandan Babu R July 1, 2020, 10:19 a.m. UTC | #2
On Tuesday 30 June 2020 9:13:20 PM IST Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Refactor the open-coded test for whether or not we're over quota.
>

The changes look good to me.

Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>

> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/xfs_dquot.c |   95 ++++++++++++++++------------------------------------
>  1 file changed, 30 insertions(+), 65 deletions(-)
> 
> 
> diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
> index 35a113d1b42b..ef34c82c28a0 100644
> --- a/fs/xfs/xfs_dquot.c
> +++ b/fs/xfs/xfs_dquot.c
> @@ -97,6 +97,33 @@ xfs_qm_adjust_dqlimits(
>  		xfs_dquot_set_prealloc_limits(dq);
>  }
>  
> +/*
> + * Determine if this quota counter is over either limit and set the quota
> + * timers as appropriate.
> + */
> +static inline void
> +xfs_qm_adjust_res_timer(
> +	struct xfs_dquot_res	*res,
> +	struct xfs_def_qres	*dres)
> +{
> +	bool			over;
> +
> +#ifdef DEBUG
> +	if (res->hardlimit)
> +		ASSERT(res->softlimit <= res->hardlimit);
> +#endif
> +
> +	over = (res->softlimit && res->count > res->softlimit) ||
> +	       (res->hardlimit && res->count > res->hardlimit);
> +
> +	if (over && res->timer == 0)
> +		res->timer = ktime_get_real_seconds() + dres->timelimit;
> +	else if (!over && res->timer != 0)
> +		res->timer = 0;
> +	else if (!over && res->timer == 0)
> +		res->warnings = 0;
> +}
> +
>  /*
>   * Check the limits and timers of a dquot and start or reset timers
>   * if necessary.
> @@ -121,71 +148,9 @@ xfs_qm_adjust_dqtimers(
>  	ASSERT(dq->q_id);
>  	defq = xfs_get_defquota(qi, xfs_dquot_type(dq));
>  
> -#ifdef DEBUG
> -	if (dq->q_blk.hardlimit)
> -		ASSERT(dq->q_blk.softlimit <= dq->q_blk.hardlimit);
> -	if (dq->q_ino.hardlimit)
> -		ASSERT(dq->q_ino.softlimit <= dq->q_ino.hardlimit);
> -	if (dq->q_rtb.hardlimit)
> -		ASSERT(dq->q_rtb.softlimit <= dq->q_rtb.hardlimit);
> -#endif
> -
> -	if (!dq->q_blk.timer) {
> -		if ((dq->q_blk.softlimit &&
> -		     (dq->q_blk.count > dq->q_blk.softlimit)) ||
> -		    (dq->q_blk.hardlimit &&
> -		     (dq->q_blk.count > dq->q_blk.hardlimit))) {
> -			dq->q_blk.timer = ktime_get_real_seconds() +
> -					defq->dfq_blk.timelimit;
> -		} else {
> -			dq->q_blk.warnings = 0;
> -		}
> -	} else {
> -		if ((!dq->q_blk.softlimit ||
> -		     (dq->q_blk.count <= dq->q_blk.softlimit)) &&
> -		    (!dq->q_blk.hardlimit ||
> -		    (dq->q_blk.count <= dq->q_blk.hardlimit))) {
> -			dq->q_blk.timer = 0;
> -		}
> -	}
> -
> -	if (!dq->q_ino.timer) {
> -		if ((dq->q_ino.softlimit &&
> -		     (dq->q_ino.count > dq->q_ino.softlimit)) ||
> -		    (dq->q_ino.hardlimit &&
> -		     (dq->q_ino.count > dq->q_ino.hardlimit))) {
> -			dq->q_ino.timer = ktime_get_real_seconds() +
> -					defq->dfq_ino.timelimit;
> -		} else {
> -			dq->q_ino.warnings = 0;
> -		}
> -	} else {
> -		if ((!dq->q_ino.softlimit ||
> -		     (dq->q_ino.count <= dq->q_ino.softlimit))  &&
> -		    (!dq->q_ino.hardlimit ||
> -		     (dq->q_ino.count <= dq->q_ino.hardlimit))) {
> -			dq->q_ino.timer = 0;
> -		}
> -	}
> -
> -	if (!dq->q_rtb.timer) {
> -		if ((dq->q_rtb.softlimit &&
> -		     (dq->q_rtb.count > dq->q_rtb.softlimit)) ||
> -		    (dq->q_rtb.hardlimit &&
> -		     (dq->q_rtb.count > dq->q_rtb.hardlimit))) {
> -			dq->q_rtb.timer = ktime_get_real_seconds() +
> -					defq->dfq_rtb.timelimit;
> -		} else {
> -			dq->q_rtb.warnings = 0;
> -		}
> -	} else {
> -		if ((!dq->q_rtb.softlimit ||
> -		     (dq->q_rtb.count <= dq->q_rtb.softlimit)) &&
> -		    (!dq->q_rtb.hardlimit ||
> -		     (dq->q_rtb.count <= dq->q_rtb.hardlimit))) {
> -			dq->q_rtb.timer = 0;
> -		}
> -	}
> +	xfs_qm_adjust_res_timer(&dq->q_blk, &defq->dfq_blk);
> +	xfs_qm_adjust_res_timer(&dq->q_ino, &defq->dfq_ino);
> +	xfs_qm_adjust_res_timer(&dq->q_rtb, &defq->dfq_rtb);
>  }
>  
>  /*
> 
>
Darrick J. Wong July 1, 2020, 5:51 p.m. UTC | #3
On Wed, Jul 01, 2020 at 09:56:21AM +0100, Christoph Hellwig wrote:
> On Tue, Jun 30, 2020 at 08:43:20AM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Refactor the open-coded test for whether or not we're over quota.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  fs/xfs/xfs_dquot.c |   95 ++++++++++++++++------------------------------------
> >  1 file changed, 30 insertions(+), 65 deletions(-)
> > 
> > 
> > diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
> > index 35a113d1b42b..ef34c82c28a0 100644
> > --- a/fs/xfs/xfs_dquot.c
> > +++ b/fs/xfs/xfs_dquot.c
> > @@ -97,6 +97,33 @@ xfs_qm_adjust_dqlimits(
> >  		xfs_dquot_set_prealloc_limits(dq);
> >  }
> >  
> > +/*
> > + * Determine if this quota counter is over either limit and set the quota
> > + * timers as appropriate.
> > + */
> > +static inline void
> > +xfs_qm_adjust_res_timer(
> > +	struct xfs_dquot_res	*res,
> > +	struct xfs_def_qres	*dres)
> > +{
> > +	bool			over;
> > +
> > +#ifdef DEBUG
> > +	if (res->hardlimit)
> > +		ASSERT(res->softlimit <= res->hardlimit);
> > +#endif
> 
> Maybe:
> 	ASSERRT(!res->hardlimit || res->softlimit <= res->hardlimit);

Changed.

> 
> > +
> > +	over = (res->softlimit && res->count > res->softlimit) ||
> > +	       (res->hardlimit && res->count > res->hardlimit);
> > +
> > +	if (over && res->timer == 0)
> > +		res->timer = ktime_get_real_seconds() + dres->timelimit;
> > +	else if (!over && res->timer != 0)
> > +		res->timer = 0;
> > +	else if (!over && res->timer == 0)
> > +		res->warnings = 0;
> 
> What about:
> 
> 	if ((res->softlimit && res->count > res->softlimit) ||
> 	    (res->hardlimit && res->count > res->hardlimit)) {
> 		if (res->timer == 0)	
> 			res->timer = ktime_get_real_seconds() + dres->timelimit;
> 	} else {
> 		if (res->timer)
> 			res->timer = 0;
> 		else
> 			res->warnings = 0;
> 	}

I don't care either way, but the last time I sent this patch out, Eric
and Amir seemed to want a flatter if structure:

https://lore.kernel.org/linux-xfs/b979d33d-361b-88cd-699c-7e5f1c621698@sandeen.net/
https://lore.kernel.org/linux-xfs/CAOQ4uxiveTQu8_7UOvN07=P4o9hBBZTCyu4sSw5UpbrNPQL2pQ@mail.gmail.com/

Granted that was before I pulled the whole thing into a separate helper
function, so maybe the context is different here...?

--D
Eric Sandeen July 1, 2020, 6:48 p.m. UTC | #4
On 7/1/20 12:51 PM, Darrick J. Wong wrote:
> On Wed, Jul 01, 2020 at 09:56:21AM +0100, Christoph Hellwig wrote:
>> On Tue, Jun 30, 2020 at 08:43:20AM -0700, Darrick J. Wong wrote:
>>> From: Darrick J. Wong <darrick.wong@oracle.com>
>>>
>>> Refactor the open-coded test for whether or not we're over quota.
>>>
>>> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
>>> ---
>>>  fs/xfs/xfs_dquot.c |   95 ++++++++++++++++------------------------------------
>>>  1 file changed, 30 insertions(+), 65 deletions(-)
>>>
>>>
>>> diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
>>> index 35a113d1b42b..ef34c82c28a0 100644
>>> --- a/fs/xfs/xfs_dquot.c
>>> +++ b/fs/xfs/xfs_dquot.c
>>> @@ -97,6 +97,33 @@ xfs_qm_adjust_dqlimits(
>>>  		xfs_dquot_set_prealloc_limits(dq);
>>>  }
>>>  
>>> +/*
>>> + * Determine if this quota counter is over either limit and set the quota
>>> + * timers as appropriate.
>>> + */
>>> +static inline void
>>> +xfs_qm_adjust_res_timer(
>>> +	struct xfs_dquot_res	*res,
>>> +	struct xfs_def_qres	*dres)
>>> +{
>>> +	bool			over;
>>> +
>>> +#ifdef DEBUG
>>> +	if (res->hardlimit)
>>> +		ASSERT(res->softlimit <= res->hardlimit);
>>> +#endif
>>
>> Maybe:
>> 	ASSERRT(!res->hardlimit || res->softlimit <= res->hardlimit);
> 
> Changed.
> 
>>
>>> +
>>> +	over = (res->softlimit && res->count > res->softlimit) ||
>>> +	       (res->hardlimit && res->count > res->hardlimit);
>>> +
>>> +	if (over && res->timer == 0)
>>> +		res->timer = ktime_get_real_seconds() + dres->timelimit;
>>> +	else if (!over && res->timer != 0)
>>> +		res->timer = 0;
>>> +	else if (!over && res->timer == 0)
>>> +		res->warnings = 0;
>>
>> What about:
>>
>> 	if ((res->softlimit && res->count > res->softlimit) ||
>> 	    (res->hardlimit && res->count > res->hardlimit)) {
>> 		if (res->timer == 0)	
>> 			res->timer = ktime_get_real_seconds() + dres->timelimit;
>> 	} else {
>> 		if (res->timer)
>> 			res->timer = 0;
>> 		else
>> 			res->warnings = 0;
>> 	}
> 
> I don't care either way, but the last time I sent this patch out, Eric
> and Amir seemed to want a flatter if structure:
> 
> https://lore.kernel.org/linux-xfs/b979d33d-361b-88cd-699c-7e5f1c621698@sandeen.net/
> https://lore.kernel.org/linux-xfs/CAOQ4uxiveTQu8_7UOvN07=P4o9hBBZTCyu4sSw5UpbrNPQL2pQ@mail.gmail.com/
> 
> Granted that was before I pulled the whole thing into a separate helper
> function, so maybe the context is different here...?

I think it is different.  I'm not too hung up about either way and
can't promise to dedicate time to thinking about it soon, so -
as you wish.  :)

-Eric
Dave Chinner July 1, 2020, 11:34 p.m. UTC | #5
On Wed, Jul 01, 2020 at 10:51:34AM -0700, Darrick J. Wong wrote:
> On Wed, Jul 01, 2020 at 09:56:21AM +0100, Christoph Hellwig wrote:
> > On Tue, Jun 30, 2020 at 08:43:20AM -0700, Darrick J. Wong wrote:
> > > From: Darrick J. Wong <darrick.wong@oracle.com>
> > > 
> > > Refactor the open-coded test for whether or not we're over quota.
> > > 
> > > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > > ---
> > >  fs/xfs/xfs_dquot.c |   95 ++++++++++++++++------------------------------------
> > >  1 file changed, 30 insertions(+), 65 deletions(-)
> > > 
> > > 
> > > diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
> > > index 35a113d1b42b..ef34c82c28a0 100644
> > > --- a/fs/xfs/xfs_dquot.c
> > > +++ b/fs/xfs/xfs_dquot.c
> > > @@ -97,6 +97,33 @@ xfs_qm_adjust_dqlimits(
> > >  		xfs_dquot_set_prealloc_limits(dq);
> > >  }
> > >  
> > > +/*
> > > + * Determine if this quota counter is over either limit and set the quota
> > > + * timers as appropriate.
> > > + */
> > > +static inline void
> > > +xfs_qm_adjust_res_timer(
> > > +	struct xfs_dquot_res	*res,
> > > +	struct xfs_def_qres	*dres)
> > > +{
> > > +	bool			over;
> > > +
> > > +#ifdef DEBUG
> > > +	if (res->hardlimit)
> > > +		ASSERT(res->softlimit <= res->hardlimit);
> > > +#endif
> > 
> > Maybe:
> > 	ASSERRT(!res->hardlimit || res->softlimit <= res->hardlimit);
> 
> Changed.
> 
> > 
> > > +
> > > +	over = (res->softlimit && res->count > res->softlimit) ||
> > > +	       (res->hardlimit && res->count > res->hardlimit);
> > > +
> > > +	if (over && res->timer == 0)
> > > +		res->timer = ktime_get_real_seconds() + dres->timelimit;
> > > +	else if (!over && res->timer != 0)
> > > +		res->timer = 0;
> > > +	else if (!over && res->timer == 0)
> > > +		res->warnings = 0;
> > 
> > What about:
> > 
> > 	if ((res->softlimit && res->count > res->softlimit) ||
> > 	    (res->hardlimit && res->count > res->hardlimit)) {
> > 		if (res->timer == 0)	
> > 			res->timer = ktime_get_real_seconds() + dres->timelimit;
> > 	} else {
> > 		if (res->timer)
> > 			res->timer = 0;
> > 		else
> > 			res->warnings = 0;
> > 	}
> 
> I don't care either way, but the last time I sent this patch out, Eric
> and Amir seemed to want a flatter if structure:

I much prefer Christoph's version - I was going to suggest the same
sort of thing myself as the "flatter" version just looks needlessly
convoluted to me.

Cheers,

Dave.
Allison Collins July 2, 2020, 6:57 p.m. UTC | #6
On 6/30/20 8:43 AM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Refactor the open-coded test for whether or not we're over quota.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Ok, the changes look correct.  I do not have a preference on the if/else 
logic mentioned in some of the other reviews.  At first glance they both 
require a bit of a pause, but I didn't find either to be too unsightly 
to read through.  I am amicable to either solution folks prefer.

Reviewed-by: Allison Collins <allison.henderson@oracle.com>
> ---
>   fs/xfs/xfs_dquot.c |   95 ++++++++++++++++------------------------------------
>   1 file changed, 30 insertions(+), 65 deletions(-)
> 
> 
> diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
> index 35a113d1b42b..ef34c82c28a0 100644
> --- a/fs/xfs/xfs_dquot.c
> +++ b/fs/xfs/xfs_dquot.c
> @@ -97,6 +97,33 @@ xfs_qm_adjust_dqlimits(
>   		xfs_dquot_set_prealloc_limits(dq);
>   }
>   
> +/*
> + * Determine if this quota counter is over either limit and set the quota
> + * timers as appropriate.
> + */
> +static inline void
> +xfs_qm_adjust_res_timer(
> +	struct xfs_dquot_res	*res,
> +	struct xfs_def_qres	*dres)
> +{
> +	bool			over;
> +
> +#ifdef DEBUG
> +	if (res->hardlimit)
> +		ASSERT(res->softlimit <= res->hardlimit);
> +#endif
> +
> +	over = (res->softlimit && res->count > res->softlimit) ||
> +	       (res->hardlimit && res->count > res->hardlimit);
> +
> +	if (over && res->timer == 0)
> +		res->timer = ktime_get_real_seconds() + dres->timelimit;
> +	else if (!over && res->timer != 0)
> +		res->timer = 0;
> +	else if (!over && res->timer == 0)
> +		res->warnings = 0;
> +}
> +
>   /*
>    * Check the limits and timers of a dquot and start or reset timers
>    * if necessary.
> @@ -121,71 +148,9 @@ xfs_qm_adjust_dqtimers(
>   	ASSERT(dq->q_id);
>   	defq = xfs_get_defquota(qi, xfs_dquot_type(dq));
>   
> -#ifdef DEBUG
> -	if (dq->q_blk.hardlimit)
> -		ASSERT(dq->q_blk.softlimit <= dq->q_blk.hardlimit);
> -	if (dq->q_ino.hardlimit)
> -		ASSERT(dq->q_ino.softlimit <= dq->q_ino.hardlimit);
> -	if (dq->q_rtb.hardlimit)
> -		ASSERT(dq->q_rtb.softlimit <= dq->q_rtb.hardlimit);
> -#endif
> -
> -	if (!dq->q_blk.timer) {
> -		if ((dq->q_blk.softlimit &&
> -		     (dq->q_blk.count > dq->q_blk.softlimit)) ||
> -		    (dq->q_blk.hardlimit &&
> -		     (dq->q_blk.count > dq->q_blk.hardlimit))) {
> -			dq->q_blk.timer = ktime_get_real_seconds() +
> -					defq->dfq_blk.timelimit;
> -		} else {
> -			dq->q_blk.warnings = 0;
> -		}
> -	} else {
> -		if ((!dq->q_blk.softlimit ||
> -		     (dq->q_blk.count <= dq->q_blk.softlimit)) &&
> -		    (!dq->q_blk.hardlimit ||
> -		    (dq->q_blk.count <= dq->q_blk.hardlimit))) {
> -			dq->q_blk.timer = 0;
> -		}
> -	}
> -
> -	if (!dq->q_ino.timer) {
> -		if ((dq->q_ino.softlimit &&
> -		     (dq->q_ino.count > dq->q_ino.softlimit)) ||
> -		    (dq->q_ino.hardlimit &&
> -		     (dq->q_ino.count > dq->q_ino.hardlimit))) {
> -			dq->q_ino.timer = ktime_get_real_seconds() +
> -					defq->dfq_ino.timelimit;
> -		} else {
> -			dq->q_ino.warnings = 0;
> -		}
> -	} else {
> -		if ((!dq->q_ino.softlimit ||
> -		     (dq->q_ino.count <= dq->q_ino.softlimit))  &&
> -		    (!dq->q_ino.hardlimit ||
> -		     (dq->q_ino.count <= dq->q_ino.hardlimit))) {
> -			dq->q_ino.timer = 0;
> -		}
> -	}
> -
> -	if (!dq->q_rtb.timer) {
> -		if ((dq->q_rtb.softlimit &&
> -		     (dq->q_rtb.count > dq->q_rtb.softlimit)) ||
> -		    (dq->q_rtb.hardlimit &&
> -		     (dq->q_rtb.count > dq->q_rtb.hardlimit))) {
> -			dq->q_rtb.timer = ktime_get_real_seconds() +
> -					defq->dfq_rtb.timelimit;
> -		} else {
> -			dq->q_rtb.warnings = 0;
> -		}
> -	} else {
> -		if ((!dq->q_rtb.softlimit ||
> -		     (dq->q_rtb.count <= dq->q_rtb.softlimit)) &&
> -		    (!dq->q_rtb.hardlimit ||
> -		     (dq->q_rtb.count <= dq->q_rtb.hardlimit))) {
> -			dq->q_rtb.timer = 0;
> -		}
> -	}
> +	xfs_qm_adjust_res_timer(&dq->q_blk, &defq->dfq_blk);
> +	xfs_qm_adjust_res_timer(&dq->q_ino, &defq->dfq_ino);
> +	xfs_qm_adjust_res_timer(&dq->q_rtb, &defq->dfq_rtb);
>   }
>   
>   /*
>

Patch
diff mbox series

diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
index 35a113d1b42b..ef34c82c28a0 100644
--- a/fs/xfs/xfs_dquot.c
+++ b/fs/xfs/xfs_dquot.c
@@ -97,6 +97,33 @@  xfs_qm_adjust_dqlimits(
 		xfs_dquot_set_prealloc_limits(dq);
 }
 
+/*
+ * Determine if this quota counter is over either limit and set the quota
+ * timers as appropriate.
+ */
+static inline void
+xfs_qm_adjust_res_timer(
+	struct xfs_dquot_res	*res,
+	struct xfs_def_qres	*dres)
+{
+	bool			over;
+
+#ifdef DEBUG
+	if (res->hardlimit)
+		ASSERT(res->softlimit <= res->hardlimit);
+#endif
+
+	over = (res->softlimit && res->count > res->softlimit) ||
+	       (res->hardlimit && res->count > res->hardlimit);
+
+	if (over && res->timer == 0)
+		res->timer = ktime_get_real_seconds() + dres->timelimit;
+	else if (!over && res->timer != 0)
+		res->timer = 0;
+	else if (!over && res->timer == 0)
+		res->warnings = 0;
+}
+
 /*
  * Check the limits and timers of a dquot and start or reset timers
  * if necessary.
@@ -121,71 +148,9 @@  xfs_qm_adjust_dqtimers(
 	ASSERT(dq->q_id);
 	defq = xfs_get_defquota(qi, xfs_dquot_type(dq));
 
-#ifdef DEBUG
-	if (dq->q_blk.hardlimit)
-		ASSERT(dq->q_blk.softlimit <= dq->q_blk.hardlimit);
-	if (dq->q_ino.hardlimit)
-		ASSERT(dq->q_ino.softlimit <= dq->q_ino.hardlimit);
-	if (dq->q_rtb.hardlimit)
-		ASSERT(dq->q_rtb.softlimit <= dq->q_rtb.hardlimit);
-#endif
-
-	if (!dq->q_blk.timer) {
-		if ((dq->q_blk.softlimit &&
-		     (dq->q_blk.count > dq->q_blk.softlimit)) ||
-		    (dq->q_blk.hardlimit &&
-		     (dq->q_blk.count > dq->q_blk.hardlimit))) {
-			dq->q_blk.timer = ktime_get_real_seconds() +
-					defq->dfq_blk.timelimit;
-		} else {
-			dq->q_blk.warnings = 0;
-		}
-	} else {
-		if ((!dq->q_blk.softlimit ||
-		     (dq->q_blk.count <= dq->q_blk.softlimit)) &&
-		    (!dq->q_blk.hardlimit ||
-		    (dq->q_blk.count <= dq->q_blk.hardlimit))) {
-			dq->q_blk.timer = 0;
-		}
-	}
-
-	if (!dq->q_ino.timer) {
-		if ((dq->q_ino.softlimit &&
-		     (dq->q_ino.count > dq->q_ino.softlimit)) ||
-		    (dq->q_ino.hardlimit &&
-		     (dq->q_ino.count > dq->q_ino.hardlimit))) {
-			dq->q_ino.timer = ktime_get_real_seconds() +
-					defq->dfq_ino.timelimit;
-		} else {
-			dq->q_ino.warnings = 0;
-		}
-	} else {
-		if ((!dq->q_ino.softlimit ||
-		     (dq->q_ino.count <= dq->q_ino.softlimit))  &&
-		    (!dq->q_ino.hardlimit ||
-		     (dq->q_ino.count <= dq->q_ino.hardlimit))) {
-			dq->q_ino.timer = 0;
-		}
-	}
-
-	if (!dq->q_rtb.timer) {
-		if ((dq->q_rtb.softlimit &&
-		     (dq->q_rtb.count > dq->q_rtb.softlimit)) ||
-		    (dq->q_rtb.hardlimit &&
-		     (dq->q_rtb.count > dq->q_rtb.hardlimit))) {
-			dq->q_rtb.timer = ktime_get_real_seconds() +
-					defq->dfq_rtb.timelimit;
-		} else {
-			dq->q_rtb.warnings = 0;
-		}
-	} else {
-		if ((!dq->q_rtb.softlimit ||
-		     (dq->q_rtb.count <= dq->q_rtb.softlimit)) &&
-		    (!dq->q_rtb.hardlimit ||
-		     (dq->q_rtb.count <= dq->q_rtb.hardlimit))) {
-			dq->q_rtb.timer = 0;
-		}
-	}
+	xfs_qm_adjust_res_timer(&dq->q_blk, &defq->dfq_blk);
+	xfs_qm_adjust_res_timer(&dq->q_ino, &defq->dfq_ino);
+	xfs_qm_adjust_res_timer(&dq->q_rtb, &defq->dfq_rtb);
 }
 
 /*