2018-06-06 02:42:14 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2005-11-02 03:59:41 +00:00
|
|
|
* Copyright (c) 2000-2002 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
#include "xfs.h"
|
|
|
|
#include "xfs_fs.h"
|
2013-10-22 23:36:05 +00:00
|
|
|
#include "xfs_shared.h"
|
2013-10-22 23:50:10 +00:00
|
|
|
#include "xfs_format.h"
|
|
|
|
#include "xfs_log_format.h"
|
|
|
|
#include "xfs_trans_resv.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "xfs_mount.h"
|
|
|
|
#include "xfs_inode.h"
|
2013-10-22 23:50:10 +00:00
|
|
|
#include "xfs_trans.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "xfs_trans_priv.h"
|
2013-10-22 23:51:50 +00:00
|
|
|
#include "xfs_quota.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "xfs_qm.h"
|
2020-07-14 17:37:35 +00:00
|
|
|
#include "xfs_trace.h"
|
2021-01-29 23:44:32 +00:00
|
|
|
#include "xfs_error.h"
|
2024-02-22 20:30:51 +00:00
|
|
|
#include "xfs_health.h"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
STATIC void xfs_trans_alloc_dqinfo(xfs_trans_t *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the locked dquot to the transaction.
|
|
|
|
* The dquot must be locked, and it cannot be associated with any
|
|
|
|
* transaction.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_dqjoin(
|
2019-11-13 01:04:02 +00:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_dquot *dqp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
ASSERT(XFS_DQ_IS_LOCKED(dqp));
|
2010-06-23 08:11:15 +00:00
|
|
|
ASSERT(dqp->q_logitem.qli_dquot == dqp);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a log_item_desc to point at the new item.
|
|
|
|
*/
|
2010-06-23 08:11:15 +00:00
|
|
|
xfs_trans_add_item(tp, &dqp->q_logitem.qli_item);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called to mark the dquot as needing
|
|
|
|
* to be logged when the transaction is committed. The dquot must
|
|
|
|
* already be associated with the given transaction.
|
|
|
|
* Note that it marks the entire transaction as dirty. In the ordinary
|
|
|
|
* case, this gets called via xfs_trans_commit, after the transaction
|
|
|
|
* is already dirty. However, there's nothing stop this from getting
|
|
|
|
* called directly, as done by xfs_qm_scall_setqlim. Hence, the TRANS_DIRTY
|
|
|
|
* flag.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_log_dquot(
|
2019-11-13 01:04:02 +00:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_dquot *dqp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
ASSERT(XFS_DQ_IS_LOCKED(dqp));
|
|
|
|
|
2020-08-17 16:59:51 +00:00
|
|
|
/* Upgrade the dquot to bigtime format if possible. */
|
|
|
|
if (dqp->q_id != 0 &&
|
2021-08-19 01:46:37 +00:00
|
|
|
xfs_has_bigtime(tp->t_mountp) &&
|
2020-08-17 16:59:51 +00:00
|
|
|
!(dqp->q_type & XFS_DQTYPE_BIGTIME))
|
|
|
|
dqp->q_type |= XFS_DQTYPE_BIGTIME;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
tp->t_flags |= XFS_TRANS_DIRTY;
|
2018-05-09 14:49:37 +00:00
|
|
|
set_bit(XFS_LI_DIRTY, &dqp->q_logitem.qli_item.li_flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Carry forward whatever is left of the quota blk reservation to
|
|
|
|
* the spanky new transaction
|
|
|
|
*/
|
2009-06-08 13:33:32 +00:00
|
|
|
void
|
2005-04-16 22:20:36 +00:00
|
|
|
xfs_trans_dup_dqinfo(
|
2019-04-17 23:30:24 +00:00
|
|
|
struct xfs_trans *otp,
|
|
|
|
struct xfs_trans *ntp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2019-04-17 23:30:24 +00:00
|
|
|
struct xfs_dqtrx *oq, *nq;
|
|
|
|
int i, j;
|
|
|
|
struct xfs_dqtrx *oqa, *nqa;
|
|
|
|
uint64_t blk_res_used;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!otp->t_dqinfo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xfs_trans_alloc_dqinfo(ntp);
|
|
|
|
|
2013-06-27 22:25:09 +00:00
|
|
|
for (j = 0; j < XFS_QM_TRANS_DQTYPES; j++) {
|
|
|
|
oqa = otp->t_dqinfo->dqs[j];
|
|
|
|
nqa = ntp->t_dqinfo->dqs[j];
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) {
|
xfs: fix quota block reservation leak when tp allocates and frees blocks
Al Viro reports that generic/231 fails frequently on XFS and bisected
the problem to the following commit:
5d11fb4b xfs: rework zero range to prevent invalid i_size updates
... which is just the first commit that happens to cause fsx to
reproduce the problem. fsx reproduces via zero range calls. The
aforementioned commit overhauls zero range to use hole punch and
fallocate. As it turns out, the problem is reproducible on demand using
basic hole punch as follows:
$ mkfs.xfs -f -m crc=1,finobt=1 <dev>
$ mount <dev> /mnt -o uquota
$ xfs_io -f -c "falloc 0 50m" /mnt/file
$ for i in $(seq 1 20); do xfs_io -c "fpunch ${i}m 32k" /mnt/file; done
$ rm -f /mnt/file
$ repquota -us /mnt
...
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 32K 0K 0K 3 0 0
A file is allocated with a single 50m extent. The extent count increases
via hole punches until the bmap converts to btree format. The file is
removed but quota reports 32k of space usage for the user. This
reservation is effectively leaked for the lifetime of the mount.
The reason this occurs is because the quota block reservation tracking
is confused when a transaction happens to free and allocate blocks at
the same time. Consider the following sequence of events:
- tp is allocated from xfs_free_file_space() and reserves several blocks
for btree management. Blocks are reserved against the dquot and marked
as such in the transaction (qtrx->qt_blk_res).
- 8 blocks are accounted free when the 32k range is punched out.
xfs_trans_mod_dquot() is called with XFS_TRANS_DQ_BCOUNT and sets
->qt_bcount_delta to -8.
- Subsequently, a block is allocated against the same transaction by
xfs_bmap_extents_to_btree() for btree conversion. A call to
xfs_trans_mod_dquot() increases qt_blk_res_used to 1 and qt_bcount_delta
to -7.
- The transaction is dup'd and committed by xfs_bmap_finish().
xfs_trans_dup_dqinfo() sets the first transaction up such that it has a
matching qt_blk_res and qt_blk_res_used of 1. The remaining unused
reservation is transferred to the duplicate tp.
When the transactions are committed, the dquots are fixed up in
xfs_trans_apply_dquot_deltas() according to one of two methods:
1.) If the transaction holds a block reservation (->qt_blk_res != 0),
_only_ the unused portion reservation is unaccounted from the dquot.
Note that the tp duplication behavior of xfs_bmap_finish() makes it such
that qt_blk_res is typically 0 for tp's with unused reservation.
2.) Otherwise, the dquot is fixed up based on the block delta
(->qt_bcount_delta) created by the transaction.
Therefore, if a transaction has a negative qt_bcount_delta and positive
qt_blk_res_used, the former set of blocks that have been removed from
the file are never factored out of the in-core dquot reservation.
Instead, *_apply_dquot_deltas() sees 1 block used out of a 1 block
reservation and believes there is nothing to fix up. The on-disk
d_bcount is updated independently from qt_bcount_delta, and thus is
correct (and allows the quota usage to correct on remount).
To deal with this situation, we effectively want the "used reservation"
part of the transaction to be consistent with any freed blocks with
respect to quota tracking. For example, if 8 blocks are freed, the
subsequent single block allocation does not need to consume the initial
reservation made by the tp. Instead, it simply borrows one from the
previously freed. One possible implementation of such borrowing is to
avoid the blks_res_used increment when bcount_delta is negative. This
alone is flawed logic in that it only handles the case where blocks are
freed before allocated, however.
Rather than add more complexity to manage synchronization between
bcount_delta and blks_res_used, kill the latter entirely. blk_res_used
is only updated in one place and always in sync with delta_bcount.
Therefore, the net block reservation consumption of the transaction is
always available from bcount_delta. Calculate the reservation
consumption on the fly where necessary based on whether the tp has a
reservation and results in a positive net block delta on the inode.
Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-05-31 21:15:37 +00:00
|
|
|
blk_res_used = 0;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (oqa[i].qt_dquot == NULL)
|
|
|
|
break;
|
|
|
|
oq = &oqa[i];
|
|
|
|
nq = &nqa[i];
|
|
|
|
|
xfs: fix quota block reservation leak when tp allocates and frees blocks
Al Viro reports that generic/231 fails frequently on XFS and bisected
the problem to the following commit:
5d11fb4b xfs: rework zero range to prevent invalid i_size updates
... which is just the first commit that happens to cause fsx to
reproduce the problem. fsx reproduces via zero range calls. The
aforementioned commit overhauls zero range to use hole punch and
fallocate. As it turns out, the problem is reproducible on demand using
basic hole punch as follows:
$ mkfs.xfs -f -m crc=1,finobt=1 <dev>
$ mount <dev> /mnt -o uquota
$ xfs_io -f -c "falloc 0 50m" /mnt/file
$ for i in $(seq 1 20); do xfs_io -c "fpunch ${i}m 32k" /mnt/file; done
$ rm -f /mnt/file
$ repquota -us /mnt
...
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 32K 0K 0K 3 0 0
A file is allocated with a single 50m extent. The extent count increases
via hole punches until the bmap converts to btree format. The file is
removed but quota reports 32k of space usage for the user. This
reservation is effectively leaked for the lifetime of the mount.
The reason this occurs is because the quota block reservation tracking
is confused when a transaction happens to free and allocate blocks at
the same time. Consider the following sequence of events:
- tp is allocated from xfs_free_file_space() and reserves several blocks
for btree management. Blocks are reserved against the dquot and marked
as such in the transaction (qtrx->qt_blk_res).
- 8 blocks are accounted free when the 32k range is punched out.
xfs_trans_mod_dquot() is called with XFS_TRANS_DQ_BCOUNT and sets
->qt_bcount_delta to -8.
- Subsequently, a block is allocated against the same transaction by
xfs_bmap_extents_to_btree() for btree conversion. A call to
xfs_trans_mod_dquot() increases qt_blk_res_used to 1 and qt_bcount_delta
to -7.
- The transaction is dup'd and committed by xfs_bmap_finish().
xfs_trans_dup_dqinfo() sets the first transaction up such that it has a
matching qt_blk_res and qt_blk_res_used of 1. The remaining unused
reservation is transferred to the duplicate tp.
When the transactions are committed, the dquots are fixed up in
xfs_trans_apply_dquot_deltas() according to one of two methods:
1.) If the transaction holds a block reservation (->qt_blk_res != 0),
_only_ the unused portion reservation is unaccounted from the dquot.
Note that the tp duplication behavior of xfs_bmap_finish() makes it such
that qt_blk_res is typically 0 for tp's with unused reservation.
2.) Otherwise, the dquot is fixed up based on the block delta
(->qt_bcount_delta) created by the transaction.
Therefore, if a transaction has a negative qt_bcount_delta and positive
qt_blk_res_used, the former set of blocks that have been removed from
the file are never factored out of the in-core dquot reservation.
Instead, *_apply_dquot_deltas() sees 1 block used out of a 1 block
reservation and believes there is nothing to fix up. The on-disk
d_bcount is updated independently from qt_bcount_delta, and thus is
correct (and allows the quota usage to correct on remount).
To deal with this situation, we effectively want the "used reservation"
part of the transaction to be consistent with any freed blocks with
respect to quota tracking. For example, if 8 blocks are freed, the
subsequent single block allocation does not need to consume the initial
reservation made by the tp. Instead, it simply borrows one from the
previously freed. One possible implementation of such borrowing is to
avoid the blks_res_used increment when bcount_delta is negative. This
alone is flawed logic in that it only handles the case where blocks are
freed before allocated, however.
Rather than add more complexity to manage synchronization between
bcount_delta and blks_res_used, kill the latter entirely. blk_res_used
is only updated in one place and always in sync with delta_bcount.
Therefore, the net block reservation consumption of the transaction is
always available from bcount_delta. Calculate the reservation
consumption on the fly where necessary based on whether the tp has a
reservation and results in a positive net block delta on the inode.
Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-05-31 21:15:37 +00:00
|
|
|
if (oq->qt_blk_res && oq->qt_bcount_delta > 0)
|
|
|
|
blk_res_used = oq->qt_bcount_delta;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
nq->qt_dquot = oq->qt_dquot;
|
|
|
|
nq->qt_bcount_delta = nq->qt_icount_delta = 0;
|
|
|
|
nq->qt_rtbcount_delta = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer whatever is left of the reservations.
|
|
|
|
*/
|
xfs: fix quota block reservation leak when tp allocates and frees blocks
Al Viro reports that generic/231 fails frequently on XFS and bisected
the problem to the following commit:
5d11fb4b xfs: rework zero range to prevent invalid i_size updates
... which is just the first commit that happens to cause fsx to
reproduce the problem. fsx reproduces via zero range calls. The
aforementioned commit overhauls zero range to use hole punch and
fallocate. As it turns out, the problem is reproducible on demand using
basic hole punch as follows:
$ mkfs.xfs -f -m crc=1,finobt=1 <dev>
$ mount <dev> /mnt -o uquota
$ xfs_io -f -c "falloc 0 50m" /mnt/file
$ for i in $(seq 1 20); do xfs_io -c "fpunch ${i}m 32k" /mnt/file; done
$ rm -f /mnt/file
$ repquota -us /mnt
...
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 32K 0K 0K 3 0 0
A file is allocated with a single 50m extent. The extent count increases
via hole punches until the bmap converts to btree format. The file is
removed but quota reports 32k of space usage for the user. This
reservation is effectively leaked for the lifetime of the mount.
The reason this occurs is because the quota block reservation tracking
is confused when a transaction happens to free and allocate blocks at
the same time. Consider the following sequence of events:
- tp is allocated from xfs_free_file_space() and reserves several blocks
for btree management. Blocks are reserved against the dquot and marked
as such in the transaction (qtrx->qt_blk_res).
- 8 blocks are accounted free when the 32k range is punched out.
xfs_trans_mod_dquot() is called with XFS_TRANS_DQ_BCOUNT and sets
->qt_bcount_delta to -8.
- Subsequently, a block is allocated against the same transaction by
xfs_bmap_extents_to_btree() for btree conversion. A call to
xfs_trans_mod_dquot() increases qt_blk_res_used to 1 and qt_bcount_delta
to -7.
- The transaction is dup'd and committed by xfs_bmap_finish().
xfs_trans_dup_dqinfo() sets the first transaction up such that it has a
matching qt_blk_res and qt_blk_res_used of 1. The remaining unused
reservation is transferred to the duplicate tp.
When the transactions are committed, the dquots are fixed up in
xfs_trans_apply_dquot_deltas() according to one of two methods:
1.) If the transaction holds a block reservation (->qt_blk_res != 0),
_only_ the unused portion reservation is unaccounted from the dquot.
Note that the tp duplication behavior of xfs_bmap_finish() makes it such
that qt_blk_res is typically 0 for tp's with unused reservation.
2.) Otherwise, the dquot is fixed up based on the block delta
(->qt_bcount_delta) created by the transaction.
Therefore, if a transaction has a negative qt_bcount_delta and positive
qt_blk_res_used, the former set of blocks that have been removed from
the file are never factored out of the in-core dquot reservation.
Instead, *_apply_dquot_deltas() sees 1 block used out of a 1 block
reservation and believes there is nothing to fix up. The on-disk
d_bcount is updated independently from qt_bcount_delta, and thus is
correct (and allows the quota usage to correct on remount).
To deal with this situation, we effectively want the "used reservation"
part of the transaction to be consistent with any freed blocks with
respect to quota tracking. For example, if 8 blocks are freed, the
subsequent single block allocation does not need to consume the initial
reservation made by the tp. Instead, it simply borrows one from the
previously freed. One possible implementation of such borrowing is to
avoid the blks_res_used increment when bcount_delta is negative. This
alone is flawed logic in that it only handles the case where blocks are
freed before allocated, however.
Rather than add more complexity to manage synchronization between
bcount_delta and blks_res_used, kill the latter entirely. blk_res_used
is only updated in one place and always in sync with delta_bcount.
Therefore, the net block reservation consumption of the transaction is
always available from bcount_delta. Calculate the reservation
consumption on the fly where necessary based on whether the tp has a
reservation and results in a positive net block delta on the inode.
Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2015-05-31 21:15:37 +00:00
|
|
|
nq->qt_blk_res = oq->qt_blk_res - blk_res_used;
|
|
|
|
oq->qt_blk_res = blk_res_used;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
nq->qt_rtblk_res = oq->qt_rtblk_res -
|
|
|
|
oq->qt_rtblk_res_used;
|
|
|
|
oq->qt_rtblk_res = oq->qt_rtblk_res_used;
|
|
|
|
|
|
|
|
nq->qt_ino_res = oq->qt_ino_res - oq->qt_ino_res_used;
|
|
|
|
oq->qt_ino_res = oq->qt_ino_res_used;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 20:30:55 +00:00
|
|
|
#ifdef CONFIG_XFS_LIVE_HOOKS
|
|
|
|
/*
|
|
|
|
* Use a static key here to reduce the overhead of quota live updates. If the
|
|
|
|
* compiler supports jump labels, the static branch will be replaced by a nop
|
|
|
|
* sled when there are no hook users. Online fsck is currently the only
|
|
|
|
* caller, so this is a reasonable tradeoff.
|
|
|
|
*
|
|
|
|
* Note: Patching the kernel code requires taking the cpu hotplug lock. Other
|
|
|
|
* parts of the kernel allocate memory with that lock held, which means that
|
|
|
|
* XFS callers cannot hold any locks that might be used by memory reclaim or
|
|
|
|
* writeback when calling the static_branch_{inc,dec} functions.
|
|
|
|
*/
|
|
|
|
DEFINE_STATIC_XFS_HOOK_SWITCH(xfs_dqtrx_hooks_switch);
|
|
|
|
|
|
|
|
void
|
|
|
|
xfs_dqtrx_hook_disable(void)
|
|
|
|
{
|
|
|
|
xfs_hooks_switch_off(&xfs_dqtrx_hooks_switch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xfs_dqtrx_hook_enable(void)
|
|
|
|
{
|
|
|
|
xfs_hooks_switch_on(&xfs_dqtrx_hooks_switch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Schedule a transactional dquot update on behalf of an inode. */
|
|
|
|
void
|
|
|
|
xfs_trans_mod_ino_dquot(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_inode *ip,
|
|
|
|
struct xfs_dquot *dqp,
|
|
|
|
unsigned int field,
|
|
|
|
int64_t delta)
|
|
|
|
{
|
|
|
|
xfs_trans_mod_dquot(tp, dqp, field, delta);
|
|
|
|
|
|
|
|
if (xfs_hooks_switched_on(&xfs_dqtrx_hooks_switch)) {
|
|
|
|
struct xfs_mod_ino_dqtrx_params p = {
|
|
|
|
.tx_id = (uintptr_t)tp,
|
|
|
|
.ino = ip->i_ino,
|
|
|
|
.q_type = xfs_dquot_type(dqp),
|
|
|
|
.q_id = dqp->q_id,
|
|
|
|
.delta = delta
|
|
|
|
};
|
|
|
|
struct xfs_quotainfo *qi = tp->t_mountp->m_quotainfo;
|
|
|
|
|
|
|
|
xfs_hooks_call(&qi->qi_mod_ino_dqtrx_hooks, field, &p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the specified functions during a dquot counter update. */
|
|
|
|
int
|
|
|
|
xfs_dqtrx_hook_add(
|
|
|
|
struct xfs_quotainfo *qi,
|
|
|
|
struct xfs_dqtrx_hook *hook)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transactional dquot updates first call the mod hook when changes
|
|
|
|
* are attached to the transaction and then call the apply hook when
|
|
|
|
* those changes are committed (or canceled).
|
|
|
|
*
|
|
|
|
* The apply hook must be installed before the mod hook so that we
|
|
|
|
* never fail to catch the end of a quota update sequence.
|
|
|
|
*/
|
|
|
|
error = xfs_hooks_add(&qi->qi_apply_dqtrx_hooks, &hook->apply_hook);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
error = xfs_hooks_add(&qi->qi_mod_ino_dqtrx_hooks, &hook->mod_hook);
|
|
|
|
if (error)
|
|
|
|
goto out_apply;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_apply:
|
|
|
|
xfs_hooks_del(&qi->qi_apply_dqtrx_hooks, &hook->apply_hook);
|
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stop calling the specified function during a dquot counter update. */
|
|
|
|
void
|
|
|
|
xfs_dqtrx_hook_del(
|
|
|
|
struct xfs_quotainfo *qi,
|
|
|
|
struct xfs_dqtrx_hook *hook)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The mod hook must be removed before apply hook to avoid giving the
|
|
|
|
* hook consumer with an incomplete update. No hooks should be running
|
|
|
|
* after these functions return.
|
|
|
|
*/
|
|
|
|
xfs_hooks_del(&qi->qi_mod_ino_dqtrx_hooks, &hook->mod_hook);
|
|
|
|
xfs_hooks_del(&qi->qi_apply_dqtrx_hooks, &hook->apply_hook);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configure dquot update hook functions. */
|
|
|
|
void
|
|
|
|
xfs_dqtrx_hook_setup(
|
|
|
|
struct xfs_dqtrx_hook *hook,
|
|
|
|
notifier_fn_t mod_fn,
|
|
|
|
notifier_fn_t apply_fn)
|
|
|
|
{
|
|
|
|
xfs_hook_setup(&hook->mod_hook, mod_fn);
|
|
|
|
xfs_hook_setup(&hook->apply_hook, apply_fn);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_XFS_LIVE_HOOKS */
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Wrap around mod_dquot to account for both user and group quotas.
|
|
|
|
*/
|
2009-06-08 13:33:32 +00:00
|
|
|
void
|
2005-04-16 22:20:36 +00:00
|
|
|
xfs_trans_mod_dquot_byino(
|
|
|
|
xfs_trans_t *tp,
|
|
|
|
xfs_inode_t *ip,
|
|
|
|
uint field,
|
2019-04-17 23:30:24 +00:00
|
|
|
int64_t delta)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-06-08 13:33:32 +00:00
|
|
|
xfs_mount_t *mp = tp->t_mountp;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-08-06 18:05:37 +00:00
|
|
|
if (!XFS_IS_QUOTA_ON(mp) ||
|
2013-06-27 22:25:04 +00:00
|
|
|
xfs_is_quota_inode(&mp->m_sb, ip->i_ino))
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
2005-06-21 05:38:48 +00:00
|
|
|
if (XFS_IS_UQUOTA_ON(mp) && ip->i_udquot)
|
2024-02-22 20:30:55 +00:00
|
|
|
xfs_trans_mod_ino_dquot(tp, ip, ip->i_udquot, field, delta);
|
2013-07-11 05:00:40 +00:00
|
|
|
if (XFS_IS_GQUOTA_ON(mp) && ip->i_gdquot)
|
2024-02-22 20:30:55 +00:00
|
|
|
xfs_trans_mod_ino_dquot(tp, ip, ip->i_gdquot, field, delta);
|
2013-07-11 05:00:40 +00:00
|
|
|
if (XFS_IS_PQUOTA_ON(mp) && ip->i_pdquot)
|
2024-02-22 20:30:55 +00:00
|
|
|
xfs_trans_mod_ino_dquot(tp, ip, ip->i_pdquot, field, delta);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 22:25:07 +00:00
|
|
|
STATIC struct xfs_dqtrx *
|
2005-04-16 22:20:36 +00:00
|
|
|
xfs_trans_get_dqtrx(
|
2013-06-27 22:25:07 +00:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_dquot *dqp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-06-27 22:25:07 +00:00
|
|
|
int i;
|
|
|
|
struct xfs_dqtrx *qa;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-07-16 00:47:13 +00:00
|
|
|
switch (xfs_dquot_type(dqp)) {
|
|
|
|
case XFS_DQTYPE_USER:
|
2013-06-27 22:25:09 +00:00
|
|
|
qa = tp->t_dqinfo->dqs[XFS_QM_TRANS_USR];
|
2020-07-16 00:47:13 +00:00
|
|
|
break;
|
|
|
|
case XFS_DQTYPE_GROUP:
|
2013-06-27 22:25:09 +00:00
|
|
|
qa = tp->t_dqinfo->dqs[XFS_QM_TRANS_GRP];
|
2020-07-16 00:47:13 +00:00
|
|
|
break;
|
|
|
|
case XFS_DQTYPE_PROJ:
|
2013-07-11 05:00:40 +00:00
|
|
|
qa = tp->t_dqinfo->dqs[XFS_QM_TRANS_PRJ];
|
2020-07-16 00:47:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-07-11 05:00:40 +00:00
|
|
|
return NULL;
|
2020-07-16 00:47:13 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-04-20 07:01:53 +00:00
|
|
|
for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (qa[i].qt_dquot == NULL ||
|
2010-04-20 07:01:53 +00:00
|
|
|
qa[i].qt_dquot == dqp)
|
|
|
|
return &qa[i];
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2010-04-20 07:01:53 +00:00
|
|
|
return NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make the changes in the transaction structure.
|
|
|
|
* The moral equivalent to xfs_trans_mod_sb().
|
|
|
|
* We don't touch any fields in the dquot, so we don't care
|
|
|
|
* if it's locked or not (most of the time it won't be).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_mod_dquot(
|
2019-04-17 23:30:24 +00:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_dquot *dqp,
|
|
|
|
uint field,
|
|
|
|
int64_t delta)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2019-04-17 23:30:24 +00:00
|
|
|
struct xfs_dqtrx *qtrx;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
ASSERT(tp);
|
2021-08-06 18:05:37 +00:00
|
|
|
ASSERT(XFS_IS_QUOTA_ON(tp->t_mountp));
|
2005-04-16 22:20:36 +00:00
|
|
|
qtrx = NULL;
|
|
|
|
|
2020-12-04 00:41:22 +00:00
|
|
|
if (!delta)
|
|
|
|
return;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (tp->t_dqinfo == NULL)
|
|
|
|
xfs_trans_alloc_dqinfo(tp);
|
|
|
|
/*
|
|
|
|
* Find either the first free slot or the slot that belongs
|
|
|
|
* to this dquot.
|
|
|
|
*/
|
|
|
|
qtrx = xfs_trans_get_dqtrx(tp, dqp);
|
|
|
|
ASSERT(qtrx);
|
|
|
|
if (qtrx->qt_dquot == NULL)
|
|
|
|
qtrx->qt_dquot = dqp;
|
|
|
|
|
2020-12-04 00:41:22 +00:00
|
|
|
trace_xfs_trans_mod_dquot_before(qtrx);
|
|
|
|
trace_xfs_trans_mod_dquot(tp, dqp, field, delta);
|
2020-07-14 17:37:35 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (field) {
|
2020-10-07 00:50:15 +00:00
|
|
|
/* regular disk blk reservation */
|
|
|
|
case XFS_TRANS_DQ_RES_BLKS:
|
2019-04-17 23:30:24 +00:00
|
|
|
qtrx->qt_blk_res += delta;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-07 00:50:15 +00:00
|
|
|
/* inode reservation */
|
|
|
|
case XFS_TRANS_DQ_RES_INOS:
|
2019-04-17 23:30:24 +00:00
|
|
|
qtrx->qt_ino_res += delta;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-07 00:50:15 +00:00
|
|
|
/* disk blocks used. */
|
|
|
|
case XFS_TRANS_DQ_BCOUNT:
|
2005-04-16 22:20:36 +00:00
|
|
|
qtrx->qt_bcount_delta += delta;
|
|
|
|
break;
|
|
|
|
|
2020-10-07 00:50:15 +00:00
|
|
|
case XFS_TRANS_DQ_DELBCOUNT:
|
2005-04-16 22:20:36 +00:00
|
|
|
qtrx->qt_delbcnt_delta += delta;
|
|
|
|
break;
|
|
|
|
|
2020-10-07 00:50:15 +00:00
|
|
|
/* Inode Count */
|
|
|
|
case XFS_TRANS_DQ_ICOUNT:
|
2005-04-16 22:20:36 +00:00
|
|
|
if (qtrx->qt_ino_res && delta > 0) {
|
2019-04-17 23:30:24 +00:00
|
|
|
qtrx->qt_ino_res_used += delta;
|
2005-04-16 22:20:36 +00:00
|
|
|
ASSERT(qtrx->qt_ino_res >= qtrx->qt_ino_res_used);
|
|
|
|
}
|
|
|
|
qtrx->qt_icount_delta += delta;
|
|
|
|
break;
|
|
|
|
|
2020-10-07 00:50:15 +00:00
|
|
|
/* rtblk reservation */
|
|
|
|
case XFS_TRANS_DQ_RES_RTBLKS:
|
2019-04-17 23:30:24 +00:00
|
|
|
qtrx->qt_rtblk_res += delta;
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-07 00:50:15 +00:00
|
|
|
/* rtblk count */
|
|
|
|
case XFS_TRANS_DQ_RTBCOUNT:
|
2005-04-16 22:20:36 +00:00
|
|
|
if (qtrx->qt_rtblk_res && delta > 0) {
|
2019-04-17 23:30:24 +00:00
|
|
|
qtrx->qt_rtblk_res_used += delta;
|
2005-04-16 22:20:36 +00:00
|
|
|
ASSERT(qtrx->qt_rtblk_res >= qtrx->qt_rtblk_res_used);
|
|
|
|
}
|
|
|
|
qtrx->qt_rtbcount_delta += delta;
|
|
|
|
break;
|
|
|
|
|
2020-10-07 00:50:15 +00:00
|
|
|
case XFS_TRANS_DQ_DELRTBCOUNT:
|
2005-04-16 22:20:36 +00:00
|
|
|
qtrx->qt_delrtb_delta += delta;
|
|
|
|
break;
|
|
|
|
|
2020-10-07 00:50:15 +00:00
|
|
|
default:
|
2005-04-16 22:20:36 +00:00
|
|
|
ASSERT(0);
|
|
|
|
}
|
2020-07-14 17:37:35 +00:00
|
|
|
|
2020-12-04 00:41:22 +00:00
|
|
|
trace_xfs_trans_mod_dquot_after(qtrx);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
xfs: dquot log reservations are too small
During review of the separate project quota inode patches, it became
obvious that the dquot log reservation calculation underestimated
the number dquots that can be modified in a transaction. This has
it's roots way back in the Irix quota implementation.
That is, when quotas were first implemented in XFS, it only
supported user and project quotas as Irix did not have group quotas.
Hence the worst case operation involving dquot modification was
calculated to involve 2 user dquots and 1 project dquot or 1 user
dequot and 2 project dquots. i.e. 3 dquots. This was determined back
in 1996, and has remained unchanged ever since.
However, back in 2001, the Linux XFS port dropped all support for
project quota and implmented group quotas over the top. This was
effectively done with a search-and-replace of project with group,
and as such the log reservation was not changed. However, with the
advent of group quotas, chmod and rename now could modify more than
3 dquots in a single transaction - both could modify 4 dquots. Hence
this log reservation has been wrong for a long time.
In 2005, project quota support was reintroduced into Linux, but it
was implemented to be mutually exclusive to group quotas and so this
didn't add any new changes to the dquot log reservation. Hence when
project quotas were in use (rather than group quotas) the log
reservation was again valid, just like in the Irix days.
Now, with the addition of the separate project quota inode, group
and project quotas are no longer mutually exclusive, and hence
operations can now modify three dquots per inode where previously it
was only two. The worst case here is the rename transaction, which
can allocate/free space on two different directory inodes, and if
they have different uid/gid/prid configurations and are world
writeable, then rename can actually modify 6 different dquots now.
Further, the dquot log reservation doesn't take into account the
space used by the dquot log format structure that precedes the dquot
that is logged, and hence further underestimates the worst case
log space required by dquots during a transaction. This has been
missing since the first commit in 1996.
Hence the worst case log reservation needs to be increased from 3 to
6, and it needs to take into account a log format header for each of
those dquots.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2013-07-09 21:04:01 +00:00
|
|
|
* Given an array of dqtrx structures, lock all the dquots associated and join
|
|
|
|
* them to the transaction, provided they have been modified. We know that the
|
2013-11-06 11:45:36 +00:00
|
|
|
* highest number of dquots of one type - usr, grp and prj - involved in a
|
|
|
|
* transaction is 3 so we don't need to make this very generic.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
STATIC void
|
|
|
|
xfs_trans_dqlockedjoin(
|
2019-04-17 23:30:24 +00:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_dqtrx *q)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
ASSERT(q[0].qt_dquot != NULL);
|
|
|
|
if (q[1].qt_dquot == NULL) {
|
|
|
|
xfs_dqlock(q[0].qt_dquot);
|
|
|
|
xfs_trans_dqjoin(tp, q[0].qt_dquot);
|
|
|
|
} else {
|
|
|
|
ASSERT(XFS_QM_TRANS_MAXDQS == 2);
|
|
|
|
xfs_dqlock2(q[0].qt_dquot, q[1].qt_dquot);
|
|
|
|
xfs_trans_dqjoin(tp, q[0].qt_dquot);
|
|
|
|
xfs_trans_dqjoin(tp, q[1].qt_dquot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 17:37:34 +00:00
|
|
|
/* Apply dqtrx changes to the quota reservation counters. */
|
|
|
|
static inline void
|
|
|
|
xfs_apply_quota_reservation_deltas(
|
|
|
|
struct xfs_dquot_res *res,
|
|
|
|
uint64_t reserved,
|
|
|
|
int64_t res_used,
|
|
|
|
int64_t count_delta)
|
|
|
|
{
|
|
|
|
if (reserved != 0) {
|
|
|
|
/*
|
|
|
|
* Subtle math here: If reserved > res_used (the normal case),
|
|
|
|
* we're simply subtracting the unused transaction quota
|
|
|
|
* reservation from the dquot reservation.
|
|
|
|
*
|
|
|
|
* If, however, res_used > reserved, then we have allocated
|
|
|
|
* more quota blocks than were reserved for the transaction.
|
|
|
|
* We must add that excess to the dquot reservation since it
|
|
|
|
* tracks (usage + resv) and by definition we didn't reserve
|
|
|
|
* that excess.
|
|
|
|
*/
|
|
|
|
res->reserved -= abs(reserved - res_used);
|
|
|
|
} else if (count_delta != 0) {
|
|
|
|
/*
|
|
|
|
* These blks were never reserved, either inside a transaction
|
|
|
|
* or outside one (in a delayed allocation). Also, this isn't
|
|
|
|
* always a negative number since we sometimes deliberately
|
|
|
|
* skip quota reservations.
|
|
|
|
*/
|
|
|
|
res->reserved += count_delta;
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2024-02-22 20:30:55 +00:00
|
|
|
#ifdef CONFIG_XFS_LIVE_HOOKS
|
|
|
|
/* Call downstream hooks now that it's time to apply dquot deltas. */
|
|
|
|
static inline void
|
|
|
|
xfs_trans_apply_dquot_deltas_hook(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_dquot *dqp)
|
|
|
|
{
|
|
|
|
if (xfs_hooks_switched_on(&xfs_dqtrx_hooks_switch)) {
|
|
|
|
struct xfs_apply_dqtrx_params p = {
|
|
|
|
.tx_id = (uintptr_t)tp,
|
|
|
|
.q_type = xfs_dquot_type(dqp),
|
|
|
|
.q_id = dqp->q_id,
|
|
|
|
};
|
|
|
|
struct xfs_quotainfo *qi = tp->t_mountp->m_quotainfo;
|
|
|
|
|
|
|
|
xfs_hooks_call(&qi->qi_apply_dqtrx_hooks,
|
|
|
|
XFS_APPLY_DQTRX_COMMIT, &p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define xfs_trans_apply_dquot_deltas_hook(tp, dqp) ((void)0)
|
|
|
|
#endif /* CONFIG_XFS_LIVE_HOOKS */
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Called by xfs_trans_commit() and similar in spirit to
|
|
|
|
* xfs_trans_apply_sb_deltas().
|
|
|
|
* Go thru all the dquots belonging to this transaction and modify the
|
|
|
|
* INCORE dquot to reflect the actual usages.
|
|
|
|
* Unreserve just the reservations done by this transaction.
|
|
|
|
* dquot is still left locked at exit.
|
|
|
|
*/
|
2009-06-08 13:33:32 +00:00
|
|
|
void
|
2005-04-16 22:20:36 +00:00
|
|
|
xfs_trans_apply_dquot_deltas(
|
2013-03-18 14:51:45 +00:00
|
|
|
struct xfs_trans *tp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
2013-03-18 14:51:45 +00:00
|
|
|
struct xfs_dquot *dqp;
|
|
|
|
struct xfs_dqtrx *qtrx, *qa;
|
2019-04-17 23:30:24 +00:00
|
|
|
int64_t totalbdelta;
|
|
|
|
int64_t totalrtbdelta;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-12-04 00:41:21 +00:00
|
|
|
if (!tp->t_dqinfo)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ASSERT(tp->t_dqinfo);
|
2013-06-27 22:25:09 +00:00
|
|
|
for (j = 0; j < XFS_QM_TRANS_DQTYPES; j++) {
|
|
|
|
qa = tp->t_dqinfo->dqs[j];
|
|
|
|
if (qa[0].qt_dquot == NULL)
|
2005-04-16 22:20:36 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock all of the dquots and join them to the transaction.
|
|
|
|
*/
|
|
|
|
xfs_trans_dqlockedjoin(tp, qa);
|
|
|
|
|
|
|
|
for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) {
|
2020-07-14 17:37:34 +00:00
|
|
|
uint64_t blk_res_used;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
qtrx = &qa[i];
|
|
|
|
/*
|
|
|
|
* The array of dquots is filled
|
|
|
|
* sequentially, not sparsely.
|
|
|
|
*/
|
|
|
|
if ((dqp = qtrx->qt_dquot) == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ASSERT(XFS_DQ_IS_LOCKED(dqp));
|
|
|
|
|
2024-02-22 20:30:55 +00:00
|
|
|
xfs_trans_apply_dquot_deltas_hook(tp, dqp);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* adjust the actual number of blocks used
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The issue here is - sometimes we don't make a blkquota
|
|
|
|
* reservation intentionally to be fair to users
|
|
|
|
* (when the amount is small). On the other hand,
|
|
|
|
* delayed allocs do make reservations, but that's
|
|
|
|
* outside of a transaction, so we have no
|
|
|
|
* idea how much was really reserved.
|
|
|
|
* So, here we've accumulated delayed allocation blks and
|
|
|
|
* non-delay blks. The assumption is that the
|
|
|
|
* delayed ones are always reserved (outside of a
|
|
|
|
* transaction), and the others may or may not have
|
|
|
|
* quota reservations.
|
|
|
|
*/
|
|
|
|
totalbdelta = qtrx->qt_bcount_delta +
|
|
|
|
qtrx->qt_delbcnt_delta;
|
|
|
|
totalrtbdelta = qtrx->qt_rtbcount_delta +
|
|
|
|
qtrx->qt_delrtb_delta;
|
2020-07-14 17:37:35 +00:00
|
|
|
|
|
|
|
if (totalbdelta != 0 || totalrtbdelta != 0 ||
|
|
|
|
qtrx->qt_icount_delta != 0) {
|
|
|
|
trace_xfs_trans_apply_dquot_deltas_before(dqp);
|
|
|
|
trace_xfs_trans_apply_dquot_deltas(qtrx);
|
|
|
|
}
|
|
|
|
|
2011-07-13 11:43:50 +00:00
|
|
|
#ifdef DEBUG
|
2005-04-16 22:20:36 +00:00
|
|
|
if (totalbdelta < 0)
|
2020-07-14 17:37:31 +00:00
|
|
|
ASSERT(dqp->q_blk.count >= -totalbdelta);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (totalrtbdelta < 0)
|
2020-07-14 17:37:31 +00:00
|
|
|
ASSERT(dqp->q_rtb.count >= -totalrtbdelta);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (qtrx->qt_icount_delta < 0)
|
2020-07-14 17:37:31 +00:00
|
|
|
ASSERT(dqp->q_ino.count >= -qtrx->qt_icount_delta);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
if (totalbdelta)
|
2020-07-14 17:37:31 +00:00
|
|
|
dqp->q_blk.count += totalbdelta;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (qtrx->qt_icount_delta)
|
2020-07-14 17:37:31 +00:00
|
|
|
dqp->q_ino.count += qtrx->qt_icount_delta;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (totalrtbdelta)
|
2020-07-14 17:37:31 +00:00
|
|
|
dqp->q_rtb.count += totalrtbdelta;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-07-14 17:37:35 +00:00
|
|
|
if (totalbdelta != 0 || totalrtbdelta != 0 ||
|
|
|
|
qtrx->qt_icount_delta != 0)
|
|
|
|
trace_xfs_trans_apply_dquot_deltas_after(dqp);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Get any default limits in use.
|
|
|
|
* Start/reset the timer(s) if needed.
|
|
|
|
*/
|
2020-07-14 17:37:30 +00:00
|
|
|
if (dqp->q_id) {
|
2020-07-14 17:37:33 +00:00
|
|
|
xfs_qm_adjust_dqlimits(dqp);
|
|
|
|
xfs_qm_adjust_dqtimers(dqp);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 17:37:13 +00:00
|
|
|
dqp->q_flags |= XFS_DQFLAG_DIRTY;
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* add this to the list of items to get logged
|
|
|
|
*/
|
|
|
|
xfs_trans_log_dquot(tp, dqp);
|
|
|
|
/*
|
|
|
|
* Take off what's left of the original reservation.
|
|
|
|
* In case of delayed allocations, there's no
|
|
|
|
* reservation that a transaction structure knows of.
|
|
|
|
*/
|
2020-07-14 17:37:34 +00:00
|
|
|
blk_res_used = max_t(int64_t, 0, qtrx->qt_bcount_delta);
|
|
|
|
xfs_apply_quota_reservation_deltas(&dqp->q_blk,
|
|
|
|
qtrx->qt_blk_res, blk_res_used,
|
|
|
|
qtrx->qt_bcount_delta);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Adjust the RT reservation.
|
|
|
|
*/
|
2020-07-14 17:37:34 +00:00
|
|
|
xfs_apply_quota_reservation_deltas(&dqp->q_rtb,
|
|
|
|
qtrx->qt_rtblk_res,
|
|
|
|
qtrx->qt_rtblk_res_used,
|
|
|
|
qtrx->qt_rtbcount_delta);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust the inode reservation.
|
|
|
|
*/
|
2020-07-14 17:37:34 +00:00
|
|
|
ASSERT(qtrx->qt_ino_res >= qtrx->qt_ino_res_used);
|
|
|
|
xfs_apply_quota_reservation_deltas(&dqp->q_ino,
|
|
|
|
qtrx->qt_ino_res,
|
|
|
|
qtrx->qt_ino_res_used,
|
|
|
|
qtrx->qt_icount_delta);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-07-14 17:37:31 +00:00
|
|
|
ASSERT(dqp->q_blk.reserved >= dqp->q_blk.count);
|
|
|
|
ASSERT(dqp->q_ino.reserved >= dqp->q_ino.count);
|
|
|
|
ASSERT(dqp->q_rtb.reserved >= dqp->q_rtb.count);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 20:30:55 +00:00
|
|
|
#ifdef CONFIG_XFS_LIVE_HOOKS
|
|
|
|
/* Call downstream hooks now that it's time to cancel dquot deltas. */
|
|
|
|
static inline void
|
|
|
|
xfs_trans_unreserve_and_mod_dquots_hook(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_dquot *dqp)
|
|
|
|
{
|
|
|
|
if (xfs_hooks_switched_on(&xfs_dqtrx_hooks_switch)) {
|
|
|
|
struct xfs_apply_dqtrx_params p = {
|
|
|
|
.tx_id = (uintptr_t)tp,
|
|
|
|
.q_type = xfs_dquot_type(dqp),
|
|
|
|
.q_id = dqp->q_id,
|
|
|
|
};
|
|
|
|
struct xfs_quotainfo *qi = tp->t_mountp->m_quotainfo;
|
|
|
|
|
|
|
|
xfs_hooks_call(&qi->qi_apply_dqtrx_hooks,
|
|
|
|
XFS_APPLY_DQTRX_UNRESERVE, &p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define xfs_trans_unreserve_and_mod_dquots_hook(tp, dqp) ((void)0)
|
|
|
|
#endif /* CONFIG_XFS_LIVE_HOOKS */
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Release the reservations, and adjust the dquots accordingly.
|
|
|
|
* This is called only when the transaction is being aborted. If by
|
|
|
|
* any chance we have done dquot modifications incore (ie. deltas) already,
|
|
|
|
* we simply throw those away, since that's the expected behavior
|
|
|
|
* when a transaction is curtailed without a commit.
|
|
|
|
*/
|
2009-06-08 13:33:32 +00:00
|
|
|
void
|
2005-04-16 22:20:36 +00:00
|
|
|
xfs_trans_unreserve_and_mod_dquots(
|
2019-11-13 01:04:02 +00:00
|
|
|
struct xfs_trans *tp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
2019-11-13 01:04:02 +00:00
|
|
|
struct xfs_dquot *dqp;
|
2019-04-17 23:30:24 +00:00
|
|
|
struct xfs_dqtrx *qtrx, *qa;
|
2019-11-13 01:04:02 +00:00
|
|
|
bool locked;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2020-12-04 00:41:21 +00:00
|
|
|
if (!tp->t_dqinfo)
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-27 22:25:09 +00:00
|
|
|
for (j = 0; j < XFS_QM_TRANS_DQTYPES; j++) {
|
|
|
|
qa = tp->t_dqinfo->dqs[j];
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) {
|
|
|
|
qtrx = &qa[i];
|
|
|
|
/*
|
|
|
|
* We assume that the array of dquots is filled
|
|
|
|
* sequentially, not sparsely.
|
|
|
|
*/
|
|
|
|
if ((dqp = qtrx->qt_dquot) == NULL)
|
|
|
|
break;
|
2024-02-22 20:30:55 +00:00
|
|
|
|
|
|
|
xfs_trans_unreserve_and_mod_dquots_hook(tp, dqp);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Unreserve the original reservation. We don't care
|
|
|
|
* about the number of blocks used field, or deltas.
|
|
|
|
* Also we don't bother to zero the fields.
|
|
|
|
*/
|
2012-11-12 23:32:59 +00:00
|
|
|
locked = false;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (qtrx->qt_blk_res) {
|
|
|
|
xfs_dqlock(dqp);
|
2012-11-12 23:32:59 +00:00
|
|
|
locked = true;
|
2020-07-14 17:37:30 +00:00
|
|
|
dqp->q_blk.reserved -=
|
2005-04-16 22:20:36 +00:00
|
|
|
(xfs_qcnt_t)qtrx->qt_blk_res;
|
|
|
|
}
|
|
|
|
if (qtrx->qt_ino_res) {
|
|
|
|
if (!locked) {
|
|
|
|
xfs_dqlock(dqp);
|
2012-11-12 23:32:59 +00:00
|
|
|
locked = true;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2020-07-14 17:37:30 +00:00
|
|
|
dqp->q_ino.reserved -=
|
2005-04-16 22:20:36 +00:00
|
|
|
(xfs_qcnt_t)qtrx->qt_ino_res;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qtrx->qt_rtblk_res) {
|
|
|
|
if (!locked) {
|
|
|
|
xfs_dqlock(dqp);
|
2012-11-12 23:32:59 +00:00
|
|
|
locked = true;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2020-07-14 17:37:30 +00:00
|
|
|
dqp->q_rtb.reserved -=
|
2005-04-16 22:20:36 +00:00
|
|
|
(xfs_qcnt_t)qtrx->qt_rtblk_res;
|
|
|
|
}
|
|
|
|
if (locked)
|
|
|
|
xfs_dqunlock(dqp);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-17 22:36:19 +00:00
|
|
|
STATIC void
|
|
|
|
xfs_quota_warn(
|
|
|
|
struct xfs_mount *mp,
|
|
|
|
struct xfs_dquot *dqp,
|
|
|
|
int type)
|
|
|
|
{
|
2020-07-16 00:50:57 +00:00
|
|
|
enum quota_type qtype;
|
2016-01-04 05:10:42 +00:00
|
|
|
|
2020-07-16 00:50:57 +00:00
|
|
|
switch (xfs_dquot_type(dqp)) {
|
|
|
|
case XFS_DQTYPE_PROJ:
|
2016-01-04 05:10:42 +00:00
|
|
|
qtype = PRJQUOTA;
|
2020-07-16 00:50:57 +00:00
|
|
|
break;
|
|
|
|
case XFS_DQTYPE_USER:
|
2016-01-04 05:10:42 +00:00
|
|
|
qtype = USRQUOTA;
|
2020-07-16 00:50:57 +00:00
|
|
|
break;
|
|
|
|
case XFS_DQTYPE_GROUP:
|
2016-01-04 05:10:42 +00:00
|
|
|
qtype = GRPQUOTA;
|
2020-07-16 00:50:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2016-01-04 05:10:42 +00:00
|
|
|
|
2020-07-14 17:37:30 +00:00
|
|
|
quota_send_warning(make_kqid(&init_user_ns, qtype, dqp->q_id),
|
2012-09-16 09:32:43 +00:00
|
|
|
mp->m_super->s_dev, type);
|
2010-01-17 22:36:19 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 17:37:34 +00:00
|
|
|
/*
|
|
|
|
* Decide if we can make an additional reservation against a quota resource.
|
|
|
|
* Returns an inode QUOTA_NL_ warning code and whether or not it's fatal.
|
|
|
|
*
|
|
|
|
* Note that we assume that the numeric difference between the inode and block
|
|
|
|
* warning codes will always be 3 since it's userspace ABI now, and will never
|
|
|
|
* decrease the quota reservation, so the *BELOW messages are irrelevant.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
xfs_dqresv_check(
|
|
|
|
struct xfs_dquot_res *res,
|
|
|
|
struct xfs_quota_limits *qlim,
|
|
|
|
int64_t delta,
|
|
|
|
bool *fatal)
|
|
|
|
{
|
|
|
|
xfs_qcnt_t hardlimit = res->hardlimit;
|
|
|
|
xfs_qcnt_t softlimit = res->softlimit;
|
|
|
|
xfs_qcnt_t total_count = res->reserved + delta;
|
|
|
|
|
|
|
|
BUILD_BUG_ON(QUOTA_NL_BHARDWARN != QUOTA_NL_IHARDWARN + 3);
|
|
|
|
BUILD_BUG_ON(QUOTA_NL_BSOFTLONGWARN != QUOTA_NL_ISOFTLONGWARN + 3);
|
|
|
|
BUILD_BUG_ON(QUOTA_NL_BSOFTWARN != QUOTA_NL_ISOFTWARN + 3);
|
|
|
|
|
|
|
|
*fatal = false;
|
|
|
|
if (delta <= 0)
|
|
|
|
return QUOTA_NL_NOWARN;
|
|
|
|
|
|
|
|
if (!hardlimit)
|
|
|
|
hardlimit = qlim->hard;
|
|
|
|
if (!softlimit)
|
|
|
|
softlimit = qlim->soft;
|
|
|
|
|
|
|
|
if (hardlimit && total_count > hardlimit) {
|
|
|
|
*fatal = true;
|
|
|
|
return QUOTA_NL_IHARDWARN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (softlimit && total_count > softlimit) {
|
|
|
|
time64_t now = ktime_get_real_seconds();
|
|
|
|
|
2022-05-10 20:27:58 +00:00
|
|
|
if (res->timer != 0 && now > res->timer) {
|
2020-07-14 17:37:34 +00:00
|
|
|
*fatal = true;
|
|
|
|
return QUOTA_NL_ISOFTLONGWARN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QUOTA_NL_ISOFTWARN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QUOTA_NL_NOWARN;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* This reserves disk blocks and inodes against a dquot.
|
|
|
|
* Flags indicate if the dquot is to be locked here and also
|
|
|
|
* if the blk reservation is for RT or regular blocks.
|
|
|
|
* Sending in XFS_QMOPT_FORCE_RES flag skips the quota check.
|
|
|
|
*/
|
|
|
|
STATIC int
|
|
|
|
xfs_trans_dqresv(
|
2019-11-13 01:04:02 +00:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_mount *mp,
|
|
|
|
struct xfs_dquot *dqp,
|
|
|
|
int64_t nblks,
|
|
|
|
long ninos,
|
|
|
|
uint flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2019-11-13 01:04:26 +00:00
|
|
|
struct xfs_quotainfo *q = mp->m_quotainfo;
|
2016-02-08 00:27:55 +00:00
|
|
|
struct xfs_def_quota *defq;
|
2020-07-14 17:37:34 +00:00
|
|
|
struct xfs_dquot_res *blkres;
|
|
|
|
struct xfs_quota_limits *qlim;
|
2009-02-08 20:51:42 +00:00
|
|
|
|
|
|
|
xfs_dqlock(dqp);
|
|
|
|
|
2020-05-21 20:07:00 +00:00
|
|
|
defq = xfs_get_defquota(q, xfs_dquot_type(dqp));
|
2016-02-08 00:27:55 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
if (flags & XFS_TRANS_DQ_RES_BLKS) {
|
2020-07-14 17:37:34 +00:00
|
|
|
blkres = &dqp->q_blk;
|
|
|
|
qlim = &defq->blk;
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2020-07-14 17:37:34 +00:00
|
|
|
blkres = &dqp->q_rtb;
|
|
|
|
qlim = &defq->rtb;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 17:37:30 +00:00
|
|
|
if ((flags & XFS_QMOPT_FORCE_RES) == 0 && dqp->q_id &&
|
2020-07-16 00:48:31 +00:00
|
|
|
xfs_dquot_is_enforced(dqp)) {
|
2020-07-14 17:37:34 +00:00
|
|
|
int quota_nl;
|
|
|
|
bool fatal;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dquot is locked already. See if we'd go over the hardlimit
|
|
|
|
* or exceed the timelimit if we'd reserve resources.
|
|
|
|
*/
|
|
|
|
quota_nl = xfs_dqresv_check(blkres, qlim, nblks, &fatal);
|
|
|
|
if (quota_nl != QUOTA_NL_NOWARN) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2020-07-14 17:37:34 +00:00
|
|
|
* Quota block warning codes are 3 more than the inode
|
|
|
|
* codes, which we check above.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2020-07-14 17:37:34 +00:00
|
|
|
xfs_quota_warn(mp, dqp, quota_nl + 3);
|
|
|
|
if (fatal)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error_return;
|
|
|
|
}
|
2020-07-14 17:37:34 +00:00
|
|
|
|
|
|
|
quota_nl = xfs_dqresv_check(&dqp->q_ino, &defq->ino, ninos,
|
|
|
|
&fatal);
|
|
|
|
if (quota_nl != QUOTA_NL_NOWARN) {
|
|
|
|
xfs_quota_warn(mp, dqp, quota_nl);
|
|
|
|
if (fatal)
|
2005-04-16 22:20:36 +00:00
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change the reservation, but not the actual usage.
|
2020-07-14 17:37:31 +00:00
|
|
|
* Note that q_blk.reserved = q_blk.count + resv
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2020-07-14 17:37:34 +00:00
|
|
|
blkres->reserved += (xfs_qcnt_t)nblks;
|
|
|
|
dqp->q_ino.reserved += (xfs_qcnt_t)ninos;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* note the reservation amt in the trans struct too,
|
|
|
|
* so that the transaction knows how much was reserved by
|
|
|
|
* it against this particular dquot.
|
|
|
|
* We don't do this when we are reserving for a delayed allocation,
|
|
|
|
* because we don't have the luxury of a transaction envelope then.
|
|
|
|
*/
|
|
|
|
if (tp) {
|
|
|
|
ASSERT(flags & XFS_QMOPT_RESBLK_MASK);
|
2020-12-04 00:41:22 +00:00
|
|
|
xfs_trans_mod_dquot(tp, dqp, flags & XFS_QMOPT_RESBLK_MASK,
|
|
|
|
nblks);
|
|
|
|
xfs_trans_mod_dquot(tp, dqp, XFS_TRANS_DQ_RES_INOS, ninos);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2021-01-29 23:44:32 +00:00
|
|
|
|
|
|
|
if (XFS_IS_CORRUPT(mp, dqp->q_blk.reserved < dqp->q_blk.count) ||
|
|
|
|
XFS_IS_CORRUPT(mp, dqp->q_rtb.reserved < dqp->q_rtb.count) ||
|
|
|
|
XFS_IS_CORRUPT(mp, dqp->q_ino.reserved < dqp->q_ino.count))
|
|
|
|
goto error_corrupt;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-01-13 22:05:49 +00:00
|
|
|
xfs_dqunlock(dqp);
|
|
|
|
return 0;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
error_return:
|
2009-02-08 20:51:42 +00:00
|
|
|
xfs_dqunlock(dqp);
|
2020-07-16 00:47:13 +00:00
|
|
|
if (xfs_dquot_type(dqp) == XFS_DQTYPE_PROJ)
|
2014-06-25 04:58:08 +00:00
|
|
|
return -ENOSPC;
|
|
|
|
return -EDQUOT;
|
2021-01-29 23:44:32 +00:00
|
|
|
error_corrupt:
|
|
|
|
xfs_dqunlock(dqp);
|
|
|
|
xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
|
2024-02-22 20:30:51 +00:00
|
|
|
xfs_fs_mark_sick(mp, XFS_SICK_FS_QUOTACHECK);
|
2021-01-29 23:44:32 +00:00
|
|
|
return -EFSCORRUPTED;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-03-31 03:04:49 +00:00
|
|
|
* Given dquot(s), make disk block and/or inode reservations against them.
|
2013-07-11 05:00:40 +00:00
|
|
|
* The fact that this does the reservation against user, group and
|
|
|
|
* project quotas is important, because this follows a all-or-nothing
|
2005-04-16 22:20:36 +00:00
|
|
|
* approach.
|
|
|
|
*
|
2009-02-08 20:51:42 +00:00
|
|
|
* flags = XFS_QMOPT_FORCE_RES evades limit enforcement. Used by chown.
|
2006-03-31 03:04:49 +00:00
|
|
|
* XFS_QMOPT_ENOSPC returns ENOSPC not EDQUOT. Used by pquota.
|
2005-04-16 22:20:36 +00:00
|
|
|
* XFS_TRANS_DQ_RES_BLKS reserves regular disk blocks
|
|
|
|
* XFS_TRANS_DQ_RES_RTBLKS reserves realtime disk blocks
|
|
|
|
* dquots are unlocked on return, if they were not locked by caller.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xfs_trans_reserve_quota_bydquots(
|
2013-06-27 22:25:07 +00:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_mount *mp,
|
|
|
|
struct xfs_dquot *udqp,
|
|
|
|
struct xfs_dquot *gdqp,
|
2013-07-11 05:00:40 +00:00
|
|
|
struct xfs_dquot *pdqp,
|
2019-04-17 23:30:24 +00:00
|
|
|
int64_t nblks,
|
2013-06-27 22:25:07 +00:00
|
|
|
long ninos,
|
|
|
|
uint flags)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-06-27 22:25:07 +00:00
|
|
|
int error;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-08-06 18:05:37 +00:00
|
|
|
if (!XFS_IS_QUOTA_ON(mp))
|
2006-03-31 03:04:49 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
ASSERT(flags & XFS_QMOPT_RESBLK_MASK);
|
|
|
|
|
|
|
|
if (udqp) {
|
2020-05-21 20:06:59 +00:00
|
|
|
error = xfs_trans_dqresv(tp, mp, udqp, nblks, ninos, flags);
|
2006-03-31 03:04:49 +00:00
|
|
|
if (error)
|
|
|
|
return error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gdqp) {
|
2020-05-21 20:06:59 +00:00
|
|
|
error = xfs_trans_dqresv(tp, mp, gdqp, nblks, ninos, flags);
|
2013-06-27 22:25:07 +00:00
|
|
|
if (error)
|
|
|
|
goto unwind_usr;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 05:00:40 +00:00
|
|
|
if (pdqp) {
|
|
|
|
error = xfs_trans_dqresv(tp, mp, pdqp, nblks, ninos, flags);
|
|
|
|
if (error)
|
|
|
|
goto unwind_grp;
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2006-03-28 22:55:14 +00:00
|
|
|
* Didn't change anything critical, so, no need to log
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2006-03-31 03:04:49 +00:00
|
|
|
return 0;
|
2013-06-27 22:25:07 +00:00
|
|
|
|
2013-07-11 05:00:40 +00:00
|
|
|
unwind_grp:
|
|
|
|
flags |= XFS_QMOPT_FORCE_RES;
|
|
|
|
if (gdqp)
|
|
|
|
xfs_trans_dqresv(tp, mp, gdqp, -nblks, -ninos, flags);
|
2013-06-27 22:25:07 +00:00
|
|
|
unwind_usr:
|
|
|
|
flags |= XFS_QMOPT_FORCE_RES;
|
|
|
|
if (udqp)
|
|
|
|
xfs_trans_dqresv(tp, mp, udqp, -nblks, -ninos, flags);
|
|
|
|
return error;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock the dquot and change the reservation if we can.
|
|
|
|
* This doesn't change the actual usage, just the reservation.
|
|
|
|
* The inode sent in is locked.
|
|
|
|
*/
|
2009-06-08 13:33:32 +00:00
|
|
|
int
|
2005-04-16 22:20:36 +00:00
|
|
|
xfs_trans_reserve_quota_nblks(
|
2009-06-08 13:33:32 +00:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_inode *ip,
|
2021-01-27 01:20:42 +00:00
|
|
|
int64_t dblocks,
|
|
|
|
int64_t rblocks,
|
|
|
|
bool force)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-06-08 13:33:32 +00:00
|
|
|
struct xfs_mount *mp = ip->i_mount;
|
2021-01-27 01:20:42 +00:00
|
|
|
unsigned int qflags = 0;
|
|
|
|
int error;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-08-06 18:05:37 +00:00
|
|
|
if (!XFS_IS_QUOTA_ON(mp))
|
2006-03-31 03:04:49 +00:00
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2013-06-27 22:25:04 +00:00
|
|
|
ASSERT(!xfs_is_quota_inode(&mp->m_sb, ip->i_ino));
|
2024-02-19 15:41:12 +00:00
|
|
|
xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-01-27 01:20:42 +00:00
|
|
|
if (force)
|
|
|
|
qflags |= XFS_QMOPT_FORCE_RES;
|
|
|
|
|
|
|
|
/* Reserve data device quota against the inode's dquots. */
|
|
|
|
error = xfs_trans_reserve_quota_bydquots(tp, mp, ip->i_udquot,
|
|
|
|
ip->i_gdquot, ip->i_pdquot, dblocks, 0,
|
|
|
|
XFS_QMOPT_RES_REGBLKS | qflags);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Do the same but for realtime blocks. */
|
|
|
|
error = xfs_trans_reserve_quota_bydquots(tp, mp, ip->i_udquot,
|
|
|
|
ip->i_gdquot, ip->i_pdquot, rblocks, 0,
|
|
|
|
XFS_QMOPT_RES_RTBLKS | qflags);
|
|
|
|
if (error) {
|
|
|
|
xfs_trans_reserve_quota_bydquots(tp, mp, ip->i_udquot,
|
|
|
|
ip->i_gdquot, ip->i_pdquot, -dblocks, 0,
|
|
|
|
XFS_QMOPT_RES_REGBLKS);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2021-01-23 00:48:34 +00:00
|
|
|
/* Change the quota reservations for an inode creation activity. */
|
|
|
|
int
|
|
|
|
xfs_trans_reserve_quota_icreate(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_dquot *udqp,
|
|
|
|
struct xfs_dquot *gdqp,
|
|
|
|
struct xfs_dquot *pdqp,
|
|
|
|
int64_t dblocks)
|
|
|
|
{
|
|
|
|
struct xfs_mount *mp = tp->t_mountp;
|
|
|
|
|
2021-08-06 18:05:37 +00:00
|
|
|
if (!XFS_IS_QUOTA_ON(mp))
|
2021-01-23 00:48:34 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return xfs_trans_reserve_quota_bydquots(tp, mp, udqp, gdqp, pdqp,
|
|
|
|
dblocks, 1, XFS_QMOPT_RES_REGBLKS);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
STATIC void
|
|
|
|
xfs_trans_alloc_dqinfo(
|
|
|
|
xfs_trans_t *tp)
|
|
|
|
{
|
2021-10-12 18:09:23 +00:00
|
|
|
tp->t_dqinfo = kmem_cache_zalloc(xfs_dqtrx_cache,
|
2020-07-22 16:23:10 +00:00
|
|
|
GFP_KERNEL | __GFP_NOFAIL);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2009-06-08 13:33:32 +00:00
|
|
|
void
|
2005-04-16 22:20:36 +00:00
|
|
|
xfs_trans_free_dqinfo(
|
|
|
|
xfs_trans_t *tp)
|
|
|
|
{
|
|
|
|
if (!tp->t_dqinfo)
|
|
|
|
return;
|
2021-10-12 18:09:23 +00:00
|
|
|
kmem_cache_free(xfs_dqtrx_cache, tp->t_dqinfo);
|
2009-06-08 13:33:32 +00:00
|
|
|
tp->t_dqinfo = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|