linux-stable/fs/xfs
Darrick J. Wong 1aec7c3d05 xfs: remove obsolete AGF counter debugging
In commit f8f2835a9c we changed the behavior of XFS to use EFIs to
remove blocks from an overfilled AGFL because there were complaints
about transaction overruns that stemmed from trying to free multiple
blocks in a single transaction.

Unfortunately, that commit missed a subtlety in the debug-mode
transaction accounting when a realtime volume is attached.  If a
realtime file undergoes a data fork mapping change such that realtime
extents are allocated (or freed) in the same transaction that a data
device block is also allocated (or freed), we can trip a debugging
assertion.  This can happen (for example) if a realtime extent is
allocated and it is necessary to reshape the bmbt to hold the new
mapping.

When we go to allocate a bmbt block from an AG, the first thing the data
device block allocator does is ensure that the freelist is the proper
length.  If the freelist is too long, it will trim the freelist to the
proper length.

In debug mode, trimming the freelist calls xfs_trans_agflist_delta() to
record the decrement in the AG free list count.  Prior to f8f28 we would
put the free block back in the free space btrees in the same
transaction, which calls xfs_trans_agblocks_delta() to record the
increment in the AG free block count.  Since AGFL blocks are included in
the global free block count (fdblocks), there is no corresponding
fdblocks update, so the AGFL free satisfies the following condition in
xfs_trans_apply_sb_deltas:

	/*
	 * Check that superblock mods match the mods made to AGF counters.
	 */
	ASSERT((tp->t_fdblocks_delta + tp->t_res_fdblocks_delta) ==
	       (tp->t_ag_freeblks_delta + tp->t_ag_flist_delta +
		tp->t_ag_btree_delta));

The comparison here used to be: (X + 0) == ((X+1) + -1 + 0), where X is
the number blocks that were allocated.

After commit f8f28 we defer the block freeing to the next chained
transaction, which means that the calls to xfs_trans_agflist_delta and
xfs_trans_agblocks_delta occur in separate transactions.  The (first)
transaction that shortens the free list trips on the comparison, which
has now become:

(X + 0) == ((X) + -1 + 0)

because we haven't freed the AGFL block yet; we've only logged an
intention to free it.  When the second transaction (the deferred free)
commits, it will evaluate the expression as:

(0 + 0) == (1 + 0 + 0)

and trip over that in turn.

At this point, the astute reader may note that the two commits tagged by
this patch have been in the kernel for a long time but haven't generated
any bug reports.  How is it that the author became aware of this bug?

This originally surfaced as an intermittent failure when I was testing
realtime rmap, but a different bug report by Zorro Lang reveals the same
assertion occuring on !lazysbcount filesystems.

The common factor to both reports (and why this problem wasn't
previously reported) becomes apparent if we consider when
xfs_trans_apply_sb_deltas is called by __xfs_trans_commit():

	if (tp->t_flags & XFS_TRANS_SB_DIRTY)
		xfs_trans_apply_sb_deltas(tp);

With a modern lazysbcount filesystem, transactions update only the
percpu counters, so they don't need to set XFS_TRANS_SB_DIRTY, hence
xfs_trans_apply_sb_deltas is rarely called.

However, updates to the count of free realtime extents are not part of
lazysbcount, so XFS_TRANS_SB_DIRTY will be set on transactions adding or
removing data fork mappings to realtime files; similarly,
XFS_TRANS_SB_DIRTY is always set on !lazysbcount filesystems.

Dave mentioned in response to an earlier version of this patch:

"IIUC, what you are saying is that this debug code is simply not
exercised in normal testing and hasn't been for the past decade?  And it
still won't be exercised on anything other than realtime device testing?

"...it was debugging code from 1994 that was largely turned into dead
code when lazysbcounters were introduced in 2007. Hence I'm not sure it
holds any value anymore."

This debugging code isn't especially helpful - you can modify the
flcount on one AG and the freeblks of another AG, and it won't trigger.
Add the fact that nobody noticed for a decade, and let's just get rid of
it (and start testing realtime :P).

This bug was found by running generic/051 on either a V4 filesystem
lacking lazysbcount; or a V5 filesystem with a realtime volume.

Cc: bfoster@redhat.com, zlang@redhat.com
Fixes: f8f2835a9c ("xfs: defer agfl block frees when dfops is available")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
2021-04-29 07:44:18 -07:00
..
libxfs xfs: remove obsolete AGF counter debugging 2021-04-29 07:44:18 -07:00
scrub xfs: remove XFS_IFEXTENTS 2021-04-15 09:35:51 -07:00
Kconfig
kmem.c
kmem.h
Makefile
mrlock.h
xfs.h
xfs_acl.c xfs: support idmapped mounts 2021-01-24 14:43:46 +01:00
xfs_acl.h fs: make helpers idmap mount aware 2021-01-24 14:27:20 +01:00
xfs_aops.c xfs: remove XFS_IFEXTENTS 2021-04-15 09:35:51 -07:00
xfs_aops.h
xfs_attr_inactive.c
xfs_attr_list.c xfs: rename and simplify xfs_bmap_one_block 2021-04-15 09:35:50 -07:00
xfs_bio_io.c block: Add bio_max_segs 2021-02-26 15:49:51 -07:00
xfs_bmap_item.c
xfs_bmap_item.h
xfs_bmap_util.c xfs: remove XFS_IFEXTENTS 2021-04-15 09:35:51 -07:00
xfs_bmap_util.h
xfs_buf.c block: Add bio_max_segs 2021-02-26 15:49:51 -07:00
xfs_buf.h xfs: don't drain buffer lru on freeze and read-only remount 2021-01-22 16:54:50 -08:00
xfs_buf_item.c xfs: optimise xfs_buf_item_size/format for contiguous regions 2021-03-25 16:47:51 -07:00
xfs_buf_item.h
xfs_buf_item_recover.c
xfs_dir2_readdir.c xfs: remove XFS_IFINLINE 2021-04-15 09:35:51 -07:00
xfs_discard.c
xfs_discard.h
xfs_dquot.c xfs: move the XFS_IFEXTENTS check into xfs_iread_extents 2021-04-15 09:35:50 -07:00
xfs_dquot.h
xfs_dquot_item.c
xfs_dquot_item.h
xfs_dquot_item_recover.c
xfs_error.c xfs: add error injection for per-AG resv failure 2021-03-25 16:47:53 -07:00
xfs_error.h
xfs_export.c
xfs_export.h
xfs_extent_busy.c xfs: don't reuse busy extents on extent trim 2021-02-25 07:58:46 -08:00
xfs_extent_busy.h
xfs_extfree_item.c
xfs_extfree_item.h
xfs_file.c xfs: move the di_flags2 field to struct xfs_inode 2021-04-07 14:37:05 -07:00
xfs_filestream.c
xfs_filestream.h xfs: move the di_flags field to struct xfs_inode 2021-04-07 14:37:05 -07:00
xfs_fsmap.c xfs: drop freeze protection when running GETFSMAP 2021-03-24 10:36:05 -07:00
xfs_fsmap.h
xfs_fsops.c xfs: remove obsolete AGF counter debugging 2021-04-29 07:44:18 -07:00
xfs_fsops.h xfs: get rid of xfs_growfs_{data,log}_t 2021-02-03 09:18:50 -08:00
xfs_globals.c xfs: consolidate the eofblocks and cowblocks workers 2021-02-03 09:18:49 -08:00
xfs_health.c
xfs_icache.c xfs: move the xfs_can_free_eofblocks call under the IOLOCK 2021-04-07 14:38:16 -07:00
xfs_icache.h xfs: rename block gc start and stop functions 2021-02-03 09:18:50 -08:00
xfs_icreate_item.c
xfs_icreate_item.h
xfs_inode.c xfs: remove XFS_IFEXTENTS 2021-04-15 09:35:51 -07:00
xfs_inode.h xfs: move the di_crtime field to struct xfs_inode 2021-04-07 14:37:05 -07:00
xfs_inode_item.c xfs: rename struct xfs_legacy_ictimestamp 2021-04-22 18:29:25 -07:00
xfs_inode_item.h
xfs_inode_item_recover.c xfs: rename struct xfs_legacy_ictimestamp 2021-04-22 18:29:25 -07:00
xfs_ioctl.c xfs: remove XFS_IFEXTENTS 2021-04-15 09:35:51 -07:00
xfs_ioctl.h
xfs_ioctl32.c xfs: remove the possibly unused mp variable in xfs_file_compat_ioctl 2021-02-03 20:31:14 +01:00
xfs_ioctl32.h
xfs_iomap.c xfs: remove XFS_IFEXTENTS 2021-04-15 09:35:51 -07:00
xfs_iomap.h
xfs_iops.c xfs: remove XFS_IFINLINE 2021-04-15 09:35:51 -07:00
xfs_iops.h xfs: support idmapped mounts 2021-01-24 14:43:46 +01:00
xfs_itable.c xfs: move the di_crtime field to struct xfs_inode 2021-04-07 14:37:05 -07:00
xfs_itable.h xfs: support idmapped mounts 2021-01-24 14:43:46 +01:00
xfs_iwalk.c xfs: increase the default parallelism levels of pwork clients 2021-02-03 09:18:49 -08:00
xfs_iwalk.h
xfs_linux.h xfs: move the di_flags field to struct xfs_inode 2021-04-07 14:37:05 -07:00
xfs_log.c xfs: fix boolreturn.cocci warnings 2021-02-10 17:28:13 -08:00
xfs_log.h xfs: cover the log during log quiesce 2021-01-22 16:54:51 -08:00
xfs_log_cil.c
xfs_log_priv.h
xfs_log_recover.c xfs: remove the di_dmevmask and di_dmstate fields from struct xfs_icdinode 2021-04-07 14:37:03 -07:00
xfs_message.c
xfs_message.h
xfs_mount.c xfs: precalculate default inode attribute offset 2021-04-07 14:37:07 -07:00
xfs_mount.h xfs: rename the blockgc workqueue 2021-03-25 16:47:50 -07:00
xfs_mru_cache.c xfs: set WQ_SYSFS on all workqueues in debug mode 2021-02-03 09:18:49 -08:00
xfs_mru_cache.h
xfs_ondisk.h xfs: rename struct xfs_legacy_ictimestamp 2021-04-22 18:29:25 -07:00
xfs_pnfs.c xfs: move the di_size field to struct xfs_inode 2021-04-07 14:37:03 -07:00
xfs_pnfs.h
xfs_pwork.c xfs: increase the default parallelism levels of pwork clients 2021-02-03 09:18:49 -08:00
xfs_pwork.h xfs: increase the default parallelism levels of pwork clients 2021-02-03 09:18:49 -08:00
xfs_qm.c xfs: move the XFS_IFEXTENTS check into xfs_iread_extents 2021-04-15 09:35:50 -07:00
xfs_qm.h
xfs_qm_bhv.c xfs: move the di_projid field to struct xfs_inode 2021-04-07 14:37:03 -07:00
xfs_qm_syscalls.c xfs: move the di_size field to struct xfs_inode 2021-04-07 14:37:03 -07:00
xfs_quota.h xfs: remove xfs_qm_vop_chown_reserve 2021-02-03 09:18:49 -08:00
xfs_quotaops.c xfs: move the di_nblocks field to struct xfs_inode 2021-04-07 14:37:03 -07:00
xfs_refcount_item.c
xfs_refcount_item.h
xfs_reflink.c xfs: move the XFS_IFEXTENTS check into xfs_iread_extents 2021-04-15 09:35:50 -07:00
xfs_reflink.h
xfs_rmap_item.c
xfs_rmap_item.h
xfs_rtalloc.c xfs: move the di_flags field to struct xfs_inode 2021-04-07 14:37:05 -07:00
xfs_rtalloc.h
xfs_stats.c
xfs_stats.h
xfs_super.c xfs: move the di_flags field to struct xfs_inode 2021-04-07 14:37:05 -07:00
xfs_super.h xfs: remove xfs_quiesce_attr declaration 2021-04-16 08:28:36 -07:00
xfs_symlink.c xfs: remove XFS_IFEXTENTS 2021-04-15 09:35:51 -07:00
xfs_symlink.h xfs: support idmapped mounts 2021-01-24 14:43:46 +01:00
xfs_sysctl.c xfs: restore speculative_cow_prealloc_lifetime sysctl 2021-02-24 10:16:08 -08:00
xfs_sysctl.h xfs: consolidate the eofblocks and cowblocks workers 2021-02-03 09:18:49 -08:00
xfs_sysfs.c
xfs_sysfs.h
xfs_trace.c xfs: add a tracepoint for blockgc scans 2021-02-03 09:18:49 -08:00
xfs_trace.h xfs: move the di_size field to struct xfs_inode 2021-04-07 14:37:03 -07:00
xfs_trans.c xfs: remove obsolete AGF counter debugging 2021-04-29 07:44:18 -07:00
xfs_trans.h xfs: remove obsolete AGF counter debugging 2021-04-29 07:44:18 -07:00
xfs_trans_ail.c
xfs_trans_buf.c
xfs_trans_dquot.c xfs: shut down the filesystem if we screw up quota reservation 2021-02-03 09:18:49 -08:00
xfs_trans_priv.h
xfs_xattr.c xfs: prevent metadata files from being inactivated 2021-03-25 16:47:50 -07:00