xfs backports for 6.6.y (from 6.11)
cover xfs backports for 6.6.y (from 6.11)
Hi all,
This series contains backports for 6.6 from the 6.11 release. Tested on 30 runs of kdevops with the following configurations:
1. CRC
2. No CRC (512 and 4k block size)
3. Reflink (1K and 4k block size)
4. Reflink without rmapbt
5. External log device
Chen Ni (1):
xfs: convert comma to semicolon
Christoph Hellwig (1):
xfs: fix the contact address for the sysfs ABI documentation
Darrick J. Wong (10):
xfs: verify buffer, inode, and dquot items every tx commit
xfs: use consistent uid/gid when grabbing dquots for inodes
xfs: declare xfs_file.c symbols in xfs_file.h
xfs: create a new helper to return a file's allocation unit
xfs: fix file_path handling in tracepoints
xfs: attr forks require attr, not attr2
xfs: conditionally allow FS_XFLAG_REALTIME changes if S_DAX is set
xfs: use XFS_BUF_DADDR_NULL for daddrs in getfsmap code
xfs: take m_growlock when running growfsrt
xfs: reset rootdir extent size hint after growfsrt
John Garry (2):
xfs: Fix xfs_flush_unmap_range() range for RT
xfs: Fix xfs_prepare_shift() range for RT
Julian Sun (1):
xfs: remove unused parameter in macro XFS_DQUOT_LOGRES
Zizhi Wo (2):
xfs: Fix the owner setting issue for rmap query in xfs fsmap
xfs: Fix missing interval for missing_owner in xfs fsmap
lei lu (1):
xfs: don't walk off the end of a directory data block
Documentation/ABI/testing/sysfs-fs-xfs | 8 +-- fs/xfs/Kconfig | 12 ++++ fs/xfs/libxfs/xfs_dir2_data.c | 31 ++++++++-- fs/xfs/libxfs/xfs_dir2_priv.h | 7 +++ fs/xfs/libxfs/xfs_quota_defs.h | 2 +- fs/xfs/libxfs/xfs_trans_resv.c | 28 ++++----- fs/xfs/scrub/agheader_repair.c | 2 +- fs/xfs/scrub/bmap.c | 8 ++- fs/xfs/scrub/trace.h | 10 ++-- fs/xfs/xfs.h | 4 ++ fs/xfs/xfs_bmap_util.c | 22 +++++--- fs/xfs/xfs_buf_item.c | 32 +++++++++++ fs/xfs/xfs_dquot_item.c | 31 ++++++++++ fs/xfs/xfs_file.c | 33 +++++------ fs/xfs/xfs_file.h | 15 +++++ fs/xfs/xfs_fsmap.c | 30 ++++++++-- fs/xfs/xfs_inode.c | 29 ++++++++-- fs/xfs/xfs_inode.h | 2 + fs/xfs/xfs_inode_item.c | 32 +++++++++++ fs/xfs/xfs_ioctl.c | 12 ++++ fs/xfs/xfs_iops.c | 1 + fs/xfs/xfs_iops.h | 3 - fs/xfs/xfs_rtalloc.c | 78 +++++++++++++++++++++----- fs/xfs/xfs_symlink.c | 8 ++- 24 files changed, 351 insertions(+), 89 deletions(-) create mode 100644 fs/xfs/xfs_file.h
Signature · 1 line
2.39.3
PATCH 1/18 xfs: fix the contact address for the sysfs ABI documentation
From: Christoph Hellwig <[email protected]>
commit 9ff4490e2ab364ec433f15668ef3f5edfb53feca upstream.
oss.sgi.com is long dead, refer to the current linux-xfs list instead.
--- Documentation/ABI/testing/sysfs-fs-xfs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-fs-xfs +4 -4
@@ -1,7 +1,7 @@ What: /sys/fs/xfs/<disk>/log/log_head_lsn Date: July 2014 KernelVersion: 3.17 -Contact: [email protected] +Contact: [email protected] Description: The log sequence number (LSN) of the current head of the log. The LSN is exported in "cycle:basic block" format.
@@ -10,7 +10,7 @@ Users: xfstests What: /sys/fs/xfs/<disk>/log/log_tail_lsn Date: July 2014 KernelVersion: 3.17 -Contact: [email protected] +Contact: [email protected] Description: The log sequence number (LSN) of the current tail of the log. The LSN is exported in "cycle:basic block" format.
@@ -18,7 +18,7 @@ Description: What: /sys/fs/xfs/<disk>/log/reserve_grant_head Date: July 2014 KernelVersion: 3.17 -Contact: [email protected] +Contact: [email protected] Description: The current state of the log reserve grant head. It represents the total log reservation of all currently
@@ -29,7 +29,7 @@ Users: xfstests What: /sys/fs/xfs/<disk>/log/write_grant_head Date: July 2014 KernelVersion: 3.17 -Contact: [email protected] +Contact: [email protected] Description: The current state of the log write grant head. It represents the total log reservation of all currently
Signature · 1 line
2.39.3
PATCH 2/18 xfs: verify buffer, inode, and dquot items every tx commit
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit 150bb10a28b9c8709ae227fc898d9cf6136faa1e upstream.
generic/388 has an annoying tendency to fail like this during log recovery:
XFS (sda4): Unmounting Filesystem 435fe39b-82b6-46ef-be56-819499585130 XFS (sda4): Mounting V5 Filesystem 435fe39b-82b6-46ef-be56-819499585130 XFS (sda4): Starting recovery (logdev: internal)
00000000: 49 4e 81 b6 03 02 00 00 00 00 00 07 00 00 00 07 IN.............. 00000010: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 10 ................ 00000020: 35 9a 8b c1 3e 6e 81 00 35 9a 8b c1 3f dc b7 00 5...>n..5...?... 00000030: 35 9a 8b c1 3f dc b7 00 00 00 00 00 00 3c 86 4f 5...?........<.O 00000040: 00 00 00 00 00 00 02 f3 00 00 00 00 00 00 00 00 ................ 00000050: 00 00 1f 01 00 00 00 00 00 00 00 02 b2 74 c9 0b .............t.. 00000060: ff ff ff ff d7 45 73 10 00 00 00 00 00 00 00 2d .....Es........- 00000070: 00 00 07 92 00 01 fe 30 00 00 00 00 00 00 00 1a .......0........ 00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00000090: 35 9a 8b c1 3b 55 0c 00 00 00 00 00 04 27 b2 d1 5...;U.......'.. 000000a0: 43 5f e3 9b 82 b6 46 ef be 56 81 94 99 58 51 30 C_....F..V...XQ0 XFS (sda4): Internal error Bad dinode after recovery at line 539 of file fs/xfs/xfs_inode_item_recover.c. Caller xlog_recover_items_pass2+0x4e/0xc0 [xfs] CPU: 0 PID: 2189311 Comm: mount Not tainted 6.9.0-rc4-djwx #rc4 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20171121_152543-x86-ol7-builder-01.us.oracle.com-4.el7.1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x4f/0x60 xfs_corruption_error+0x90/0xa0 xlog_recover_inode_commit_pass2+0x5f1/0xb00 xlog_recover_items_pass2+0x4e/0xc0 xlog_recover_commit_trans+0x2db/0x350 xlog_recovery_process_trans+0xab/0xe0 xlog_recover_process_data+0xa7/0x130 xlog_do_recovery_pass+0x398/0x840 xlog_do_log_recovery+0x62/0xc0 xlog_do_recover+0x34/0x1d0 xlog_recover+0xe9/0x1a0 xfs_log_mount+0xff/0x260 xfs_mountfs+0x5d9/0xb60 xfs_fs_fill_super+0x76b/0xa30 get_tree_bdev+0x124/0x1d0 vfs_get_tree+0x17/0xa0 path_mount+0x72b/0xa90 __x64_sys_mount+0x112/0x150 do_syscall_64+0x49/0x100 entry_SYSCALL_64_after_hwframe+0x4b/0x53 </TASK>
XFS (sda4): Corruption detected. Unmount and run xfs_repair
XFS (sda4): Metadata corruption detected at xfs_dinode_verify.part.0+0x739/0x920 [xfs], inode 0x427b2d1 XFS (sda4): Filesystem has been shut down due to log error (0x2).
XFS (sda4): Please unmount the filesystem and rectify the problem(s).
XFS (sda4): log mount/recovery failed: error -117
XFS (sda4): log mount failed
This inode log item recovery failing the dinode verifier after replaying the contents of the inode log item into the ondisk inode. Looking back into what the kernel was doing at the time of the fs shutdown, a thread was in the middle of running a series of transactions, each of which committed changes to the inode.
At some point in the middle of that chain, an invalid (at least according to the verifier) change was committed. Had the filesystem not shut down in the middle of the chain, a subsequent transaction would have corrected the invalid state and nobody would have noticed. But that's not what happened here. Instead, the invalid inode state was committed to the ondisk log, so log recovery tripped over it.
The actual defect here was an overzealous inode verifier, which was fixed in a separate patch. This patch adds some transaction precommit functions for CONFIG_XFS_DEBUG=y mode so that we can detect these kinds of transient errors at transaction commit time, where it's much easier to find the root cause.
--- fs/xfs/Kconfig | 12 ++++++++++++ fs/xfs/xfs.h | 4 ++++ fs/xfs/xfs_buf_item.c | 32 ++++++++++++++++++++++++++++++++ fs/xfs/xfs_dquot_item.c | 31 +++++++++++++++++++++++++++++++ fs/xfs/xfs_inode_item.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+)
fs/xfs/Kconfig +12 -0
@@ -204,6 +204,18 @@ config XFS_DEBUG Say N unless you are an XFS developer, or you play one on TV. +config XFS_DEBUG_EXPENSIVE + bool "XFS expensive debugging checks" + depends on XFS_FS && XFS_DEBUG + help + Say Y here to get an XFS build with expensive debugging checks + enabled. These checks may affect performance significantly. + + Note that the resulting code will be HUGER and SLOWER, and probably + not useful unless you are debugging a particular problem. + + Say N unless you are an XFS developer, or you play one on TV. + config XFS_ASSERT_FATAL bool "XFS fatal asserts" default y
fs/xfs/xfs.h +4 -0
@@ -10,6 +10,10 @@#define DEBUG 1#endif +#ifdef CONFIG_XFS_DEBUG_EXPENSIVE +#define DEBUG_EXPENSIVE 1 +#endif +#ifdef CONFIG_XFS_ASSERT_FATAL #define XFS_ASSERT_FATAL 1#endif
fs/xfs/xfs_buf_item.c +32 -0
@@ -22,6 +22,7 @@#include "xfs_trace.h" #include "xfs_log.h" #include "xfs_log_priv.h" +#include "xfs_error.h" struct kmem_cache *xfs_buf_item_cache;
@@ -781,8 +782,39 @@ xfs_buf_item_committed(return lsn; } +#ifdef DEBUG_EXPENSIVE +static int +xfs_buf_item_precommit ( +struct xfs_trans *tp, +struct xfs_log_item *lip) +{ +struct xfs_buf_log_item *bip =BUF_ITEM (lip); +struct xfs_buf *bp = bip->bli_buf; +struct xfs_mount *mp = bp->b_mount; +xfs_failaddr_t fa; + +if (!bp->b_ops || !bp->b_ops->verify_struct) +return 0 ; +if (bip->bli_flags &XFS_BLI_STALE ) +return 0 ; + + fa = bp->b_ops->verify_struct (bp); +if (fa) { +xfs_buf_verifier_error (bp, -EFSCORRUPTED , bp->b_ops->name, + bp->b_addr,BBTOB (bp->b_length), fa); +xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE ); +ASSERT (fa ==NULL ); + } + +return 0 ; +} +#else +# define xfs_buf_item_precommit NULL +#endif +static const struct xfs_item_ops xfs_buf_item_ops = { .iop_size = xfs_buf_item_size, + .iop_precommit = xfs_buf_item_precommit, .iop_format = xfs_buf_item_format, .iop_pin = xfs_buf_item_pin, .iop_unpin = xfs_buf_item_unpin,
fs/xfs/xfs_dquot_item.c +31 -0
@@ -17,6 +17,7 @@#include "xfs_trans_priv.h" #include "xfs_qm.h" #include "xfs_log.h" +#include "xfs_error.h" static inline struct xfs_dq_logitem *DQUOT_ITEM (struct xfs_log_item *lip) {
@@ -193,8 +194,38 @@ xfs_qm_dquot_logitem_committing(return xfs_qm_dquot_logitem_release (lip); } +#ifdef DEBUG_EXPENSIVE +static int +xfs_qm_dquot_logitem_precommit ( +struct xfs_trans *tp, +struct xfs_log_item *lip) +{ +struct xfs_dquot *dqp =DQUOT_ITEM (lip)->qli_dquot; +struct xfs_mount *mp = dqp->q_mount; +struct xfs_disk_dquot ddq = { }; +xfs_failaddr_t fa; + +xfs_dquot_to_disk (&ddq, dqp); + fa =xfs_dquot_verify (mp, &ddq, dqp->q_id); +if (fa) { +XFS_CORRUPTION_ERROR ("Bad dquot during logging" , +XFS_ERRLEVEL_LOW , mp, &ddq,sizeof (ddq)); +xfs_alert (mp, +"Metadata corruption detected at %pS, dquot 0x%x" , + fa, dqp->q_id); +xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE ); +ASSERT (fa ==NULL ); + } + +return 0 ; +} +#else +# define xfs_qm_dquot_logitem_precommit NULL +#endif +static const struct xfs_item_ops xfs_dquot_item_ops = { .iop_size = xfs_qm_dquot_logitem_size, + .iop_precommit = xfs_qm_dquot_logitem_precommit, .iop_format = xfs_qm_dquot_logitem_format, .iop_pin = xfs_qm_dquot_logitem_pin, .iop_unpin = xfs_qm_dquot_logitem_unpin,
fs/xfs/xfs_inode_item.c +32 -0
@@ -36,6 +36,36 @@ xfs_inode_item_sort(return INODE_ITEM (lip)->ili_inode->i_ino; } +#ifdef DEBUG_EXPENSIVE +static void +xfs_inode_item_precommit_check ( +struct xfs_inode *ip) +{ +struct xfs_mount *mp = ip->i_mount; +struct xfs_dinode *dip; +xfs_failaddr_t fa; + + dip =kzalloc (mp->m_sb.sb_inodesize,GFP_KERNEL |GFP_NOFS ); +if (!dip) { +ASSERT (dip !=NULL ); +return ; + } + +xfs_inode_to_disk (ip, dip,0 ); +xfs_dinode_calc_crc (mp, dip); + fa =xfs_dinode_verify (mp, ip->i_ino, dip); +if (fa) { +xfs_inode_verifier_error (ip, -EFSCORRUPTED , __func__, dip, +sizeof (*dip), fa); +xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE ); +ASSERT (fa ==NULL ); + } +kfree (dip); +} +#else +# define xfs_inode_item_precommit_check (ip) ((void)0) +#endif +/* * Prior to finally logging the inode, we have to ensure that all the * per-modification inode state changes are applied. This includes VFS inode
@@ -168,6 +198,8 @@ xfs_inode_item_precommit( iip->ili_fields |= (flags | iip->ili_last_fields);spin_unlock (&iip->ili_lock); +xfs_inode_item_precommit_check (ip); +/* * We are done with the log item transaction dirty state, so clear it so * that it doesn't pollute future transactions.
Signature · 1 line
2.39.3
PATCH 3/18 xfs: use consistent uid/gid when grabbing dquots for inodes
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit 24a4e1cb322e2bf0f3a1afd1978b610a23aa8f36 upstream.
I noticed that callers of xfs_qm_vop_dqalloc use the following code to compute the anticipated uid of the new file:
mapped_fsuid(idmap, &init_user_ns);
whereas the VFS uses a slightly different computation for actually assigning i_uid:
mapped_fsuid(idmap, i_user_ns(inode));
Technically, these are not the same things. According to Christian Brauner, the only time that inode->i_sb->s_user_ns != &init_user_ns is when the filesystem was mounted in a new mount namespace by an unpriviledged user. XFS does not allow this, which is why we've never seen bug reports about quotas being incorrect or the uid checks in xfs_qm_vop_create_dqattach tripping debug assertions.
However, this /is/ a logic bomb, so let's make the code consistent.
--- fs/xfs/xfs_inode.c | 16 ++++++++++------ fs/xfs/xfs_symlink.c | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-)
fs/xfs/xfs_inode.c +10 -6
@@ -982,10 +982,12 @@ xfs_create( prid =xfs_get_initial_prid (dp);/* -* Make sure that we have allocated dquot(s) on disk. +* Make sure that we have allocated dquot(s) on disk. The uid/gid +* computation code must match what the VFS uses to assign i_[ug]id. +* INHERIT adjusts the gid computation for setgid/grpid systems. */ - error =xfs_qm_vop_dqalloc (dp,mapped_fsuid (idmap, &init_user_ns), -mapped_fsgid (idmap, &init_user_ns), prid, + error =xfs_qm_vop_dqalloc (dp,mapped_fsuid (idmap,i_user_ns (VFS_I (dp))), +mapped_fsgid (idmap,i_user_ns (VFS_I (dp))), prid,XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , &udqp, &gdqp, &pdqp);if (error)
@@ -1131,10 +1133,12 @@ xfs_create_tmpfile( prid =xfs_get_initial_prid (dp);/* -* Make sure that we have allocated dquot(s) on disk. +* Make sure that we have allocated dquot(s) on disk. The uid/gid +* computation code must match what the VFS uses to assign i_[ug]id. +* INHERIT adjusts the gid computation for setgid/grpid systems. */ - error =xfs_qm_vop_dqalloc (dp,mapped_fsuid (idmap, &init_user_ns), -mapped_fsgid (idmap, &init_user_ns), prid, + error =xfs_qm_vop_dqalloc (dp,mapped_fsuid (idmap,i_user_ns (VFS_I (dp))), +mapped_fsgid (idmap,i_user_ns (VFS_I (dp))), prid,XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , &udqp, &gdqp, &pdqp);if (error)
fs/xfs/xfs_symlink.c +5 -3
@@ -191,10 +191,12 @@ xfs_symlink( prid =xfs_get_initial_prid (dp);/* -* Make sure that we have allocated dquot(s) on disk. +* Make sure that we have allocated dquot(s) on disk. The uid/gid +* computation code must match what the VFS uses to assign i_[ug]id. +* INHERIT adjusts the gid computation for setgid/grpid systems. */ - error =xfs_qm_vop_dqalloc (dp,mapped_fsuid (idmap, &init_user_ns), -mapped_fsgid (idmap, &init_user_ns), prid, + error =xfs_qm_vop_dqalloc (dp,mapped_fsuid (idmap,i_user_ns (VFS_I (dp))), +mapped_fsgid (idmap,i_user_ns (VFS_I (dp))), prid,XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , &udqp, &gdqp, &pdqp);if (error)
Signature · 1 line
2.39.3
PATCH 4/18 xfs: declare xfs_file.c symbols in xfs_file.h
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit 00acb28d96746f78389f23a7b5309a917b45c12f upstream.
[backport: dependency of d3b689d and f23660f]
Move the two public symbols in xfs_file.c to xfs_file.h. We're about to add more public symbols in that source file, so let's finally create the header file.
--- fs/xfs/xfs_file.c | 1 + fs/xfs/xfs_file.h | 12 ++++++++++++ fs/xfs/xfs_ioctl.c | 1 + fs/xfs/xfs_iops.c | 1 + fs/xfs/xfs_iops.h | 3 --- 5 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 fs/xfs/xfs_file.h
fs/xfs/xfs_file.c +1 -0
@@ -24,6 +24,7 @@#include "xfs_pnfs.h" #include "xfs_iomap.h" #include "xfs_reflink.h" +#include "xfs_file.h" #include <linux/dax.h> #include <linux/falloc.h>
fs/xfs/xfs_file.h new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2000-2005 Silicon Graphics, Inc. +* All Rights Reserved. +*/ +#ifndef __XFS_FILE_H__ +#define __XFS_FILE_H__ + +extern const struct file_operations xfs_file_operations; +extern const struct file_operations xfs_dir_file_operations; + +#endif /* __XFS_FILE_H__ */
fs/xfs/xfs_ioctl.c +1 -0
@@ -38,6 +38,7 @@#include "xfs_reflink.h" #include "xfs_ioctl.h" #include "xfs_xattr.h" +#include "xfs_file.h" #include <linux/mount.h> #include <linux/namei.h>
fs/xfs/xfs_iops.c +1 -0
@@ -25,6 +25,7 @@#include "xfs_error.h" #include "xfs_ioctl.h" #include "xfs_xattr.h" +#include "xfs_file.h" #include <linux/posix_acl.h> #include <linux/security.h>
fs/xfs/xfs_iops.h +0 -3
@@ -8,9 +8,6 @@struct xfs_inode ; -extern const struct file_operations xfs_file_operations; -extern const struct file_operations xfs_dir_file_operations; -extern ssize_t xfs_vn_listxattr (struct dentry *,char *data,size_t size); int xfs_vn_setattr_size(struct mnt_idmap *idmap,
Signature · 1 line
2.39.3
PATCH 5/18 xfs: create a new helper to return a file's allocation unit
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit ee20808d848c87a51e176706d81b95a21747d6cf upstream.
[backport: dependency of d3b689d and f23660f]
Create a new helper function to calculate the fundamental allocation unit (i.e. the smallest unit of space we can allocate) of a file. Things are going to get hairy with range-exchange on the realtime device, so prepare for this now.
Remove the static attribute from xfs_is_falloc_aligned since the next patch will need it.
--- fs/xfs/xfs_file.c | 32 ++++++++++++-------------------- fs/xfs/xfs_file.h | 3 +++ fs/xfs/xfs_inode.c | 13 +++++++++++++ fs/xfs/xfs_inode.h | 2 ++ 4 files changed, 30 insertions(+), 20 deletions(-)
fs/xfs/xfs_file.c +12 -20
@@ -39,33 +39,25 @@ static const struct vm_operations_struct xfs_file_vm_ops;* Decide if the given file range is aligned to the size of the fundamental * allocation unit for the file. */ -static bool +bool xfs_is_falloc_aligned (struct xfs_inode *ip,loff_t pos,long long int len) { -struct xfs_mount *mp = ip->i_mount; -uint64_t mask; - -if (XFS_IS_REALTIME_INODE (ip)) { -if (!is_power_of_2 (mp->m_sb.sb_rextsize)) { -u64 rextbytes; -u32 mod; - - rextbytes =XFS_FSB_TO_B (mp, mp->m_sb.sb_rextsize); -div_u64_rem (pos, rextbytes, &mod); -if (mod) -return false; -div_u64_rem (len, rextbytes, &mod); -return mod ==0 ; - } - mask =XFS_FSB_TO_B (mp, mp->m_sb.sb_rextsize) -1 ; - }else { - mask = mp->m_sb.sb_blocksize -1 ; +unsigned int alloc_unit =xfs_inode_alloc_unitsize (ip); + +if (!is_power_of_2 (alloc_unit)) { +u32 mod; + +div_u64_rem (pos, alloc_unit, &mod); +if (mod) +return false; +div_u64_rem (len, alloc_unit, &mod); +return mod ==0 ; } -return !((pos | len) & mask); +return !((pos | len) & (alloc_unit -1 )); }/*
fs/xfs/xfs_file.h +3 -0
@@ -9,4 +9,7 @@extern const struct file_operations xfs_file_operations;extern const struct file_operations xfs_dir_file_operations; +bool xfs_is_falloc_aligned (struct xfs_inode *ip,loff_t pos, +long long int len); +#endif /* __XFS_FILE_H__ */
fs/xfs/xfs_inode.c +13 -0
@@ -3782,3 +3782,16 @@ xfs_inode_reload_unlinked(return error; } + +/* Returns the size of fundamental allocation unit for a file, in bytes. */ +unsigned int +xfs_inode_alloc_unitsize ( +struct xfs_inode *ip) +{ +unsigned int blocks =1 ; + +if (XFS_IS_REALTIME_INODE (ip)) + blocks = ip->i_mount->m_sb.sb_rextsize; + +return XFS_FSB_TO_B (ip->i_mount, blocks); +}
fs/xfs/xfs_inode.h +2 -0
@@ -622,4 +622,6 @@ xfs_inode_unlinked_incomplete(int xfs_inode_reload_unlinked_bucket (struct xfs_trans *tp,struct xfs_inode *ip);int xfs_inode_reload_unlinked (struct xfs_inode *ip); +unsigned int xfs_inode_alloc_unitsize (struct xfs_inode *ip); +#endif /* __XFS_INODE_H__ */
Signature · 1 line
2.39.3
PATCH 6/18 xfs: Fix xfs_flush_unmap_range() range for RT
In reply to Catherine HoangFrom: John Garry <[email protected]>
commit d3b689d7c711a9f36d3e48db9eaa75784a892f4c upstream.
Currently xfs_flush_unmap_range() does unmap for a full RT extent range, which we also want to ensure is clean and idle.
This code change is originally from Dave Chinner.
--- fs/xfs/xfs_bmap_util.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/xfs/xfs_bmap_util.c +8 -4
@@ -963,14 +963,18 @@ xfs_flush_unmap_range( xfs_off_t offset, xfs_off_t len) { -struct xfs_mount *mp = ip->i_mount;struct inode *inode =VFS_I (ip);xfs_off_t rounding, start, end;int error; - rounding =max_t (xfs_off_t, mp->m_sb.sb_blocksize,PAGE_SIZE ); - start =round_down (offset, rounding); - end =round_up (offset + len, rounding) -1 ; +/* +* Make sure we extend the flush out to extent alignment +* boundaries so any extent range overlapping the start/end +* of the modification we are about to do is clean and idle. +*/ + rounding =max_t (xfs_off_t,xfs_inode_alloc_unitsize (ip),PAGE_SIZE ); + start =rounddown_64 (offset, rounding); + end =roundup_64 (offset + len, rounding) -1 ; error =filemap_write_and_wait_range (inode->i_mapping, start, end);if (error)
Signature · 1 line
2.39.3
PATCH 7/18 xfs: Fix xfs_prepare_shift() range for RT
In reply to Catherine HoangFrom: John Garry <[email protected]>
commit f23660f059470ec7043748da7641e84183c23bc8 upstream.
The RT extent range must be considered in the xfs_flush_unmap_range() call to stabilize the boundary.
This code change is originally from Dave Chinner.
--- fs/xfs/xfs_bmap_util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/xfs/xfs_bmap_util.c +6 -4
@@ -1059,7 +1059,7 @@ xfs_prepare_shift( struct xfs_inode *ip, loff_t offset) { -struct xfs_mount *mp = ip->i_mount; +unsigned int rounding;int error;/*
@@ -1077,11 +1077,13 @@ xfs_prepare_shift(* with the full range of the operation. If we don't, a COW writeback * completion could race with an insert, front merge with the start * extent (after split) during the shift and corrupt the file. Start -* with the block just prior to the start to stabilize the boundary. +* with the allocation unit just prior to the start to stabilize the +* boundary. */ - offset =round_down (offset, mp->m_sb.sb_blocksize); + rounding =xfs_inode_alloc_unitsize (ip); + offset =rounddown_64 (offset, rounding);if (offset) - offset -= mp->m_sb.sb_blocksize; + offset -= rounding;/* * Writeback and invalidate cache for the remainder of the file as we're
Signature · 1 line
2.39.3
PATCH 8/18 xfs: don't walk off the end of a directory data block
In reply to Catherine HoangFrom: lei lu <[email protected]>
commit 0c7fcdb6d06cdf8b19b57c17605215b06afa864a upstream.
This adds sanity checks for xfs_dir2_data_unused and xfs_dir2_data_entry to make sure don't stray beyond valid memory region. Before patching, the loop simply checks that the start offset of the dup and dep is within the range. So in a crafted image, if last entry is xfs_dir2_data_unused, we can change dup->length to dup->length-1 and leave 1 byte of space. In the next traversal, this space will be considered as dup or dep. We may encounter an out of bound read when accessing the fixed members.
In the patch, we make sure that the remaining bytes large enough to hold an unused entry before accessing xfs_dir2_data_unused and xfs_dir2_data_unused is XFS_DIR2_DATA_ALIGN byte aligned. We also make sure that the remaining bytes large enough to hold a dirent with a single-byte name before accessing xfs_dir2_data_entry.
--- fs/xfs/libxfs/xfs_dir2_data.c | 31 ++++++++++++++++++++++++++----- fs/xfs/libxfs/xfs_dir2_priv.h | 7 +++++++ 2 files changed, 33 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_dir2_data.c +26 -5
@@ -177,6 +177,14 @@ __xfs_dir3_data_check(while (offset < end) {struct xfs_dir2_data_unused *dup = bp->b_addr + offset;struct xfs_dir2_data_entry *dep = bp->b_addr + offset; +unsigned int reclen; + +/* +* Are the remaining bytes large enough to hold an +* unused entry? +*/ +if (offset > end -xfs_dir2_data_unusedsize (1 )) +return __this_address;/* * If it's unused, look for the space in the bestfree table.
@@ -186,9 +194,13 @@ __xfs_dir3_data_check(if (be16_to_cpu (dup->freetag) ==XFS_DIR2_DATA_FREE_TAG ) {xfs_failaddr_t fa; + reclen =xfs_dir2_data_unusedsize ( +be16_to_cpu (dup->length));if (lastfree !=0 )return __this_address; -if (offset +be16_to_cpu (dup->length) > end) +if (be16_to_cpu (dup->length) != reclen) +return __this_address; +if (offset + reclen > end)return __this_address;if (be16_to_cpu (*xfs_dir2_data_unused_tag_p (dup)) != offset)
@@ -206,10 +218,18 @@ __xfs_dir3_data_check( be16_to_cpu(bf[2].length))return __this_address; } - offset +=be16_to_cpu (dup->length); + offset += reclen; lastfree =1 ;continue ; } + +/* +* This is not an unused entry. Are the remaining bytes +* large enough for a dirent with a single-byte name? +*/ +if (offset > end -xfs_dir2_data_entsize (mp,1 )) +return __this_address; +/* * It's a real entry. Validate the fields. * If this is a block directory then make sure it's
@@ -218,9 +238,10 @@ __xfs_dir3_data_check(*/ if (dep->namelen ==0 )return __this_address; -if (!xfs_verify_dir_ino (mp,be64_to_cpu (dep->inumber))) + reclen =xfs_dir2_data_entsize (mp, dep->namelen); +if (offset + reclen > end)return __this_address; -if (offset +xfs_dir2_data_entsize (mp, dep->namelen) > end) +if (!xfs_verify_dir_ino (mp,be64_to_cpu (dep->inumber)))return __this_address;if (be16_to_cpu (*xfs_dir2_data_entry_tag_p (mp, dep)) != offset)return __this_address;
@@ -244,7 +265,7 @@ __xfs_dir3_data_check(if (i >=be32_to_cpu (btp->count))return __this_address; } - offset +=xfs_dir2_data_entsize (mp, dep->namelen); + offset += reclen; }/* * Need to have seen all the entries and all the bestfree slots.
fs/xfs/libxfs/xfs_dir2_priv.h +7 -0
@@ -187,6 +187,13 @@ void xfs_dir2_sf_put_ftype(struct xfs_mount *mp,extern int xfs_readdir (struct xfs_trans *tp,struct xfs_inode *dp,struct dir_context *ctx,size_t bufsize); +static inline unsigned int +xfs_dir2_data_unusedsize ( +unsigned int len) +{ +return round_up (len,XFS_DIR2_DATA_ALIGN ); +} + static inline unsigned int xfs_dir2_data_entsize( struct xfs_mount *mp,
Signature · 1 line
2.39.3
PATCH 9/18 xfs: convert comma to semicolon
In reply to Catherine HoangFrom: Chen Ni <[email protected]>
commit 7bf888fa26e8f22bed4bc3965ab2a2953104ff96 upstream.
Replace a comma between expression statements by a semicolon.
--- fs/xfs/scrub/agheader_repair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/agheader_repair.c +1 -1
@@ -705,7 +705,7 @@ xrep_agfl_init_header(* step. */ xagb_bitmap_init (&af.used_extents); - af.agfl_bno =xfs_buf_to_agfl_bno (agfl_bp), + af.agfl_bno =xfs_buf_to_agfl_bno (agfl_bp);xagb_bitmap_walk (agfl_extents, xrep_agfl_fill, &af); error =xagb_bitmap_disunion (agfl_extents, &af.used_extents);if (error)
Signature · 1 line
2.39.3
PATCH 10/18 xfs: fix file_path handling in tracepoints
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit 19ebc8f84ea12e18dd6c8d3ecaf87bcf4666eee1 upstream.
[backport: only apply fix for 3934e8ebb7cc6]
Since file_path() takes the output buffer as one of its arguments, we might as well have it format directly into the tracepoint's char array instead of wasting stack space.
--- fs/xfs/scrub/trace.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/xfs/scrub/trace.h +4 -6
@@ -784,18 +784,16 @@ TRACE_EVENT(xfile_create,TP_STRUCT__entry (__field (dev_t ,dev ) __field(unsigned long, ino) -__array (char, pathname,256 ) +__array (char, pathname,MAXNAMELEN ) ),TP_fast_assign ( - char pathname[257]; char *path; __entry->ino =file_inode (xf->file)->i_ino; -memset (pathname,0 ,sizeof (pathname)); - path =file_path (xf->file, pathname,sizeof (pathname) -1 ); + path =file_path (xf->file, __entry->pathname,MAXNAMELEN );if (IS_ERR (path)) - path ="(unknown)" ; -strncpy (__entry->pathname, path,sizeof (__entry->pathname)); +strncpy (__entry->pathname,"(unknown)" , +sizeof (__entry->pathname)); ), TP_printk("xfino 0x%lx path '%s'", __entry->ino,
Signature · 1 line
2.39.3
PATCH 11/18 xfs: remove unused parameter in macro XFS_DQUOT_LOGRES
In reply to Catherine HoangFrom: Julian Sun <[email protected]>
commit af5d92f2fad818663da2ce073b6fe15b9d56ffdc upstream.
In the macro definition of XFS_DQUOT_LOGRES, a parameter is accepted, but it is not used. Hence, it should be removed.
This patch has only passed compilation test, but it should be fine.
--- fs/xfs/libxfs/xfs_quota_defs.h | 2 +- fs/xfs/libxfs/xfs_trans_resv.c | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-)
fs/xfs/libxfs/xfs_quota_defs.h +1 -1
@@ -56,7 +56,7 @@ typedef uint8_t xfs_dqtype_t;* And, of course, we also need to take into account the dquot log format item * used to describe each dquot. */ -#define XFS_DQUOT_LOGRES (mp) \ +#define XFS_DQUOT_LOGRES \ ((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6)#define XFS_IS_QUOTA_ON (mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT)
fs/xfs/libxfs/xfs_trans_resv.c +14 -14
@@ -334,11 +334,11 @@ xfs_calc_write_reservation( blksz); t1 += adj; t3 += adj; -return XFS_DQUOT_LOGRES (mp) +max3 (t1, t2, t3); +return XFS_DQUOT_LOGRES +max3 (t1, t2, t3); } t4 =xfs_calc_refcountbt_reservation (mp,1 ); -return XFS_DQUOT_LOGRES (mp) +max (t4,max3 (t1, t2, t3)); +return XFS_DQUOT_LOGRES +max (t4,max3 (t1, t2, t3)); }unsigned int
@@ -406,11 +406,11 @@ xfs_calc_itruncate_reservation(xfs_refcountbt_block_count (mp,4 ), blksz); -return XFS_DQUOT_LOGRES (mp) +max3 (t1, t2, t3); +return XFS_DQUOT_LOGRES +max3 (t1, t2, t3); } t4 =xfs_calc_refcountbt_reservation (mp,2 ); -return XFS_DQUOT_LOGRES (mp) +max (t4,max3 (t1, t2, t3)); +return XFS_DQUOT_LOGRES +max (t4,max3 (t1, t2, t3)); }unsigned int
@@ -436,7 +436,7 @@ STATIC uintxfs_calc_rename_reservation ( struct xfs_mount *mp) { -return XFS_DQUOT_LOGRES (mp) + +return XFS_DQUOT_LOGRES + max((xfs_calc_inode_res(mp, 5) + xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1))),
@@ -475,7 +475,7 @@ STATIC uintxfs_calc_link_reservation ( struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + + return XFS_DQUOT_LOGRES + xfs_calc_iunlink_remove_reservation(mp) + max((xfs_calc_inode_res(mp, 2) + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
@@ -513,7 +513,7 @@ STATIC uintxfs_calc_remove_reservation ( struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + + return XFS_DQUOT_LOGRES + xfs_calc_iunlink_add_reservation(mp) + max((xfs_calc_inode_res(mp, 2) + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp),
@@ -572,7 +572,7 @@ xfs_calc_icreate_resv_alloc( STATIC uintxfs_calc_icreate_reservation (xfs_mount_t *mp) { -return XFS_DQUOT_LOGRES (mp) + +return XFS_DQUOT_LOGRES +max (xfs_calc_icreate_resv_alloc (mp),xfs_calc_create_resv_modify (mp)); }
@@ -581,7 +581,7 @@ STATIC uintxfs_calc_create_tmpfile_reservation ( struct xfs_mount *mp) { -uint res =XFS_DQUOT_LOGRES (mp); +uint res =XFS_DQUOT_LOGRES ; res +=xfs_calc_icreate_resv_alloc (mp);return res +xfs_calc_iunlink_add_reservation (mp);
@@ -630,7 +630,7 @@ STATIC uintxfs_calc_ifree_reservation ( struct xfs_mount *mp) { -return XFS_DQUOT_LOGRES (mp) + +return XFS_DQUOT_LOGRES +xfs_calc_inode_res (mp,1 ) +xfs_calc_buf_res (3 , mp->m_sb.sb_sectsize) + xfs_calc_iunlink_remove_reservation(mp) +
@@ -647,7 +647,7 @@ STATIC uintxfs_calc_ichange_reservation ( struct xfs_mount *mp) { -return XFS_DQUOT_LOGRES (mp) + +return XFS_DQUOT_LOGRES +xfs_calc_inode_res (mp,1 ) +xfs_calc_buf_res (1 , mp->m_sb.sb_sectsize);
@@ -756,7 +756,7 @@ STATIC uintxfs_calc_addafork_reservation ( struct xfs_mount *mp) { -return XFS_DQUOT_LOGRES (mp) + +return XFS_DQUOT_LOGRES +xfs_calc_inode_res (mp,1 ) +xfs_calc_buf_res (2 , mp->m_sb.sb_sectsize) + xfs_calc_buf_res(1, mp->m_dir_geo->blksize) +
@@ -804,7 +804,7 @@ STATIC uintxfs_calc_attrsetm_reservation ( struct xfs_mount *mp) { -return XFS_DQUOT_LOGRES (mp) + +return XFS_DQUOT_LOGRES +xfs_calc_inode_res (mp,1 ) +xfs_calc_buf_res (1 , mp->m_sb.sb_sectsize) +xfs_calc_buf_res (XFS_DA_NODE_MAXDEPTH ,XFS_FSB_TO_B (mp,1 ));
@@ -844,7 +844,7 @@ STATIC uintxfs_calc_attrrm_reservation ( struct xfs_mount *mp) { -return XFS_DQUOT_LOGRES (mp) + +return XFS_DQUOT_LOGRES + max((xfs_calc_inode_res(mp, 1) + xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1)) +
Signature · 1 line
2.39.3
PATCH 12/18 xfs: attr forks require attr, not attr2
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit 73c34b0b85d46bf9c2c0b367aeaffa1e2481b136 upstream.
It turns out that I misunderstood the difference between the attr and attr2 feature bits. "attr" means that at some point an attr fork was created somewhere in the filesystem. "attr2" means that inodes have variable-sized forks, but says nothing about whether or not there actually /are/ attr forks in the system.
If we have an attr fork, we only need to check that attr is set.
--- fs/xfs/scrub/bmap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/xfs/scrub/bmap.c +7 -1
@@ -857,7 +857,13 @@ xchk_bmap( }break ;case XFS_ATTR_FORK : -if (!xfs_has_attr (mp) && !xfs_has_attr2 (mp)) +/* +* "attr" means that an attr fork was created at some point in +* the life of this filesystem. "attr2" means that inodes have +* variable-sized data/attr fork areas. Hence we only check +* attr here. +*/ +if (!xfs_has_attr (mp))xchk_ino_set_corrupt (sc, sc->ip->i_ino);break ;default :
Signature · 1 line
2.39.3
PATCH 13/18 xfs: conditionally allow FS_XFLAG_REALTIME changes if S_DAX is set
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit 8d16762047c627073955b7ed171a36addaf7b1ff upstream.
If a file has the S_DAX flag (aka fsdax access mode) set, we cannot allow users to change the realtime flag unless the datadev and rtdev both support fsdax access modes. Even if there are no extents allocated to the file, the setattr thread could be racing with another thread that has already started down the write code paths.
--- fs/xfs/xfs_ioctl.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/xfs/xfs_ioctl.c +11 -0
@@ -1128,6 +1128,17 @@ xfs_ioctl_setattr_xflags(/* Can't change realtime flag if any extents are allocated. */ if (ip->i_df.if_nextents || ip->i_delayed_blks)return -EINVAL ; + +/* +* If S_DAX is enabled on this file, we can only switch the +* device if both support fsdax. We can't update S_DAX because +* there might be other threads walking down the access paths. +*/ +if (IS_DAX (VFS_I (ip)) && + (mp->m_ddev_targp->bt_daxdev ==NULL || + (mp->m_rtdev_targp && + mp->m_rtdev_targp->bt_daxdev ==NULL ))) +return -EINVAL ; }if (rtflag) {
Signature · 1 line
2.39.3
PATCH 14/18 xfs: Fix the owner setting issue for rmap query in xfs fsmap
In reply to Catherine HoangFrom: Zizhi Wo <[email protected]>
commit 68415b349f3f16904f006275757f4fcb34b8ee43 upstream.
I notice a rmap query bug in xfs_io fsmap:
[root@fedora ~]# xfs_io -c 'fsmap -vvvv' /mnt
EXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL 0: 253:16 [0..7]: static fs metadata 0 (0..7) 8 1: 253:16 [8..23]: per-AG metadata 0 (8..23) 16 2: 253:16 [24..39]: inode btree 0 (24..39) 16 3: 253:16 [40..47]: per-AG metadata 0 (40..47) 8 4: 253:16 [48..55]: refcount btree 0 (48..55) 8 5: 253:16 [56..103]: per-AG metadata 0 (56..103) 48 6: 253:16 [104..127]: free space 0 (104..127) 24
......
Bug:
[root@fedora ~]# xfs_io -c 'fsmap -vvvv -d 0 3' /mnt [root@fedora ~]#
Normally, we should be able to get one record, but we got nothing.
The root cause of this problem lies in the incorrect setting of rm_owner in the rmap query. In the case of the initial query where the owner is not set, __xfs_getfsmap_datadev() first sets info->high.rm_owner to ULLONG_MAX. This is done to prevent any omissions when comparing rmap items. However, if the current ag is detected to be the last one, the function sets info's high_irec based on the provided key. If high->rm_owner is not specified, it should continue to be set to ULLONG_MAX; otherwise, there will be issues with interval omissions. For example, consider "start" and "end" within the same block. If high->rm_owner == 0, it will be smaller than the founded record in rmapbt, resulting in a query with no records. The main call stack is as follows:
xfs_ioc_getfsmap
xfs_getfsmap
xfs_getfsmap_datadev_rmapbt
__xfs_getfsmap_datadev
info->high.rm_owner = ULLONG_MAX
if (pag->pag_agno == end_ag)
xfs_fsmap_owner_to_rmap
// set info->high.rm_owner = 0 because fmr_owner == -1ULL
dest->rm_owner = 0
// get nothing
xfs_getfsmap_datadev_rmapbt_queryThe problem can be resolved by simply modify the xfs_fsmap_owner_to_rmap function internal logic to achieve.
After applying this patch, the above problem have been solved:
[root@fedora ~]# xfs_io -c 'fsmap -vvvv -d 0 3' /mnt
EXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL 0: 253:16 [0..7]: static fs metadata 0 (0..7) 8
--- fs/xfs/xfs_fsmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_fsmap.c +1 -1
@@ -71,7 +71,7 @@ xfs_fsmap_owner_to_rmap(switch (src->fmr_owner) {case 0 :/* "lowest owner id possible" */ case -1ULL :/* "highest owner id possible" */ - dest->rm_owner =0 ; + dest->rm_owner = src->fmr_owner;break ;case XFS_FMR_OWN_FREE : dest->rm_owner =XFS_RMAP_OWN_NULL ;
Signature · 1 line
2.39.3
PATCH 15/18 xfs: use XFS_BUF_DADDR_NULL for daddrs in getfsmap code
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit 6b35cc8d9239569700cc7cc737c8ed40b8b9cfdb upstream.
Use XFS_BUF_DADDR_NULL (instead of a magic sentinel value) to mean "this field is null" like the rest of xfs.
--- fs/xfs/xfs_fsmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_fsmap.c +2 -2
@@ -252,7 +252,7 @@ xfs_getfsmap_rec_before_start( const struct xfs_rmap_irec *rec, xfs_daddr_t rec_daddr) { - if (info->low_daddr != -1ULL) + if (info->low_daddr != XFS_BUF_DADDR_NULL) return rec_daddr < info->low_daddr;if (info->low.rm_blockcount)return xfs_rmap_compare (rec, &info->low) <0 ;
@@ -986,7 +986,7 @@ xfs_getfsmap( info.dev = handlers[i].dev; info.last = false; info.pag =NULL ; - info.low_daddr =-1ULL ; + info.low_daddr =XFS_BUF_DADDR_NULL ; info.low.rm_blockcount =0 ; error = handlers[i].fn (tp, dkeys, &info);if (error)
Signature · 1 line
2.39.3
PATCH 16/18 xfs: Fix missing interval for missing_owner in xfs fsmap
In reply to Catherine HoangFrom: Zizhi Wo <[email protected]>
commit ca6448aed4f10ad88eba79055f181eb9a589a7b3 upstream.
In the fsmap query of xfs, there is an interval missing problem:
[root@fedora ~]# xfs_io -c 'fsmap -vvvv' /mnt
EXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL 0: 253:16 [0..7]: static fs metadata 0 (0..7) 8 1: 253:16 [8..23]: per-AG metadata 0 (8..23) 16 2: 253:16 [24..39]: inode btree 0 (24..39) 16 3: 253:16 [40..47]: per-AG metadata 0 (40..47) 8 4: 253:16 [48..55]: refcount btree 0 (48..55) 8 5: 253:16 [56..103]: per-AG metadata 0 (56..103) 48 6: 253:16 [104..127]: free space 0 (104..127) 24
......
BUG:
[root@fedora ~]# xfs_io -c 'fsmap -vvvv -d 104 107' /mnt [root@fedora ~]#
Normally, we should be able to get [104, 107), but we got nothing.
The problem is caused by shifting. The query for the problem-triggered scenario is for the missing_owner interval (e.g. freespace in rmapbt/ unknown space in bnobt), which is obtained by subtraction (gap). For this scenario, the interval is obtained by info->last. However, rec_daddr is calculated based on the start_block recorded in key[1], which is converted by calling XFS_BB_TO_FSBT. Then if rec_daddr does not exceed info->next_daddr, which means keys[1].fmr_physical >> (mp)->m_blkbb_log <= info->next_daddr, no records will be displayed. In the above example, 104 >> (mp)->m_blkbb_log = 12 and 107 >> (mp)->m_blkbb_log = 12, so the two are reduced to 0 and the gap is ignored:
before calculate ----------------> after shifting
104(st) 107(ed) 12(st/ed)
|---------| | sector size block size
Resolve this issue by introducing the "end_daddr" field in xfs_getfsmap_info. This records |key[1].fmr_physical + key[1].length| at the granularity of sector. If the current query is the last, the rec_daddr is end_daddr to prevent missing interval problems caused by shifting. We only need to focus on the last query, because xfs disks are internally aligned with disk blocksize that are powers of two and minimum 512, so there is no problem with shifting in previous queries.
After applying this patch, the above problem have been solved:
[root@fedora ~]# xfs_io -c 'fsmap -vvvv -d 104 107' /mnt
EXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL 0: 253:16 [104..106]: free space 0 (104..106) 3
--- fs/xfs/xfs_fsmap.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
fs/xfs/xfs_fsmap.c +23 -1
@@ -162,6 +162,7 @@ struct xfs_getfsmap_info {xfs_daddr_t next_daddr;/* next daddr we expect */ /* daddr of low fsmap key when we're using the rtbitmap */ xfs_daddr_t low_daddr; +xfs_daddr_t end_daddr;/* daddr of high fsmap key */ u64 missing_owner;/* owner of holes */ u32 dev;/* device id */ /*
@@ -182,6 +183,7 @@ struct xfs_getfsmap_dev {int (*fn)(struct xfs_trans *tp,const struct xfs_fsmap *keys,struct xfs_getfsmap_info *info); +sector_t nr_sectors; };/* Compare two getfsmap device handlers. */
@@ -294,6 +296,18 @@ xfs_getfsmap_helper(return 0 ; } +/* +* For an info->last query, we're looking for a gap between the last +* mapping emitted and the high key specified by userspace. If the +* user's query spans less than 1 fsblock, then info->high and +* info->low will have the same rm_startblock, which causes rec_daddr +* and next_daddr to be the same. Therefore, use the end_daddr that +* we calculated from userspace's high key to synthesize the record. +* Note that if the btree query found a mapping, there won't be a gap. +*/ +if (info->last && info->end_daddr !=XFS_BUF_DADDR_NULL ) + rec_daddr = info->end_daddr; +/* Are we just counting mappings? */ if (info->head->fmh_count ==0 ) {if (info->head->fmh_entries ==UINT_MAX )
@@ -907,17 +921,21 @@ xfs_getfsmap(/* Set up our device handlers. */ memset (handlers,0 ,sizeof (handlers)); + handlers[0 ].nr_sectors =XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks); handlers[0 ].dev =new_encode_dev (mp->m_ddev_targp->bt_dev);if (use_rmap) handlers[0 ].fn = xfs_getfsmap_datadev_rmapbt;else handlers[0 ].fn = xfs_getfsmap_datadev_bnobt;if (mp->m_logdev_targp != mp->m_ddev_targp) { + handlers[1 ].nr_sectors =XFS_FSB_TO_BB (mp, + mp->m_sb.sb_logblocks); handlers[1 ].dev =new_encode_dev (mp->m_logdev_targp->bt_dev); handlers[1 ].fn = xfs_getfsmap_logdev; }#ifdef CONFIG_XFS_RT if (mp->m_rtdev_targp) { + handlers[2 ].nr_sectors =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rblocks); handlers[2 ].dev =new_encode_dev (mp->m_rtdev_targp->bt_dev); handlers[2 ].fn = xfs_getfsmap_rtdev_rtbitmap; }
@@ -949,6 +967,7 @@ xfs_getfsmap( info.next_daddr = head->fmh_keys[0 ].fmr_physical + head->fmh_keys[0 ].fmr_length; + info.end_daddr =XFS_BUF_DADDR_NULL ; info.fsmap_recs = fsmap_recs; info.head = head;
@@ -969,8 +988,11 @@ xfs_getfsmap(* low key, zero out the low key so that we get * everything from the beginning. */ -if (handlers[i].dev == head->fmh_keys[1 ].fmr_device) +if (handlers[i].dev == head->fmh_keys[1 ].fmr_device) { dkeys[1 ] = head->fmh_keys[1 ]; + info.end_daddr =min (handlers[i].nr_sectors -1 , + dkeys[1 ].fmr_physical); + }if (handlers[i].dev > head->fmh_keys[0 ].fmr_device)memset (&dkeys[0 ],0 ,sizeof (struct xfs_fsmap ));
Signature · 1 line
2.39.3
Re: [PATCH 6.6 CANDIDATE 16/18] xfs: Fix missing interval for missing_owner in xfs fsmap
Quoted 3 lines · Catherine Hoang
From: Zizhi Wo <[email protected]>
commit
ca6448aed4f10ad88eba79055f181eb9a589a7b3upstream.
/me notes that this fixpatch itself needs:
https://lore.kernel.org/linux-xfs/173258397820.4032920.11184703272397099638.stgit@frogsfrogsfrogs/
but that's still on the list of pending 6.12 backports. I don't know if you want to just drop this for now and pull it in for the 6.12 catch-up?
--D
Quoted 144 lines
In the fsmap query of xfs, there is an interval missing problem:
[root@fedora ~]#xfs_io-c 'fsmap -vvvv' /mntEXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL 0: 253:16 [0..7]: static fs metadata 0 (0..7) 8 1: 253:16 [8..23]: per-AG metadata 0 (8..23) 16 2: 253:16 [24..39]: inode btree 0 (24..39) 16 3: 253:16 [40..47]: per-AG metadata 0 (40..47) 8 4: 253:16 [48..55]: refcount btree 0 (48..55) 8 5: 253:16 [56..103]: per-AG metadata 0 (56..103) 48 6: 253:16 [104..127]: free space 0 (104..127) 24......
BUG:
[root@fedora ~]#xfs_io-c 'fsmap -vvvv -d 104 107' /mnt [root@fedora ~]#
Normally, we should be able to get [104, 107), but we got nothing.The problem is caused by shifting. The query for the problem-triggered scenario is for the
missing_ownerinterval (e.g. freespace in rmapbt/ unknown space in bnobt), which is obtained by subtraction (gap). For this scenario, the interval is obtained byinfo->last. However,rec_daddris calculated based on thestart_blockrecorded in key[1], which is converted by callingXFS_BB_TO_FSBT. Then ifrec_daddrdoes not exceedinfo->next_daddr, which means keys[1].fmr_physical >> (mp)->m_blkbb_log <=info->next_daddr, no records will be displayed. In the above example, 104 >> (mp)->m_blkbb_log = 12 and 107 >> (mp)->m_blkbb_log = 12, so the two are reduced to 0 and the gap is ignored:before calculate ----------------> after shifting
104(st) 107(ed) 12(st/ed)|---------| | sector size block sizeResolve this issue by introducing the "
end_daddr" field inxfs_getfsmap_info. This records |key[1].fmr_physical + key[1].length| at the granularity of sector. If the current query is the last, therec_daddrisend_daddrto prevent missing interval problems caused by shifting. We only need to focus on the last query, because xfs disks are internally aligned with disk blocksize that are powers of two and minimum 512, so there is no problem with shifting in previous queries.After applying this patch, the above problem have been solved:
[root@fedora ~]#xfs_io-c 'fsmap -vvvv -d 104 107' /mntEXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL 0: 253:16 [104..106]: free space 0 (104..106) 3Fixes e89c041338ed ("xfs: implement the GETFSMAP ioctl")Signed-off-by Zizhi Wo <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>[djwong: limit the range of end_addr correctly]Signed-off-by Darrick J. Wong <[email protected]>Signed-off-by Chandan Babu R <[email protected]>Signed-off-by Catherine Hoang <[email protected]>--- fs/xfs/xfs_fsmap.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)fs/xfs/xfs_fsmap.c +23
-1@@ -162,6 +162,7 @@ struct xfs_getfsmap_info {xfs_daddr_t next_daddr;/* next daddr we expect */ /* daddr of low fsmap key when we're using the rtbitmap */ xfs_daddr_t low_daddr; +xfs_daddr_t end_daddr;/* daddr of high fsmap key */ u64 missing_owner;/* owner of holes */ u32 dev;/* device id */ /* @@ -182,6 +183,7 @@ struct xfs_getfsmap_dev {int (*fn)(struct xfs_trans *tp,const struct xfs_fsmap *keys,struct xfs_getfsmap_info *info); +sector_t nr_sectors; };/* Compare two getfsmap device handlers. */ @@ -294,6 +296,18 @@ xfs_getfsmap_helper(return 0 ; } +/* +* For an info->last query, we're looking for a gap between the last +* mapping emitted and the high key specified by userspace. If the +* user's query spans less than 1 fsblock, then info->high and +* info->low will have the same rm_startblock, which causes rec_daddr +* and next_daddr to be the same. Therefore, use the end_daddr that +* we calculated from userspace's high key to synthesize the record. +* Note that if the btree query found a mapping, there won't be a gap. +*/ +if (info->last && info->end_daddr !=XFS_BUF_DADDR_NULL ) + rec_daddr = info->end_daddr; +/* Are we just counting mappings? */ if (info->head->fmh_count ==0 ) {if (info->head->fmh_entries ==UINT_MAX )@@ -907,17 +921,21 @@ xfs_getfsmap(/* Set up our device handlers. */ memset (handlers,0 ,sizeof (handlers)); + handlers[0 ].nr_sectors =XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks); handlers[0 ].dev =new_encode_dev (mp->m_ddev_targp->bt_dev);if (use_rmap) handlers[0 ].fn = xfs_getfsmap_datadev_rmapbt;else handlers[0 ].fn = xfs_getfsmap_datadev_bnobt;if (mp->m_logdev_targp != mp->m_ddev_targp) { + handlers[1 ].nr_sectors =XFS_FSB_TO_BB (mp, + mp->m_sb.sb_logblocks); handlers[1 ].dev =new_encode_dev (mp->m_logdev_targp->bt_dev); handlers[1 ].fn = xfs_getfsmap_logdev; }#ifdef CONFIG_XFS_RT if (mp->m_rtdev_targp) { + handlers[2 ].nr_sectors =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rblocks); handlers[2 ].dev =new_encode_dev (mp->m_rtdev_targp->bt_dev); handlers[2 ].fn = xfs_getfsmap_rtdev_rtbitmap; }@@ -949,6 +967,7 @@ xfs_getfsmap( info.next_daddr = head->fmh_keys[0 ].fmr_physical + head->fmh_keys[0 ].fmr_length; + info.end_daddr =XFS_BUF_DADDR_NULL ; info.fsmap_recs = fsmap_recs; info.head = head;@@ -969,8 +988,11 @@ xfs_getfsmap(* low key, zero out the low key so that we get * everything from the beginning. */ -if (handlers[i].dev == head->fmh_keys[1 ].fmr_device) +if (handlers[i].dev == head->fmh_keys[1 ].fmr_device) { dkeys[1 ] = head->fmh_keys[1 ]; + info.end_daddr =min (handlers[i].nr_sectors -1 , + dkeys[1 ].fmr_physical); + }if (handlers[i].dev > head->fmh_keys[0 ].fmr_device)memset (&dkeys[0 ],0 ,sizeof (struct xfs_fsmap ));Signature · 1 line
2.39.3
PATCH 17/18 xfs: take m_growlock when running growfsrt
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit 16e1fbdce9c8d084863fd63cdaff8fb2a54e2f88 upstream.
Take the grow lock when we're expanding the realtime volume, like we do for the other growfs calls.
--- fs/xfs/xfs_rtalloc.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
fs/xfs/xfs_rtalloc.c +25 -13
@@ -953,34 +953,39 @@ xfs_growfs_rt(/* Needs to have been mounted with an rt device. */ if (!XFS_IS_REALTIME_MOUNT (mp))return -EINVAL ; + +if (!mutex_trylock (&mp->m_growlock)) +return -EWOULDBLOCK ;/* * Mount should fail if the rt bitmap/summary files don't load, but * we'll check anyway. */ + error = -EINVAL ;if (!mp->m_rbmip || !mp->m_rsumip) -return -EINVAL ; + goto out_unlock;/* Shrink not supported. */ if (in->newblocks <= sbp->sb_rblocks) -return -EINVAL ; + goto out_unlock;/* Can only change rt extent size when adding rt volume. */ if (sbp->sb_rblocks >0 && in->extsize != sbp->sb_rextsize) -return -EINVAL ; + goto out_unlock;/* Range check the extent size. */ if (XFS_FSB_TO_B (mp, in->extsize) >XFS_MAX_RTEXTSIZE ||XFS_FSB_TO_B (mp, in->extsize) <XFS_MIN_RTEXTSIZE ) -return -EINVAL ; + goto out_unlock;/* Unsupported realtime features. */ + error = -EOPNOTSUPP ;if (xfs_has_rmapbt (mp) ||xfs_has_reflink (mp) ||xfs_has_quota (mp)) -return -EOPNOTSUPP ; + goto out_unlock; nrblocks = in->newblocks; error =xfs_sb_validate_fsb_count (sbp, nrblocks);if (error) -return error; + goto out_unlock;/* * Read in the last block of the device, make sure it exists. */
@@ -988,7 +993,7 @@ xfs_growfs_rt(XFS_FSB_TO_BB (mp, nrblocks -1 ), XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL);if (error) -return error; + goto out_unlock;xfs_buf_relse (bp);/*
@@ -996,8 +1001,10 @@ xfs_growfs_rt(*/ nrextents = nrblocks;do_div (nrextents, in->extsize); -if (!xfs_validate_rtextents (nrextents)) -return -EINVAL ; +if (!xfs_validate_rtextents (nrextents)) { + error = -EINVAL ; + goto out_unlock; + } nrbmblocks =howmany_64 (nrextents,NBBY * sbp->sb_blocksize); nrextslog =xfs_compute_rextslog (nrextents); nrsumlevels = nrextslog +1 ;
@@ -1009,8 +1016,11 @@ xfs_growfs_rt(* the log. This prevents us from getting a log overflow, * since we'll log basically the whole summary file at once. */ -if (nrsumblocks > (mp->m_sb.sb_logblocks >>1 )) -return -EINVAL ; +if (nrsumblocks > (mp->m_sb.sb_logblocks >>1 )) { + error = -EINVAL ; + goto out_unlock; + } +/* * Get the old block counts for bitmap and summary inodes. * These can't change since other growfs callers are locked out.
@@ -1022,10 +1032,10 @@ xfs_growfs_rt(*/ error =xfs_growfs_rt_alloc (mp, rbmblocks, nrbmblocks, mp->m_rbmip);if (error) -return error; + goto out_unlock; error =xfs_growfs_rt_alloc (mp, rsumblocks, nrsumblocks, mp->m_rsumip);if (error) -return error; + goto out_unlock; rsum_cache = mp->m_rsum_cache;if (nrbmblocks != sbp->sb_rbmblocks)
@@ -1190,6 +1200,8 @@ xfs_growfs_rt( } } +out_unlock: +mutex_unlock (&mp->m_growlock);return error; }
Signature · 1 line
2.39.3
PATCH 18/18 xfs: reset rootdir extent size hint after growfsrt
In reply to Catherine HoangFrom: "Darrick J. Wong" <[email protected]>
commit a24cae8fc1f13f6f6929351309f248fd2e9351ce upstream.
If growfsrt is run on a filesystem that doesn't have a rt volume, it's possible to change the rt extent size. If the root directory was previously set up with an inherited extent size hint and rtinherit, it's possible that the hint is no longer a multiple of the rt extent size. Although the verifiers don't complain about this, xfs_repair will, so if we detect this situation, log the root directory to clean it up. This is still racy, but it's better than nothing.
--- fs/xfs/xfs_rtalloc.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
fs/xfs/xfs_rtalloc.c +40 -0
@@ -915,6 +915,39 @@ xfs_alloc_rsum_cache(xfs_warn (mp,"could not allocate realtime summary cache" ); } +/* +* If we changed the rt extent size (meaning there was no rt volume previously) +* and the root directory had EXTSZINHERIT and RTINHERIT set, it's possible +* that the extent size hint on the root directory is no longer congruent with +* the new rt extent size. Log the rootdir inode to fix this. +*/ +static int +xfs_growfs_rt_fixup_extsize ( +struct xfs_mount *mp) +{ +struct xfs_inode *ip = mp->m_rootip; +struct xfs_trans *tp; +int error =0 ; + +xfs_ilock (ip,XFS_IOLOCK_EXCL ); +if (!(ip->i_diflags &XFS_DIFLAG_RTINHERIT ) || + !(ip->i_diflags &XFS_DIFLAG_EXTSZINHERIT )) + goto out_iolock; + + error =xfs_trans_alloc_inode (ip, &M_RES (mp)->tr_ichange,0 ,0 , false, + &tp); +if (error) + goto out_iolock; + +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); + error =xfs_trans_commit (tp); +xfs_iunlock (ip,XFS_ILOCK_EXCL ); + +out_iolock: +xfs_iunlock (ip,XFS_IOLOCK_EXCL ); +return error; +} +/* * Visible (exported) functions. */
@@ -944,6 +977,7 @@ xfs_growfs_rt(xfs_sb_t *sbp;/* old superblock */ xfs_fsblock_t sumbno;/* summary block number */ uint8_t *rsum_cache;/* old summary cache */ +xfs_agblock_t old_rextsize = mp->m_sb.sb_rextsize; sbp = &mp->m_sb;
@@ -1177,6 +1211,12 @@ xfs_growfs_rt(if (error) goto out_free; +if (old_rextsize != in->extsize) { + error =xfs_growfs_rt_fixup_extsize (mp); +if (error) + goto out_free; + } +/* Update secondary superblocks now the physical grow has completed */ error =xfs_update_secondary_sbs (mp);
Signature · 1 line
2.39.3
Quoted 10 lines · Catherine Hoang
Hi all,
This series contains backports for 6.6 from the 6.11 release. Tested on 30 runs of kdevops with the following configurations:
1. CRC
2. No CRC (512 and 4k block size)
3. Reflink (1K and 4k block size)
4. Reflink without rmapbt
5. External log device
For everything except for patch 16,
--D
Quoted 64 lines
Chen Ni (1):
xfs: convert comma to semicolonChristoph Hellwig (1):
xfs: fix the contact address for the sysfs ABI documentationDarrick J. Wong (10):
xfs: verify buffer, inode, and dquot items every tx commit
xfs: use consistent uid/gid when grabbing dquots for inodes
xfs: declarexfs_file.csymbols inxfs_file.h
xfs: create a new helper to return a file's allocation unit
xfs: fixfile_pathhandling in tracepoints
xfs: attr forks require attr, not attr2
xfs: conditionally allowFS_XFLAG_REALTIMEchanges ifS_DAXis set
xfs: useXFS_BUF_DADDR_NULLfor daddrs in getfsmap code
xfs: takem_growlockwhen running growfsrt
xfs: reset rootdir extent size hint after growfsrtJohn Garry (2):
xfs: Fixxfs_flush_unmap_range()range for RT
xfs: Fixxfs_prepare_shift()range for RTJulian Sun (1):
xfs: remove unused parameter in macroXFS_DQUOT_LOGRESZizhi Wo (2):
xfs: Fix the owner setting issue for rmap query in xfs fsmap
xfs: Fix missing interval formissing_ownerin xfs fsmaplei lu (1):
xfs: don't walk off the end of a directory data blockDocumentation/ABI/testing/sysfs-fs-xfs | 8 +-- fs/xfs/Kconfig | 12 ++++ fs/xfs/libxfs/xfs_dir2_data.c | 31 ++++++++-- fs/xfs/libxfs/xfs_dir2_priv.h | 7 +++ fs/xfs/libxfs/xfs_quota_defs.h | 2 +- fs/xfs/libxfs/xfs_trans_resv.c | 28 ++++----- fs/xfs/scrub/agheader_repair.c | 2 +- fs/xfs/scrub/bmap.c | 8 ++- fs/xfs/scrub/trace.h | 10 ++-- fs/xfs/xfs.h | 4 ++ fs/xfs/xfs_bmap_util.c | 22 +++++--- fs/xfs/xfs_buf_item.c | 32 +++++++++++ fs/xfs/xfs_dquot_item.c | 31 ++++++++++ fs/xfs/xfs_file.c | 33 +++++------ fs/xfs/xfs_file.h | 15 +++++ fs/xfs/xfs_fsmap.c | 30 ++++++++-- fs/xfs/xfs_inode.c | 29 ++++++++-- fs/xfs/xfs_inode.h | 2 + fs/xfs/xfs_inode_item.c | 32 +++++++++++ fs/xfs/xfs_ioctl.c | 12 ++++ fs/xfs/xfs_iops.c | 1 + fs/xfs/xfs_iops.h | 3 - fs/xfs/xfs_rtalloc.c | 78 +++++++++++++++++++++----- fs/xfs/xfs_symlink.c | 8 ++- 24 files changed, 351 insertions(+), 89 deletions(-) create mode 100644 fs/xfs/xfs_file.hSignature · 1 line
2.39.3