linux-stable/fs/gfs2
Bob Peterson 1c28dace66 gfs2: ignore negated quota changes
[ Upstream commit 4c6a08125f ]

When lots of quota changes are made, there may be cases in which an
inode's quota information is increased and then decreased, such as when
blocks are added to a file, then deleted from it. If the timing is
right, function do_qc can add pending quota changes to a transaction,
then later, another call to do_qc can negate those changes, resulting
in a net gain of 0. The quota_change information is recorded in the qc
buffer (and qd element of the inode as well). The buffer is added to the
transaction by the first call to do_qc, but a subsequent call changes
the value from non-zero back to zero. At that point it's too late to
remove the buffer_head from the transaction. Later, when the quota sync
code is called, the zero-change qd element is discovered and flagged as
an assert warning. If the fs is mounted with errors=panic, the kernel
will panic.

This is usually seen when files are truncated and the quota changes are
negated by punch_hole/truncate which uses gfs2_quota_hold and
gfs2_quota_unhold rather than block allocations that use gfs2_quota_lock
and gfs2_quota_unlock which automatically do quota sync.

This patch solves the problem by adding a check to qd_check_sync such
that net-zero quota changes already added to the transaction are no
longer deemed necessary to be synced, and skipped.

In this case references are taken for the qd and the slot from do_qc
so those need to be put. The normal sequence of events for a normal
non-zero quota change is as follows:

gfs2_quota_change
   do_qc
      qd_hold
      slot_hold

Later, when the changes are to be synced:

gfs2_quota_sync
   qd_fish
      qd_check_sync
         gets qd ref via lockref_get_not_dead
   do_sync
      do_qc(QC_SYNC)
         qd_put
	    lockref_put_or_lock
   qd_unlock
      qd_put
         lockref_put_or_lock

In the net-zero change case, we add a check to qd_check_sync so it puts
the qd and slot references acquired in gfs2_quota_change and skip the
unneeded sync.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-28 16:45:44 +00:00
..
acl.c
acl.h
aops.c treewide: Remove uninitialized_var() usage 2023-08-11 11:33:32 +02:00
bmap.c gfs2: take jdata unstuff into account in do_grow 2019-12-05 15:37:32 +01:00
bmap.h
dentry.c
dir.c
dir.h
export.c
file.c gfs2: Fix fallocate chunk size 2018-05-30 07:52:35 +02:00
gfs2.h
glock.c gfs2: Fix use-after-free in gfs2_glock_shrink_scan 2021-06-30 08:48:46 -04:00
glock.h
glops.c gfs2: Fix inode height consistency check 2023-05-30 12:38:35 +01:00
glops.h
incore.h
inode.c gfs2: clean up iopen glock mess in gfs2_create_inode 2020-10-01 13:12:30 +02:00
inode.h
Kconfig
lock_dlm.c gfs2: Don't call dlm after protocol is unmounted 2021-09-22 11:45:30 +02:00
log.c gfs2: initialize transaction tr_ailX_lists earlier 2020-09-23 10:46:33 +02:00
log.h gfs2: fix glock reference problem in gfs2_trans_remove_revoke 2019-12-17 20:40:01 +01:00
lops.c gfs2: fix glock reference problem in gfs2_trans_remove_revoke 2019-12-17 20:40:01 +01:00
lops.h
main.c
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
meta_io.c
meta_io.h
ops_fstype.c gfs2: Switch from strlcpy to strscpy 2022-11-25 17:36:55 +01:00
quota.c gfs2: ignore negated quota changes 2023-11-28 16:45:44 +00:00
quota.h gfs2: move privileged user check to gfs2_quota_lock_check 2020-06-03 08:17:52 +02:00
recovery.c
recovery.h
rgrp.c gfs2: assign rgrp glock before compute_bitstructs 2022-04-27 13:15:29 +02:00
rgrp.h
super.c gfs2: Fix possible data races in gfs2_show_options() 2023-08-30 16:35:11 +02:00
super.h
sys.c
sys.h
trace_gfs2.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trans.c gfs2: initialize transaction tr_ailX_lists earlier 2020-09-23 10:46:33 +02:00
trans.h
util.c
util.h
xattr.c
xattr.h