xfs: inode cleanups for metadata directories
Hi everyone,
For 6.11, here's a pile of cleanups for inode creation, directory handling, and log intent item processing. The icreate/dir cleanups are needed for metadata directories, and the log intent cleanups are for adding rmap and reflink to the realtime volume.
The very last patch in the entire patchbomb implements FITRIM for the realtime volume because a user asked.
FWIW, rt modernization are deferred to a future kernel release because recovering from LSFMM took a while and then there have been a lot of stability problems with 6.10. The last of /those/ fixes will be sent as a separate series after this patchbomb and really ought to get in before 6.10 finalizes.
--D
PATCH 1/5 xfs: hoist inode operations to libxfs
Hi all,
This series hoists inode creation, renaming, and deletion operations to libxfs in anticipation of the metadata inode directory feature, which maintains a directory tree of metadata inodes. This will be necessary for further enhancements to the realtime feature, subvolume support.
There aren't supposed to be any functional changes in this intense refactoring -- we just split the functions into pieces that are generic and pieces that are specific to libxfs clients. As a bonus, we can remove various open-coded pieces of mkfs.xfs and xfs_repair when this series gets to xfsprogs.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=inode-refactor
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=inode-refactor
---
Commits in this patchset:
* xfs: use consistent uid/gid when grabbing dquots for inodes
* xfs: move inode copy-on-write predicates to xfs_inode.[ch]
* xfs: hoist extent size helpers to libxfs
* xfs: hoist inode flag conversion functions to libxfs
* xfs: hoist project id get/set functions to libxfs
* xfs: pack icreate initialization parameters into a separate structure
* xfs: implement atime updates in xfs_trans_ichgtime
* xfs: use xfs_trans_ichgtime to set times when allocating inode
* xfs: split new inode creation into two pieces
* xfs: hoist new inode initialization functions to libxfs
* xfs: push xfs_icreate_args creation out of xfs_create*
* xfs: wrap inode creation dqalloc calls
* xfs: hoist xfs_iunlink to libxfs
* xfs: hoist xfs_{bump,drop}link to libxfs
* xfs: separate the icreate logic around INIT_XATTRS
* xfs: create libxfs helper to link a new inode into a directory
* xfs: create libxfs helper to link an existing inode into a directory
* xfs: hoist inode free function to libxfs
* xfs: create libxfs helper to remove an existing inode/name from a directory
* xfs: create libxfs helper to exchange two directory entries
* xfs: create libxfs helper to rename two directory entries
* xfs: move dirent update hooks to xfs_dir2.c
* xfs: get rid of trivial rename helpers
* xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_bmap.c | 43 + fs/xfs/libxfs/xfs_bmap.h | 3 fs/xfs/libxfs/xfs_dir2.c | 661 +++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 49 + fs/xfs/libxfs/xfs_format.h | 9 fs/xfs/libxfs/xfs_ialloc.c | 15 fs/xfs/libxfs/xfs_inode_util.c | 749 ++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 62 ++ fs/xfs/libxfs/xfs_ondisk.h | 1 fs/xfs/libxfs/xfs_shared.h | 7 fs/xfs/libxfs/xfs_trans_inode.c | 2 fs/xfs/scrub/common.c | 1 fs/xfs/scrub/tempfile.c | 21 - fs/xfs/xfs_inode.c | 1487 ++++----------------------------------- fs/xfs/xfs_inode.h | 70 -- fs/xfs/xfs_ioctl.c | 60 -- fs/xfs/xfs_iops.c | 51 + fs/xfs/xfs_linux.h | 2 fs/xfs/xfs_qm.c | 7 fs/xfs/xfs_reflink.h | 10 fs/xfs/xfs_symlink.c | 70 +- fs/xfs/xfs_trans.h | 1 23 files changed, 1837 insertions(+), 1545 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_inode_util.c create mode 100644 fs/xfs/libxfs/xfs_inode_util.h
PATCH 1/24 xfs: use consistent uid/gid when grabbing dquots for inodes
From: Darrick J. Wong <[email protected]>
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
@@ -1059,10 +1059,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)
@@ -1234,10 +1236,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
@@ -122,10 +122,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)
Re: [PATCH 01/24] xfs: use consistent uid/gid when grabbing dquots for inodes
Looks good:
PATCH 2/24 xfs: move inode copy-on-write predicates to xfs_inode.[ch]
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move these inode predicate functions to xfs_inode.[ch] since they're not reflink functions.
--- fs/xfs/xfs_inode.c | 8 ++++++++ fs/xfs/xfs_inode.h | 7 +++++++ fs/xfs/xfs_reflink.h | 10 ---------- 3 files changed, 15 insertions(+), 10 deletions(-)
fs/xfs/xfs_inode.c +8 -0
@@ -4282,3 +4282,11 @@ xfs_inode_alloc_unitsize(return XFS_FSB_TO_B (ip->i_mount, blocks); } + +/* Should we always be using copy on write for file writes? */ +bool +xfs_is_always_cow_inode ( +struct xfs_inode *ip) +{ +return ip->i_mount->m_always_cow &&xfs_has_reflink (ip->i_mount); +}
fs/xfs/xfs_inode.h +7 -0
@@ -292,6 +292,13 @@ static inline bool xfs_is_metadata_inode(struct xfs_inode *ip)xfs_is_quota_inode (&mp->m_sb, ip->i_ino); } +bool xfs_is_always_cow_inode (struct xfs_inode *ip); + +static inline bool xfs_is_cow_inode (struct xfs_inode *ip) +{ +return xfs_is_reflink_inode (ip) ||xfs_is_always_cow_inode (ip); +} +/* * Check if an inode has any data in the COW fork. This might be often false * even for inodes with the reflink flag when there is no pending COW operation.
fs/xfs/xfs_reflink.h +0 -10
@@ -6,16 +6,6 @@#ifndef __XFS_REFLINK_H#define __XFS_REFLINK_H 1 -static inline bool xfs_is_always_cow_inode (struct xfs_inode *ip) -{ -return ip->i_mount->m_always_cow &&xfs_has_reflink (ip->i_mount); -} - -static inline bool xfs_is_cow_inode (struct xfs_inode *ip) -{ -return xfs_is_reflink_inode (ip) ||xfs_is_always_cow_inode (ip); -} -extern int xfs_reflink_trim_around_shared (struct xfs_inode *ip,struct xfs_bmbt_irec *irec,bool *shared); int xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
Re: [PATCH 02/24] xfs: move inode copy-on-write predicates to xfs_inode.[ch]
Looks good:
PATCH 3/24 xfs: hoist extent size helpers to libxfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the extent size helpers to xfs_bmap.c in libxfs since they're used there already.
--- fs/xfs/libxfs/xfs_bmap.c | 42 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_bmap.h | 3 +++ fs/xfs/xfs_inode.c | 44 -------------------------------------------- fs/xfs/xfs_inode.h | 3 --- fs/xfs/xfs_iops.c | 1 + 5 files changed, 46 insertions(+), 47 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +42 -0
@@ -6454,3 +6454,45 @@ xfs_bmap_query_all(return xfs_btree_query_all (cur, xfs_bmap_query_range_helper, &query); } + +/* Helper function to extract extent size hint from inode */ +xfs_extlen_t +xfs_get_extsz_hint ( +struct xfs_inode *ip) +{ +/* +* No point in aligning allocations if we need to COW to actually +* write to them. +*/ +if (xfs_is_always_cow_inode (ip)) +return 0 ; +if ((ip->i_diflags &XFS_DIFLAG_EXTSIZE ) && ip->i_extsize) +return ip->i_extsize; +if (XFS_IS_REALTIME_INODE (ip) && + ip->i_mount->m_sb.sb_rextsize >1 ) +return ip->i_mount->m_sb.sb_rextsize; +return 0 ; +} + +/* +* Helper function to extract CoW extent size hint from inode. +* Between the extent size hint and the CoW extent size hint, we +* return the greater of the two. If the value is zero (automatic), +* use the default size. +*/ +xfs_extlen_t +xfs_get_cowextsz_hint ( +struct xfs_inode *ip) +{ +xfs_extlen_t a, b; + + a =0 ; +if (ip->i_diflags2 &XFS_DIFLAG2_COWEXTSIZE ) + a = ip->i_cowextsize; + b =xfs_get_extsz_hint (ip); + + a =max (a, b); +if (a ==0 ) +return XFS_DEFAULT_COWEXTSZ_HINT ; +return a; +}
fs/xfs/libxfs/xfs_bmap.h +3 -0
@@ -296,4 +296,7 @@ typedef int (*xfs_bmap_query_range_fn)(int xfs_bmap_query_all (struct xfs_btree_cur *cur,xfs_bmap_query_range_fn fn,void *priv); +xfs_extlen_t xfs_get_extsz_hint (struct xfs_inode *ip); +xfs_extlen_t xfs_get_cowextsz_hint (struct xfs_inode *ip); +#endif /* __XFS_BMAP_H__ */
fs/xfs/xfs_inode.c +0 -44
50 lines not on this page · raw message
fs/xfs/xfs_inode.h +0 -3
@@ -563,9 +563,6 @@ int xfs_iflush_cluster(struct xfs_buf *);void xfs_lock_two_inodes (struct xfs_inode *ip0,uint ip0_mode,struct xfs_inode *ip1,uint ip1_mode); -xfs_extlen_t xfs_get_extsz_hint (struct xfs_inode *ip); -xfs_extlen_t xfs_get_cowextsz_hint (struct xfs_inode *ip); - int xfs_init_new_inode(struct mnt_idmap *idmap, struct xfs_trans *tp, struct xfs_inode *pip, xfs_ino_t ino, umode_t mode, xfs_nlink_t nlink, dev_t rdev, prid_t prid, bool init_xattrs,
fs/xfs/xfs_iops.c +1 -0
@@ -26,6 +26,7 @@#include "xfs_ioctl.h" #include "xfs_xattr.h" #include "xfs_file.h" +#include "xfs_bmap.h" #include <linux/posix_acl.h> #include <linux/security.h>
Re: [PATCH 03/24] xfs: hoist extent size helpers to libxfs
Looks good:
PATCH 4/24 xfs: hoist inode flag conversion functions to libxfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Hoist the inode flag conversion functions into libxfs so that we can keep them in sync. Do this by creating a new xfs_inode_util.c file in libxfs.
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_bmap.c | 1 fs/xfs/libxfs/xfs_inode_util.c | 124 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 14 +++++ fs/xfs/xfs_inode.c | 49 ---------------- fs/xfs/xfs_inode.h | 2 - fs/xfs/xfs_ioctl.c | 60 ------------------- 7 files changed, 141 insertions(+), 110 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_inode_util.c create mode 100644 fs/xfs/libxfs/xfs_inode_util.h
fs/xfs/Makefile +1 -0
@@ -40,6 +40,7 @@ xfs-y += $(addprefix libxfs/, \ xfs_iext_tree.o \ xfs_inode_fork.o \ xfs_inode_buf.o \ + xfs_inode_util.o \ xfs_log_rlimit.o \ xfs_ag_resv.o \ xfs_parent.o \
fs/xfs/libxfs/xfs_bmap.c +1 -0
@@ -39,6 +39,7 @@#include "xfs_health.h" #include "xfs_bmap_item.h" #include "xfs_symlink_remote.h" +#include "xfs_inode_util.h" struct kmem_cache *xfs_bmap_intent_cache;
fs/xfs/libxfs/xfs_inode_util.c new file +124 -0
124 lines not on this page · raw message
fs/xfs/libxfs/xfs_inode_util.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. +* All Rights Reserved. +*/ +#ifndef __XFS_INODE_UTIL_H__ +#define __XFS_INODE_UTIL_H__ + +uint16_t xfs_flags2diflags (struct xfs_inode *ip,unsigned int xflags); +uint64_t xfs_flags2diflags2 (struct xfs_inode *ip,unsigned int xflags); +uint32_t xfs_dic2xflags (struct xfs_inode *ip); +uint32_t xfs_ip2xflags (struct xfs_inode *ip); + +#endif /* __XFS_INODE_UTIL_H__ */
fs/xfs/xfs_inode.c +0 -49
55 lines not on this page · raw message
fs/xfs/xfs_inode.h +1 -1
@@ -8,6 +8,7 @@#include "xfs_inode_buf.h" #include "xfs_inode_fork.h" +#include "xfs_inode_util.h" /* * Kernel only inode definitions
@@ -549,7 +550,6 @@ void xfs_assert_ilocked(struct xfs_inode *, uint);uint xfs_ilock_data_map_shared (struct xfs_inode *);uint xfs_ilock_attr_map_shared (struct xfs_inode *); -uint xfs_ip2xflags (struct xfs_inode *);int xfs_ifree (struct xfs_trans *,struct xfs_inode *);int xfs_itruncate_extents_flags (struct xfs_trans **,struct xfs_inode *,int ,xfs_fsize_t ,int );
fs/xfs/xfs_ioctl.c +0 -60
66 lines not on this page · raw message
Re: [PATCH 04/24] xfs: hoist inode flag conversion functions to libxfs
Looks good:
PATCH 5/24 xfs: hoist project id get/set functions to libxfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the project id get and set functions into libxfs.
--- fs/xfs/libxfs/xfs_inode_util.c | 10 ++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 2 ++ fs/xfs/xfs_inode.h | 9 --------- fs/xfs/xfs_linux.h | 2 -- 4 files changed, 12 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +10 -0
@@ -122,3 +122,13 @@ xfs_ip2xflags( flags |=FS_XFLAG_HASATTR ;return flags; } + +prid_t +xfs_get_initial_prid (struct xfs_inode *dp) +{ +if (dp->i_diflags &XFS_DIFLAG_PROJINHERIT ) +return dp->i_projid; + +/* Assign to the root project by default. */ +return 0 ; +}
fs/xfs/libxfs/xfs_inode_util.h +2 -0
@@ -11,4 +11,6 @@ uint64_t xfs_flags2diflags2(struct xfs_inode *ip, unsigned int xflags);uint32_t xfs_dic2xflags (struct xfs_inode *ip);uint32_t xfs_ip2xflags (struct xfs_inode *ip); +prid_t xfs_get_initial_prid (struct xfs_inode *dp); +#endif /* __XFS_INODE_UTIL_H__ */
fs/xfs/xfs_inode.h +0 -9
@@ -271,15 +271,6 @@ xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned long flags)return ret; } -static inline prid_t -xfs_get_initial_prid (struct xfs_inode *dp) -{ -if (dp->i_diflags &XFS_DIFLAG_PROJINHERIT ) -return dp->i_projid; - -return XFS_PROJID_DEFAULT ; -} -static inline bool xfs_is_reflink_inode (struct xfs_inode *ip) {return ip->i_diflags2 &XFS_DIFLAG2_REFLINK ;
fs/xfs/xfs_linux.h +0 -2
@@ -135,8 +135,6 @@ typedef __u32 xfs_nlink_t;*/ #define __this_address ({ __label__ __here; __here: barrier(); &&__here; }) -#define XFS_PROJID_DEFAULT 0 -#define howmany (x, y) (((x)+((y)-1))/(y))static inline void delay (long ticks)
Re: [PATCH 05/24] xfs: hoist project id get/set functions to libxfs
Looks good:
PATCH 6/24 xfs: pack icreate initialization parameters into a separate structure
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Callers that want to create an inode currently pass all possible file attribute values for the new inode into xfs_init_new_inode as ten separate parameters. This causes two code maintenance issues: first, we have large multi-line call sites which programmers must read carefully to make sure they did not accidentally invert a value. Second, all three file id parameters must be passed separately to the quota functions; any discrepancy results in quota count errors.
Clean this up by creating a new icreate_args structure to hold all this information, some helpers to initialize them properly, and make the callers pass this structure through to the creation function, whose name we shorten to xfs_icreate. This eliminates the issues, enables us to keep the inode init code in sync with userspace via libxfs, and is needed for future metadata directory tree management.
(A subsequent cleanup will also fix the quota alloc calls.)
--- fs/xfs/libxfs/xfs_inode_util.h | 22 ++++++++++ fs/xfs/scrub/tempfile.c | 12 +++-- fs/xfs/xfs_inode.c | 89 ++++++++++++++++++++++++++-------------- fs/xfs/xfs_inode.h | 6 +-- fs/xfs/xfs_qm.c | 6 ++- fs/xfs/xfs_symlink.c | 12 ++++- 6 files changed, 101 insertions(+), 46 deletions(-)
fs/xfs/libxfs/xfs_inode_util.h +22 -0
@@ -13,4 +13,26 @@ uint32_t xfs_ip2xflags(struct xfs_inode *ip);prid_t xfs_get_initial_prid (struct xfs_inode *dp); +/* +* File creation context. +* +* Due to our only partial reliance on the VFS to propagate uid and gid values +* according to accepted Unix behaviors, callers must initialize idmap to the +* correct idmapping structure to get the correct inheritance behaviors when +* XFS_MOUNT_GRPID is set. +* +* To create files detached from the directory tree (e.g. quota inodes), set +* idmap to NULL. To create a tree root, set pip to NULL. +*/ +struct xfs_icreate_args { +struct mnt_idmap *idmap; +struct xfs_inode *pip;/* parent inode or null */ +dev_t rdev; +umode_t mode; + +#define XFS_ICREATE_TMPFILE (1U << 0)/* create an unlinked file */ +#define XFS_ICREATE_INIT_XATTRS (1U << 1)/* will set xattrs immediately */ +uint16_t flags; +}; +#endif /* __XFS_INODE_UTIL_H__ */
fs/xfs/scrub/tempfile.c +7 -5
@@ -40,6 +40,11 @@ xrep_tempfile_create( struct xfs_scrub *sc, uint16_t mode) { +struct xfs_icreate_args args = { + .pip = sc->mp->m_rootip, + .mode = mode, + .flags =XFS_ICREATE_TMPFILE , + };struct xfs_mount *mp = sc->mp;struct xfs_trans *tp =NULL ;struct xfs_dquot *udqp =NULL ;
@@ -87,14 +92,11 @@ xrep_tempfile_create( error =xfs_dialloc (&tp, dp->i_ino, mode, &ino);if (error) goto out_trans_cancel; - error =xfs_init_new_inode (&nop_mnt_idmap, tp, dp, ino, mode,0 ,0 , -0 , false, &sc->tempip); + error =xfs_icreate (tp, ino, &args, &sc->tempip);if (error) goto out_trans_cancel; -/* Change the ownership of the inode to root. */ -VFS_I (sc->tempip)->i_uid =GLOBAL_ROOT_UID ; -VFS_I (sc->tempip)->i_gid =GLOBAL_ROOT_GID ; +/* We don't touch file data, so drop the realtime flags. */ sc->tempip->i_diflags &= ~(XFS_DIFLAG_REALTIME |XFS_DIFLAG_RTINHERIT );xfs_trans_log_inode (tp, sc->tempip,XFS_ILOG_CORE );
fs/xfs/xfs_inode.c +57 -32
155 lines not on this page · raw message
fs/xfs/xfs_inode.h +2 -4
@@ -554,10 +554,8 @@ int xfs_iflush_cluster(struct xfs_buf *);void xfs_lock_two_inodes (struct xfs_inode *ip0,uint ip0_mode,struct xfs_inode *ip1,uint ip1_mode); -int xfs_init_new_inode (struct mnt_idmap *idmap,struct xfs_trans *tp, -struct xfs_inode *pip,xfs_ino_t ino,umode_t mode, -xfs_nlink_t nlink,dev_t rdev,prid_t prid,bool init_xattrs, -struct xfs_inode **ipp); +int xfs_icreate (struct xfs_trans *tp,xfs_ino_t ino, +const struct xfs_icreate_args *args,struct xfs_inode **ipp);static inline int xfs_itruncate_extents(
fs/xfs/xfs_qm.c +4 -2
@@ -793,12 +793,14 @@ xfs_qm_qino_alloc(return error;if (need_alloc) { +struct xfs_icreate_args args = { + .mode =S_IFREG , + };xfs_ino_t ino; error =xfs_dialloc (&tp,0 ,S_IFREG , &ino);if (!error) - error =xfs_init_new_inode (&nop_mnt_idmap, tp,NULL , ino, -S_IFREG ,1 ,0 ,0 , false, ipp); + error =xfs_icreate (tp, ino, &args, ipp);if (error) {xfs_trans_cancel (tp);return error;
fs/xfs/xfs_symlink.c +9 -3
@@ -90,6 +90,11 @@ xfs_symlink( struct xfs_inode **ipp) {struct xfs_mount *mp = dp->i_mount; +struct xfs_icreate_args args = { + .idmap = idmap, + .pip = dp, + .mode =S_IFLNK | (mode & ~S_IFMT ), + };struct xfs_trans *tp =NULL ;struct xfs_inode *ip =NULL ;int error =0 ;
@@ -111,6 +116,9 @@ xfs_symlink(if (xfs_is_shutdown (mp))return -EIO ; +if (xfs_has_parent (mp)) + args.flags |=XFS_ICREATE_INIT_XATTRS ; +/* * Check component lengths of the target path name. */
@@ -170,9 +178,7 @@ xfs_symlink(*/ error =xfs_dialloc (&tp, dp->i_ino,S_IFLNK , &ino);if (!error) - error =xfs_init_new_inode (idmap, tp, dp, ino, -S_IFLNK | (mode & ~S_IFMT ),1 ,0 , prid, -xfs_has_parent (mp), &ip); + error =xfs_icreate (tp, ino, &args, &ip);if (error) goto out_trans_cancel;
Re: [PATCH 06/24] xfs: pack icreate initialization parameters into a separate structure
Looks good:
PATCH 7/24 xfs: implement atime updates in xfs_trans_ichgtime
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable xfs_trans_ichgtime to change the inode access time so that we can use this function to set inode times when allocating inodes instead of open-coding it.
--- fs/xfs/libxfs/xfs_shared.h | 1 + fs/xfs/libxfs/xfs_trans_inode.c | 2 ++ 2 files changed, 3 insertions(+)
fs/xfs/libxfs/xfs_shared.h +1 -0
@@ -183,6 +183,7 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,#define XFS_ICHGTIME_MOD 0x1/* data fork modification timestamp */ #define XFS_ICHGTIME_CHG 0x2/* inode field change timestamp */ #define XFS_ICHGTIME_CREATE 0x4/* inode create timestamp */ +#define XFS_ICHGTIME_ACCESS 0x8/* last access timestamp */ /* Computed inode geometry for the filesystem. */ struct xfs_ino_geometry {
fs/xfs/libxfs/xfs_trans_inode.c +2 -0
@@ -68,6 +68,8 @@ xfs_trans_ichgtime(inode_set_mtime_to_ts (inode, tv);if (flags &XFS_ICHGTIME_CHG )inode_set_ctime_to_ts (inode, tv); +if (flags &XFS_ICHGTIME_ACCESS ) +inode_set_atime_to_ts (inode, tv);if (flags &XFS_ICHGTIME_CREATE ) ip->i_crtime = tv; }
Re: [PATCH 07/24] xfs: implement atime updates in xfs_trans_ichgtime
Looks good:
PATCH 8/24 xfs: use xfs_trans_ichgtime to set times when allocating inode
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use xfs_trans_ichgtime to set the inode times when allocating an inode, instead of open-coding them here.
--- fs/xfs/xfs_inode.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/xfs/xfs_inode.c +7 -8
@@ -672,10 +672,11 @@ xfs_icreate(struct inode *dir = pip ?VFS_I (pip) :NULL ;struct xfs_mount *mp = tp->t_mountp;struct xfs_inode *ip; -unsigned int flags; -int error; -struct timespec64 tv;struct inode *inode; +unsigned int flags; +int times =XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG | +XFS_ICHGTIME_ACCESS ; +int error;/* * Protect against obviously corrupt allocation btree records. Later
@@ -743,19 +744,17 @@ xfs_icreate( ip->i_df.if_nextents =0 ;ASSERT (ip->i_nblocks ==0 ); - tv =inode_set_ctime_current (inode); -inode_set_mtime_to_ts (inode, tv); -inode_set_atime_to_ts (inode, tv); - ip->i_extsize =0 ; ip->i_diflags =0 ;if (xfs_has_v3inodes (mp)) {inode_set_iversion (inode,1 ); ip->i_cowextsize =0 ; - ip->i_crtime = tv; + times |=XFS_ICHGTIME_CREATE ; } +xfs_trans_ichgtime (tp, ip, times); + flags =XFS_ILOG_CORE ;switch (args->mode &S_IFMT ) {case S_IFIFO :
Re: [PATCH 08/24] xfs: use xfs_trans_ichgtime to set times when allocating inode
Looks good:
PATCH 9/24 xfs: split new inode creation into two pieces
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
There are two parts to initializing a newly allocated inode: setting up the incore structures, and initializing the new inode core based on the parent inode and the current user's environment. The initialization code is not specific to the kernel, so we would like to share that with userspace by hoisting it to libxfs. Therefore, split xfs_icreate into separate functions to prepare for the next few patches.
--- fs/xfs/libxfs/xfs_ialloc.c | 15 +++++++++ fs/xfs/xfs_inode.c | 77 ++++++++++++++++++++------------------------ 2 files changed, 50 insertions(+), 42 deletions(-)
fs/xfs/libxfs/xfs_ialloc.c +15 -0
@@ -1946,6 +1946,21 @@ xfs_dialloc( }return -ENOSPC ; } + +/* +* Protect against obviously corrupt allocation btree records. Later +* xfs_iget checks will catch re-allocation of other active in-memory +* and on-disk inodes. If we don't catch reallocating the parent inode +* here we will deadlock in xfs_iget() so we have to do these checks +* first. +*/ +if (ino == parent || !xfs_verify_dir_ino (mp, ino)) { +xfs_alert (mp,"Allocated a known in-use inode 0x%llx!" , ino); +xfs_agno_mark_sick (mp,XFS_INO_TO_AGNO (mp, ino), +XFS_SICK_AG_INOBT ); +return -EFSCORRUPTED ; + } + *new_ino = ino;return 0 ; }
fs/xfs/xfs_inode.c +35 -42
99 lines not on this page · raw message
Re: [PATCH 09/24] xfs: split new inode creation into two pieces
Looks good:
PATCH 10/24 xfs: hoist new inode initialization functions to libxfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move all the code that initializes a new inode's attributes from the icreate_args structure and the parent directory into libxfs.
--- fs/xfs/libxfs/xfs_inode_util.c | 212 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 12 ++ fs/xfs/libxfs/xfs_shared.h | 8 -- fs/xfs/xfs_inode.c | 209 --------------------------------------- fs/xfs/xfs_trans.h | 1 5 files changed, 225 insertions(+), 217 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +212 -0
@@ -3,6 +3,7 @@* Copyright (c) 2000-2006 Silicon Graphics, Inc. * All Rights Reserved. */ +#include <linux/iversion.h> #include "xfs.h" #include "xfs_fs.h" #include "xfs_shared.h"
@@ -13,6 +14,10 @@#include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_inode_util.h" +#include "xfs_trans.h" +#include "xfs_ialloc.h" +#include "xfs_health.h" +#include "xfs_bmap.h" uint16_t xfs_flags2diflags(
@@ -132,3 +137,210 @@ xfs_get_initial_prid(struct xfs_inode *dp)/* Assign to the root project by default. */ return 0 ; } + +/* Propagate di_flags from a parent inode to a child inode. */ +static inline void +xfs_inode_inherit_flags ( +struct xfs_inode *ip, +const struct xfs_inode *pip) +{ +unsigned int di_flags =0 ; +xfs_failaddr_t failaddr; +umode_t mode =VFS_I (ip)->i_mode; + +if (S_ISDIR (mode)) { +if (pip->i_diflags &XFS_DIFLAG_RTINHERIT ) + di_flags |=XFS_DIFLAG_RTINHERIT ; +if (pip->i_diflags &XFS_DIFLAG_EXTSZINHERIT ) { + di_flags |=XFS_DIFLAG_EXTSZINHERIT ; + ip->i_extsize = pip->i_extsize; + } +if (pip->i_diflags &XFS_DIFLAG_PROJINHERIT ) + di_flags |=XFS_DIFLAG_PROJINHERIT ; + }else if (S_ISREG (mode)) { +if ((pip->i_diflags &XFS_DIFLAG_RTINHERIT ) && +xfs_has_realtime (ip->i_mount)) + di_flags |=XFS_DIFLAG_REALTIME ; +if (pip->i_diflags &XFS_DIFLAG_EXTSZINHERIT ) { + di_flags |=XFS_DIFLAG_EXTSIZE ; + ip->i_extsize = pip->i_extsize; + } + } +if ((pip->i_diflags &XFS_DIFLAG_NOATIME ) && + xfs_inherit_noatime) + di_flags |=XFS_DIFLAG_NOATIME ; +if ((pip->i_diflags &XFS_DIFLAG_NODUMP ) && + xfs_inherit_nodump) + di_flags |=XFS_DIFLAG_NODUMP ; +if ((pip->i_diflags &XFS_DIFLAG_SYNC ) && + xfs_inherit_sync) + di_flags |=XFS_DIFLAG_SYNC ; +if ((pip->i_diflags &XFS_DIFLAG_NOSYMLINKS ) && + xfs_inherit_nosymlinks) + di_flags |=XFS_DIFLAG_NOSYMLINKS ; +if ((pip->i_diflags &XFS_DIFLAG_NODEFRAG ) && + xfs_inherit_nodefrag) + di_flags |=XFS_DIFLAG_NODEFRAG ; +if (pip->i_diflags &XFS_DIFLAG_FILESTREAM ) + di_flags |=XFS_DIFLAG_FILESTREAM ; + + ip->i_diflags |= di_flags; + +/* +* Inode verifiers on older kernels only check that the extent size +* hint is an integer multiple of the rt extent size on realtime files. +* They did not check the hint alignment on a directory with both +* rtinherit and extszinherit flags set. If the misaligned hint is +* propagated from a directory into a new realtime file, new file +* allocations will fail due to math errors in the rt allocator and/or +* trip the verifiers. Validate the hint settings in the new file so +* that we don't let broken hints propagate. +*/ + failaddr =xfs_inode_validate_extsize (ip->i_mount, ip->i_extsize, +VFS_I (ip)->i_mode, ip->i_diflags); +if (failaddr) { + ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE | +XFS_DIFLAG_EXTSZINHERIT ); + ip->i_extsize =0 ; + } +} + +/* Propagate di_flags2 from a parent inode to a child inode. */ +static inline void +xfs_inode_inherit_flags2 ( +struct xfs_inode *ip, +const struct xfs_inode *pip) +{ +xfs_failaddr_t failaddr; + +if (pip->i_diflags2 &XFS_DIFLAG2_COWEXTSIZE ) { + ip->i_diflags2 |=XFS_DIFLAG2_COWEXTSIZE ; + ip->i_cowextsize = pip->i_cowextsize; + } +if (pip->i_diflags2 &XFS_DIFLAG2_DAX ) + ip->i_diflags2 |=XFS_DIFLAG2_DAX ; + +/* Don't let invalid cowextsize hints propagate. */ + failaddr =xfs_inode_validate_cowextsize (ip->i_mount, ip->i_cowextsize, +VFS_I (ip)->i_mode, ip->i_diflags, ip->i_diflags2); +if (failaddr) { + ip->i_diflags2 &= ~XFS_DIFLAG2_COWEXTSIZE ; + ip->i_cowextsize =0 ; + } +} + +/* Initialise an inode's attributes. */ +void +xfs_inode_init ( +struct xfs_trans *tp, +const struct xfs_icreate_args *args, +struct xfs_inode *ip) +{ +struct xfs_inode *pip = args->pip; +struct inode *dir = pip ?VFS_I (pip) :NULL ; +struct xfs_mount *mp = tp->t_mountp; +struct inode *inode =VFS_I (ip); +unsigned int flags; +int times =XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG | +XFS_ICHGTIME_ACCESS ; + +if (args->flags &XFS_ICREATE_TMPFILE ) +set_nlink (inode,0 ); +else if (S_ISDIR (args->mode)) +set_nlink (inode,2 ); +else +set_nlink (inode,1 ); + inode->i_rdev = args->rdev; + +if (!args->idmap || pip ==NULL ) { +/* creating a tree root, sb rooted, or detached file */ + inode->i_uid =GLOBAL_ROOT_UID ; + inode->i_gid =GLOBAL_ROOT_GID ; + ip->i_projid =0 ; + inode->i_mode = args->mode; + }else { +/* creating a child in the directory tree */ +if (dir && !(dir->i_mode &S_ISGID ) &&xfs_has_grpid (mp)) { +inode_fsuid_set (inode, args->idmap); + inode->i_gid = dir->i_gid; + inode->i_mode = args->mode; + }else { +inode_init_owner (args->idmap, inode, dir, args->mode); + } + +/* +* If the group ID of the new file does not match the effective +* group ID or one of the supplementary group IDs, the S_ISGID +* bit is cleared (and only if the irix_sgid_inherit +* compatibility variable is set). +*/ +if (irix_sgid_inherit && (inode->i_mode &S_ISGID ) && + !vfsgid_in_group_p (i_gid_into_vfsgid (args->idmap, inode))) + inode->i_mode &= ~S_ISGID ; + + ip->i_projid = pip ?xfs_get_initial_prid (pip) :0 ; + } + + ip->i_disk_size =0 ; + ip->i_df.if_nextents =0 ; +ASSERT (ip->i_nblocks ==0 ); + + ip->i_extsize =0 ; + ip->i_diflags =0 ; + +if (xfs_has_v3inodes (mp)) { +inode_set_iversion (inode,1 ); + ip->i_cowextsize =0 ; + times |=XFS_ICHGTIME_CREATE ; + } + +xfs_trans_ichgtime (tp, ip, times); + + flags =XFS_ILOG_CORE ; +switch (args->mode &S_IFMT ) { +case S_IFIFO : +case S_IFCHR : +case S_IFBLK : +case S_IFSOCK : + ip->i_df.if_format =XFS_DINODE_FMT_DEV ; + flags |=XFS_ILOG_DEV ; +break ; +case S_IFREG : +case S_IFDIR : +if (pip && (pip->i_diflags &XFS_DIFLAG_ANY )) +xfs_inode_inherit_flags (ip, pip); +if (pip && (pip->i_diflags2 &XFS_DIFLAG2_ANY )) +xfs_inode_inherit_flags2 (ip, pip); + fallthrough; +case S_IFLNK : + ip->i_df.if_format =XFS_DINODE_FMT_EXTENTS ; + ip->i_df.if_bytes =0 ; + ip->i_df.if_data =NULL ; +break ; +default : +ASSERT (0 ); + } + +/* +* If we need to create attributes immediately after allocating the +* inode, initialise an empty attribute fork right now. We use the +* default fork offset for attributes here as we don't know exactly what +* size or how many attributes we might be adding. We can do this +* safely here because we know the data fork is completely empty and +* this saves us from needing to run a separate transaction to set the +* fork offset in the immediate future. +*/ +if (args->flags &XFS_ICREATE_INIT_XATTRS ) { + ip->i_forkoff =xfs_default_attroffset (ip) >>3 ; +xfs_ifork_init_attr (ip,XFS_DINODE_FMT_EXTENTS ,0 ); + +if (!xfs_has_attr (mp)) { +spin_lock (&mp->m_sb_lock); +xfs_add_attr (mp); +spin_unlock (&mp->m_sb_lock); +xfs_log_sb (tp); + } + } + +xfs_trans_log_inode (tp, ip, flags); +}
fs/xfs/libxfs/xfs_inode_util.h +12 -0
@@ -35,4 +35,16 @@ struct xfs_icreate_args { uint16_t flags; }; +/* +* Flags for xfs_trans_ichgtime(). +*/ +#define XFS_ICHGTIME_MOD 0x1/* data fork modification timestamp */ +#define XFS_ICHGTIME_CHG 0x2/* inode field change timestamp */ +#define XFS_ICHGTIME_CREATE 0x4/* inode create timestamp */ +#define XFS_ICHGTIME_ACCESS 0x8/* last access timestamp */ +void xfs_trans_ichgtime (struct xfs_trans *tp,struct xfs_inode *ip,int flags); + +void xfs_inode_init (struct xfs_trans *tp,const struct xfs_icreate_args *args, +struct xfs_inode *ip); +#endif /* __XFS_INODE_UTIL_H__ */
fs/xfs/libxfs/xfs_shared.h +0 -8
@@ -177,14 +177,6 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,#define XFS_REFC_BTREE_REF 1#define XFS_SSB_REF 0 -/* -* Flags for xfs_trans_ichgtime(). -*/ -#define XFS_ICHGTIME_MOD 0x1/* data fork modification timestamp */ -#define XFS_ICHGTIME_CHG 0x2/* inode field change timestamp */ -#define XFS_ICHGTIME_CREATE 0x4/* inode create timestamp */ -#define XFS_ICHGTIME_ACCESS 0x8/* last access timestamp */ -/* Computed inode geometry for the filesystem. */ struct xfs_ino_geometry {/* Maximum inode count in this filesystem. */
fs/xfs/xfs_inode.c +1 -208
221 lines not on this page · raw message
fs/xfs/xfs_trans.h +0 -1
@@ -224,7 +224,6 @@ void xfs_trans_stale_inode_buf(xfs_trans_t *, struct xfs_buf *);bool xfs_trans_ordered_buf (xfs_trans_t *,struct xfs_buf *);void xfs_trans_dquot_buf (xfs_trans_t *,struct xfs_buf *,uint );void xfs_trans_inode_alloc_buf (xfs_trans_t *,struct xfs_buf *); -void xfs_trans_ichgtime (struct xfs_trans *,struct xfs_inode *,int );void xfs_trans_ijoin (struct xfs_trans *,struct xfs_inode *,uint );void xfs_trans_log_buf (struct xfs_trans *,struct xfs_buf *,uint ,uint );
Re: [PATCH 10/24] xfs: hoist new inode initialization functions to libxfs
Looks good:
PATCH 11/24 xfs: push xfs_icreate_args creation out of xfs_create*
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the initialization of the xfs_icreate_args structure out of xfs_create and xfs_create_tempfile into their callers so that we can set the new inode's attributes in one place and pass that through instead of open coding the collection of attributes all over the code.
--- fs/xfs/xfs_inode.c | 86 ++++++++++++++++++++++++---------------------------- fs/xfs/xfs_inode.h | 9 ++--- fs/xfs/xfs_iops.c | 41 +++++++++++++++---------- 3 files changed, 66 insertions(+), 70 deletions(-)
fs/xfs/xfs_inode.c +39 -47
@@ -730,35 +730,25 @@ xfs_dir_hook_setup(int xfs_create ( -struct mnt_idmap *idmap, -struct xfs_inode *dp, +const struct xfs_icreate_args *args,struct xfs_name *name, -umode_t mode, -dev_t rdev, -bool init_xattrs, -xfs_inode_t **ipp) +struct xfs_inode **ipp) { -struct xfs_icreate_args args = { - .idmap = idmap, - .pip = dp, - .rdev = rdev, - .mode = mode, - .flags = init_xattrs ?XFS_ICREATE_INIT_XATTRS :0 , - }; -int is_dir =S_ISDIR (mode); +struct xfs_inode *dp = args->pip;struct xfs_mount *mp = dp->i_mount;struct xfs_inode *ip =NULL ;struct xfs_trans *tp =NULL ; -int error; +struct xfs_dquot *udqp =NULL ; +struct xfs_dquot *gdqp =NULL ; +struct xfs_dquot *pdqp =NULL ; +struct xfs_trans_res *tres; +struct xfs_parent_args *ppargs; +xfs_ino_t ino; +prid_t prid;bool unlock_dp_on_error = false; -prid_t prid; -struct xfs_dquot *udqp =NULL ; -struct xfs_dquot *gdqp =NULL ; -struct xfs_dquot *pdqp =NULL ; -struct xfs_trans_res *tres; +bool is_dir =S_ISDIR (args->mode);uint resblks; -xfs_ino_t ino; -struct xfs_parent_args *ppargs; +int error;trace_xfs_create (dp, name);
@@ -774,8 +764,9 @@ xfs_create(* 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,i_user_ns (VFS_I (dp))), -mapped_fsgid (idmap,i_user_ns (VFS_I (dp))), prid, + error =xfs_qm_vop_dqalloc (dp, +mapped_fsuid (args->idmap,i_user_ns (VFS_I (dp))), +mapped_fsgid (args->idmap,i_user_ns (VFS_I (dp))), prid,XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , &udqp, &gdqp, &pdqp);if (error)
@@ -818,9 +809,9 @@ xfs_create(* entry pointing to them, but a directory also the "." entry * pointing to itself. */ - error =xfs_dialloc (&tp, dp->i_ino, mode, &ino); + error =xfs_dialloc (&tp, dp->i_ino, args->mode, &ino);if (!error) - error =xfs_icreate (tp, ino, &args, &ip); + error =xfs_icreate (tp, ino, args, &ip);if (error) goto out_trans_cancel;
@@ -922,44 +913,37 @@ xfs_create(int xfs_create_tmpfile ( -struct mnt_idmap *idmap, -struct xfs_inode *dp, -umode_t mode, -bool init_xattrs, +const struct xfs_icreate_args *args,struct xfs_inode **ipp) { -struct xfs_icreate_args args = { - .idmap = idmap, - .pip = dp, - .mode = mode, - .flags =XFS_ICREATE_TMPFILE , - }; +struct xfs_inode *dp = args->pip;struct xfs_mount *mp = dp->i_mount;struct xfs_inode *ip =NULL ;struct xfs_trans *tp =NULL ; -int error; -prid_t prid;struct xfs_dquot *udqp =NULL ;struct xfs_dquot *gdqp =NULL ;struct xfs_dquot *pdqp =NULL ;struct xfs_trans_res *tres; -uint resblks;xfs_ino_t ino; +prid_t prid; +uint resblks; +int error; + +ASSERT (args->flags &XFS_ICREATE_TMPFILE );if (xfs_is_shutdown (mp))return -EIO ; prid =xfs_get_initial_prid (dp); -if (init_xattrs) - args.flags |=XFS_ICREATE_INIT_XATTRS ;/* * 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,i_user_ns (VFS_I (dp))), -mapped_fsgid (idmap,i_user_ns (VFS_I (dp))), prid, + error =xfs_qm_vop_dqalloc (dp, +mapped_fsuid (args->idmap,i_user_ns (VFS_I (dp))), +mapped_fsgid (args->idmap,i_user_ns (VFS_I (dp))), prid,XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , &udqp, &gdqp, &pdqp);if (error)
@@ -973,9 +957,9 @@ xfs_create_tmpfile(if (error) goto out_release_dquots; - error =xfs_dialloc (&tp, dp->i_ino, mode, &ino); + error =xfs_dialloc (&tp, dp->i_ino, args->mode, &ino);if (!error) - error =xfs_icreate (tp, ino, &args, &ip); + error =xfs_icreate (tp, ino, args, &ip);if (error) goto out_trans_cancel;
@@ -2839,12 +2823,20 @@ xfs_rename_alloc_whiteout(struct xfs_inode *dp, struct xfs_inode **wip) { + struct xfs_icreate_args args = { + .idmap = idmap, + .pip = dp, + .mode =S_IFCHR |WHITEOUT_MODE , + .flags =XFS_ICREATE_TMPFILE , + };struct xfs_inode *tmpfile;struct qstr name;int error; - error =xfs_create_tmpfile (idmap, dp,S_IFCHR |WHITEOUT_MODE , -xfs_has_parent (dp->i_mount), &tmpfile); +if (xfs_has_parent (dp->i_mount)) + args.flags |=XFS_ICREATE_INIT_XATTRS ; + + error =xfs_create_tmpfile (&args, &tmpfile);if (error)return error;
fs/xfs/xfs_inode.h +3 -6
@@ -516,12 +516,9 @@ int xfs_release(struct xfs_inode *ip);int xfs_inactive (struct xfs_inode *ip);int xfs_lookup (struct xfs_inode *dp,const struct xfs_name *name,struct xfs_inode **ipp,struct xfs_name *ci_name); -int xfs_create (struct mnt_idmap *idmap, -struct xfs_inode *dp,struct xfs_name *name, -umode_t mode,dev_t rdev,bool need_xattr, -struct xfs_inode **ipp); -int xfs_create_tmpfile (struct mnt_idmap *idmap, -struct xfs_inode *dp,umode_t mode,bool init_xattrs, +int xfs_create (const struct xfs_icreate_args *iargs, +struct xfs_name *name,struct xfs_inode **ipp); +int xfs_create_tmpfile (const struct xfs_icreate_args *iargs,struct xfs_inode **ipp);int xfs_remove (struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode *ip);
fs/xfs/xfs_iops.c +24 -17
72 lines not on this page · raw message
Re: [PATCH 11/24] xfs: push xfs_icreate_args creation out of xfs_create*
Looks good:
PATCH 12/24 xfs: wrap inode creation dqalloc calls
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a helper that calls dqalloc to allocate and grab a reference to dquots for the user, group, and project ids listed in an icreate structure. This simplifies the creat-related dqalloc callsites scattered around the code base.
--- fs/xfs/scrub/tempfile.c | 9 +++--- fs/xfs/xfs_inode.c | 74 +++++++++++++++++++++++++++-------------------- fs/xfs/xfs_inode.h | 4 +++ fs/xfs/xfs_symlink.c | 20 +++---------- 4 files changed, 55 insertions(+), 52 deletions(-)
fs/xfs/scrub/tempfile.c +4 -5
@@ -47,9 +47,9 @@ xrep_tempfile_create( };struct xfs_mount *mp = sc->mp;struct xfs_trans *tp =NULL ; -struct xfs_dquot *udqp =NULL ; -struct xfs_dquot *gdqp =NULL ; -struct xfs_dquot *pdqp =NULL ; +struct xfs_dquot *udqp; +struct xfs_dquot *gdqp; +struct xfs_dquot *pdqp;struct xfs_trans_res *tres;struct xfs_inode *dp = mp->m_rootip;xfs_ino_t ino;
@@ -70,8 +70,7 @@ xrep_tempfile_create(* inode should be completely root owned so that we don't fail due to * quota limits. */ - error =xfs_qm_vop_dqalloc (dp,GLOBAL_ROOT_UID ,GLOBAL_ROOT_GID ,0 , -XFS_QMOPT_QUOTALL , &udqp, &gdqp, &pdqp); + error =xfs_icreate_dqalloc (&args, &udqp, &gdqp, &pdqp);if (error)return error;
fs/xfs/xfs_inode.c +42 -32
109 lines not on this page · raw message
fs/xfs/xfs_inode.h +4 -0
@@ -660,4 +660,8 @@ void xfs_dir_hook_setup(struct xfs_dir_hook *hook, notifier_fn_t mod_fn);# define xfs_dir_update_hook (dp, ip, delta, name) ((void)0)#endif /* CONFIG_XFS_LIVE_HOOKS */ +int xfs_icreate_dqalloc (const struct xfs_icreate_args *args, +struct xfs_dquot **udqpp,struct xfs_dquot **gdqpp, +struct xfs_dquot **pdqpp); +#endif /* __XFS_INODE_H__ */
fs/xfs/xfs_symlink.c +5 -15
@@ -101,10 +101,9 @@ xfs_symlink(int pathlen;bool unlock_dp_on_error = false;xfs_filblks_t fs_blocks; -prid_t prid; -struct xfs_dquot *udqp =NULL ; -struct xfs_dquot *gdqp =NULL ; -struct xfs_dquot *pdqp =NULL ; +struct xfs_dquot *udqp; +struct xfs_dquot *gdqp; +struct xfs_dquot *pdqp;uint resblks;xfs_ino_t ino;struct xfs_parent_args *ppargs;
@@ -127,17 +126,8 @@ xfs_symlink(return -ENAMETOOLONG ;ASSERT (pathlen >0 ); - prid =xfs_get_initial_prid (dp); - -/* -* 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,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); +/* Make sure that we have allocated dquot(s) on disk. */ + error =xfs_icreate_dqalloc (&args, &udqp, &gdqp, &pdqp);if (error)return error;
Re: [PATCH 12/24] xfs: wrap inode creation dqalloc calls
Looks good:
PATCH 13/24 xfs: hoist xfs_iunlink to libxfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move xfs_iunlink and xfs_iunlink_remove to libxfs.
--- fs/xfs/libxfs/xfs_inode_util.c | 282 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 4 + fs/xfs/xfs_inode.c | 280 ---------------------------------------- fs/xfs/xfs_inode.h | 5 - 4 files changed, 289 insertions(+), 282 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +282 -0
@@ -18,6 +18,10 @@#include "xfs_ialloc.h" #include "xfs_health.h" #include "xfs_bmap.h" +#include "xfs_error.h" +#include "xfs_trace.h" +#include "xfs_ag.h" +#include "xfs_iunlink_item.h" uint16_t xfs_flags2diflags(
@@ -344,3 +348,281 @@ xfs_inode_init(xfs_trans_log_inode (tp, ip, flags); } + +/* +* In-Core Unlinked List Lookups +* ============================= +* +* Every inode is supposed to be reachable from some other piece of metadata +* with the exception of the root directory. Inodes with a connection to a +* file descriptor but not linked from anywhere in the on-disk directory tree +* are collectively known as unlinked inodes, though the filesystem itself +* maintains links to these inodes so that on-disk metadata are consistent. +* +* XFS implements a per-AG on-disk hash table of unlinked inodes. The AGI +* header contains a number of buckets that point to an inode, and each inode +* record has a pointer to the next inode in the hash chain. This +* singly-linked list causes scaling problems in the iunlink remove function +* because we must walk that list to find the inode that points to the inode +* being removed from the unlinked hash bucket list. +* +* Hence we keep an in-memory double linked list to link each inode on an +* unlinked list. Because there are 64 unlinked lists per AGI, keeping pointer +* based lists would require having 64 list heads in the perag, one for each +* list. This is expensive in terms of memory (think millions of AGs) and cache +* misses on lookups. Instead, use the fact that inodes on the unlinked list +* must be referenced at the VFS level to keep them on the list and hence we +* have an existence guarantee for inodes on the unlinked list. +* +* Given we have an existence guarantee, we can use lockless inode cache lookups +* to resolve aginos to xfs inodes. This means we only need 8 bytes per inode +* for the double linked unlinked list, and we don't need any extra locking to +* keep the list safe as all manipulations are done under the AGI buffer lock. +* Keeping the list up to date does not require memory allocation, just finding +* the XFS inode and updating the next/prev unlinked list aginos. +*/ + +/* +* Update the prev pointer of the next agino. Returns -ENOLINK if the inode +* is not in cache. +*/ +static int +xfs_iunlink_update_backref ( +struct xfs_perag *pag, +xfs_agino_t prev_agino, +xfs_agino_t next_agino) +{ +struct xfs_inode *ip; + +/* No update necessary if we are at the end of the list. */ +if (next_agino ==NULLAGINO ) +return 0 ; + + ip =xfs_iunlink_lookup (pag, next_agino); +if (!ip) +return -ENOLINK ; + + ip->i_prev_unlinked = prev_agino; +return 0 ; +} + +/* +* Point the AGI unlinked bucket at an inode and log the results. The caller +* is responsible for validating the old value. +*/ +STATIC int +xfs_iunlink_update_bucket ( +struct xfs_trans *tp, +struct xfs_perag *pag, +struct xfs_buf *agibp, +unsigned int bucket_index, +xfs_agino_t new_agino) +{ +struct xfs_agi *agi = agibp->b_addr; +xfs_agino_t old_value; +int offset; + +ASSERT (xfs_verify_agino_or_null (pag, new_agino)); + + old_value =be32_to_cpu (agi->agi_unlinked[bucket_index]); +trace_xfs_iunlink_update_bucket (tp->t_mountp, pag->pag_agno, bucket_index, + old_value, new_agino); + +/* +* We should never find the head of the list already set to the value +* passed in because either we're adding or removing ourselves from the +* head of the list. +*/ +if (old_value == new_agino) { +xfs_buf_mark_corrupt (agibp); +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGI ); +return -EFSCORRUPTED ; + } + + agi->agi_unlinked[bucket_index] =cpu_to_be32 (new_agino); + offset = offsetof(struct xfs_agi , agi_unlinked) + + (sizeof (xfs_agino_t) * bucket_index); +xfs_trans_log_buf (tp, agibp, offset, offset +sizeof (xfs_agino_t) -1 ); +return 0 ; +} + +static int +xfs_iunlink_insert_inode ( +struct xfs_trans *tp, +struct xfs_perag *pag, +struct xfs_buf *agibp, +struct xfs_inode *ip) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_agi *agi = agibp->b_addr; +xfs_agino_t next_agino; +xfs_agino_t agino =XFS_INO_TO_AGINO (mp, ip->i_ino); +short bucket_index = agino %XFS_AGI_UNLINKED_BUCKETS ; +int error; + +/* +* Get the index into the agi hash table for the list this inode will +* go on. Make sure the pointer isn't garbage and that this inode +* isn't already on the list. +*/ + next_agino =be32_to_cpu (agi->agi_unlinked[bucket_index]); +if (next_agino == agino || + !xfs_verify_agino_or_null (pag, next_agino)) { +xfs_buf_mark_corrupt (agibp); +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGI ); +return -EFSCORRUPTED ; + } + +/* +* Update the prev pointer in the next inode to point back to this +* inode. +*/ + error =xfs_iunlink_update_backref (pag, agino, next_agino); +if (error == -ENOLINK ) + error =xfs_iunlink_reload_next (tp, agibp, agino, next_agino); +if (error) +return error; + +if (next_agino !=NULLAGINO ) { +/* +* There is already another inode in the bucket, so point this +* inode to the current head of the list. +*/ + error =xfs_iunlink_log_inode (tp, ip, pag, next_agino); +if (error) +return error; + ip->i_next_unlinked = next_agino; + } + +/* Point the head of the list to point to this inode. */ + ip->i_prev_unlinked =NULLAGINO ; +return xfs_iunlink_update_bucket (tp, pag, agibp, bucket_index, agino); +} + +/* +* This is called when the inode's link count has gone to 0 or we are creating +* a tmpfile via O_TMPFILE. The inode @ip must have nlink == 0. +* +* We place the on-disk inode on a list in the AGI. It will be pulled from this +* list when the inode is freed. +*/ +int +xfs_iunlink ( +struct xfs_trans *tp, +struct xfs_inode *ip) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_perag *pag; +struct xfs_buf *agibp; +int error; + +ASSERT (VFS_I (ip)->i_nlink ==0 ); +ASSERT (VFS_I (ip)->i_mode !=0 ); +trace_xfs_iunlink (ip); + + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ip->i_ino)); + +/* Get the agi buffer first. It ensures lock ordering on the list. */ + error =xfs_read_agi (pag, tp,0 , &agibp); +if (error) + goto out; + + error =xfs_iunlink_insert_inode (tp, pag, agibp, ip); +out: +xfs_perag_put (pag); +return error; +} + +static int +xfs_iunlink_remove_inode ( +struct xfs_trans *tp, +struct xfs_perag *pag, +struct xfs_buf *agibp, +struct xfs_inode *ip) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_agi *agi = agibp->b_addr; +xfs_agino_t agino =XFS_INO_TO_AGINO (mp, ip->i_ino); +xfs_agino_t head_agino; +short bucket_index = agino %XFS_AGI_UNLINKED_BUCKETS ; +int error; + +trace_xfs_iunlink_remove (ip); + +/* +* Get the index into the agi hash table for the list this inode will +* go on. Make sure the head pointer isn't garbage. +*/ + head_agino =be32_to_cpu (agi->agi_unlinked[bucket_index]); +if (!xfs_verify_agino (pag, head_agino)) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + agi,sizeof (*agi)); +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGI ); +return -EFSCORRUPTED ; + } + +/* +* Set our inode's next_unlinked pointer to NULL and then return +* the old pointer value so that we can update whatever was previous +* to us in the list to point to whatever was next in the list. +*/ + error =xfs_iunlink_log_inode (tp, ip, pag,NULLAGINO ); +if (error) +return error; + +/* +* Update the prev pointer in the next inode to point back to previous +* inode in the chain. +*/ + error =xfs_iunlink_update_backref (pag, ip->i_prev_unlinked, + ip->i_next_unlinked); +if (error == -ENOLINK ) + error =xfs_iunlink_reload_next (tp, agibp, ip->i_prev_unlinked, + ip->i_next_unlinked); +if (error) +return error; + +if (head_agino != agino) { +struct xfs_inode *prev_ip; + + prev_ip =xfs_iunlink_lookup (pag, ip->i_prev_unlinked); +if (!prev_ip) { +xfs_inode_mark_sick (ip,XFS_SICK_INO_CORE ); +return -EFSCORRUPTED ; + } + + error =xfs_iunlink_log_inode (tp, prev_ip, pag, + ip->i_next_unlinked); + prev_ip->i_next_unlinked = ip->i_next_unlinked; + }else { +/* Point the head of the list to the next unlinked inode. */ + error =xfs_iunlink_update_bucket (tp, pag, agibp, bucket_index, + ip->i_next_unlinked); + } + + ip->i_next_unlinked =NULLAGINO ; + ip->i_prev_unlinked =0 ; +return error; +} + +/* +* Pull the on-disk inode from the AGI unlinked list. +*/ +int +xfs_iunlink_remove ( +struct xfs_trans *tp, +struct xfs_perag *pag, +struct xfs_inode *ip) +{ +struct xfs_buf *agibp; +int error; + +trace_xfs_iunlink_remove (ip); + +/* Get the agi buffer first. It ensures lock ordering on the list. */ + error =xfs_read_agi (pag, tp,0 , &agibp); +if (error) +return error; + +return xfs_iunlink_remove_inode (tp, pag, agibp, ip); +}
fs/xfs/libxfs/xfs_inode_util.h +4 -0
@@ -47,4 +47,8 @@ void xfs_trans_ichgtime(struct xfs_trans *tp, struct xfs_inode *ip, int flags);void xfs_inode_init (struct xfs_trans *tp,const struct xfs_icreate_args *args,struct xfs_inode *ip); +int xfs_iunlink (struct xfs_trans *tp,struct xfs_inode *ip); +int xfs_iunlink_remove (struct xfs_trans *tp,struct xfs_perag *pag, +struct xfs_inode *ip); +#endif /* __XFS_INODE_UTIL_H__ */
fs/xfs/xfs_inode.c +1 -279
303 lines not on this page · raw message
fs/xfs/xfs_inode.h +2 -3
@@ -606,10 +606,9 @@ extern struct kmem_cache *xfs_inode_cache;bool xfs_inode_needs_inactive (struct xfs_inode *ip); -int xfs_iunlink (struct xfs_trans *tp,struct xfs_inode *ip); -int xfs_iunlink_remove (struct xfs_trans *tp,struct xfs_perag *pag, -struct xfs_inode *ip);struct xfs_inode *xfs_iunlink_lookup (struct xfs_perag *pag,xfs_agino_t agino); +int xfs_iunlink_reload_next (struct xfs_trans *tp,struct xfs_buf *agibp, +xfs_agino_t prev_agino,xfs_agino_t next_agino);void xfs_end_io (struct work_struct *work);
Re: [PATCH 13/24] xfs: hoist xfs_iunlink to libxfs
Looks good:
PATCH 14/24 xfs: hoist xfs_{bump,drop}link to libxfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move xfs_bumplink and xfs_droplink to libxfs.
--- fs/xfs/libxfs/xfs_inode_util.c | 53 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 2 ++ fs/xfs/xfs_inode.c | 53 ---------------------------------------- fs/xfs/xfs_inode.h | 2 -- 4 files changed, 55 insertions(+), 55 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +53 -0
@@ -626,3 +626,56 @@ xfs_iunlink_remove(return xfs_iunlink_remove_inode (tp, pag, agibp, ip); } + +/* +* Decrement the link count on an inode & log the change. If this causes the +* link count to go to zero, move the inode to AGI unlinked list so that it can +* be freed when the last active reference goes away via xfs_inactive(). +*/ +int +xfs_droplink ( +struct xfs_trans *tp, +struct xfs_inode *ip) +{ +struct inode *inode =VFS_I (ip); + +xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG ); + +if (inode->i_nlink ==0 ) { +xfs_info_ratelimited (tp->t_mountp, +"Inode 0x%llx link count dropped below zero. Pinning link count." , + ip->i_ino); +set_nlink (inode,XFS_NLINK_PINNED ); + } +if (inode->i_nlink !=XFS_NLINK_PINNED ) +drop_nlink (inode); + +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); + +if (inode->i_nlink) +return 0 ; + +return xfs_iunlink (tp, ip); +} + +/* +* Increment the link count on an inode & log the change. +*/ +void +xfs_bumplink ( +struct xfs_trans *tp, +struct xfs_inode *ip) +{ +struct inode *inode =VFS_I (ip); + +xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG ); + +if (inode->i_nlink ==XFS_NLINK_PINNED -1 ) +xfs_info_ratelimited (tp->t_mountp, +"Inode 0x%llx link count exceeded maximum. Pinning link count." , + ip->i_ino); +if (inode->i_nlink !=XFS_NLINK_PINNED ) +inc_nlink (inode); + +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); +}
fs/xfs/libxfs/xfs_inode_util.h +2 -0
@@ -50,5 +50,7 @@ void xfs_inode_init(struct xfs_trans *tp, const struct xfs_icreate_args *args,int xfs_iunlink (struct xfs_trans *tp,struct xfs_inode *ip);int xfs_iunlink_remove (struct xfs_trans *tp,struct xfs_perag *pag,struct xfs_inode *ip); +int xfs_droplink (struct xfs_trans *tp,struct xfs_inode *ip); +void xfs_bumplink (struct xfs_trans *tp,struct xfs_inode *ip);#endif /* __XFS_INODE_UTIL_H__ */
fs/xfs/xfs_inode.c +0 -53
59 lines not on this page · raw message
fs/xfs/xfs_inode.h +0 -2
@@ -615,8 +615,6 @@ void xfs_end_io(struct work_struct *work);int xfs_ilock2_io_mmap (struct xfs_inode *ip1,struct xfs_inode *ip2);void xfs_iunlock2_io_mmap (struct xfs_inode *ip1,struct xfs_inode *ip2);void xfs_iunlock2_remapping (struct xfs_inode *ip1,struct xfs_inode *ip2); -int xfs_droplink (struct xfs_trans *tp,struct xfs_inode *ip); -void xfs_bumplink (struct xfs_trans *tp,struct xfs_inode *ip);void xfs_lock_inodes (struct xfs_inode **ips,int inodes,uint lock_mode);void xfs_sort_inodes (struct xfs_inode **i_tab,unsigned int num_inodes);
Re: [PATCH 14/24] xfs: hoist xfs_{bump,drop}link to libxfs
Looks good:
PATCH 15/24 xfs: separate the icreate logic around INIT_XATTRS
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
INIT_XATTRS is overloaded here -- it's set during the creat process when we think that we're immediately going to set some ACL xattrs to save time. However, it's also used by the parent pointers code to enable the attr fork in preparation to receive ppptr xattrs. This results in xfs_has_parent() branches scattered around the codebase to turn on INIT_XATTRS.
Linkable files are created far more commonly than unlinkable temporary files or directory tree roots, so we should centralize this logic in xfs_inode_init. For the three callers that don't want parent pointers (online repiar tempfiles, unlinkable tempfiles, rootdir creation) we provide an UNLINKABLE flag to skip attr fork initialization.
--- fs/xfs/libxfs/xfs_inode_util.c | 36 ++++++++++++++++++++++++++---------- fs/xfs/libxfs/xfs_inode_util.h | 1 + fs/xfs/scrub/tempfile.c | 2 +- fs/xfs/xfs_inode.c | 3 --- fs/xfs/xfs_iops.c | 11 ++++------- fs/xfs/xfs_qm.c | 1 + fs/xfs/xfs_symlink.c | 3 --- 7 files changed, 33 insertions(+), 24 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +26 -10
@@ -233,6 +233,31 @@ xfs_inode_inherit_flags2( } } +/* +* If we need to create attributes immediately after allocating the inode, +* initialise an empty attribute fork right now. We use the default fork offset +* for attributes here as we don't know exactly what size or how many +* attributes we might be adding. We can do this safely here because we know +* the data fork is completely empty and this saves us from needing to run a +* separate transaction to set the fork offset in the immediate future. +* +* If we have parent pointers and the caller hasn't told us that the file will +* never be linked into a directory tree, we /must/ create the attr fork. +*/ +static inline bool +xfs_icreate_want_attrfork ( +struct xfs_mount *mp, +const struct xfs_icreate_args *args) +{ +if (args->flags &XFS_ICREATE_INIT_XATTRS ) +return true; + +if (!(args->flags &XFS_ICREATE_UNLINKABLE ) &&xfs_has_parent (mp)) +return true; + +return false; +} +/* Initialise an inode's attributes. */ void xfs_inode_init(
@@ -325,16 +350,7 @@ xfs_inode_init(ASSERT (0 ); } -/* -* If we need to create attributes immediately after allocating the -* inode, initialise an empty attribute fork right now. We use the -* default fork offset for attributes here as we don't know exactly what -* size or how many attributes we might be adding. We can do this -* safely here because we know the data fork is completely empty and -* this saves us from needing to run a separate transaction to set the -* fork offset in the immediate future. -*/ -if (args->flags &XFS_ICREATE_INIT_XATTRS ) { +if (xfs_icreate_want_attrfork (mp, args)) { ip->i_forkoff =xfs_default_attroffset (ip) >>3 ;xfs_ifork_init_attr (ip,XFS_DINODE_FMT_EXTENTS ,0 );
fs/xfs/libxfs/xfs_inode_util.h +1 -0
@@ -32,6 +32,7 @@ struct xfs_icreate_args {#define XFS_ICREATE_TMPFILE (1U << 0)/* create an unlinked file */ #define XFS_ICREATE_INIT_XATTRS (1U << 1)/* will set xattrs immediately */ +#define XFS_ICREATE_UNLINKABLE (1U << 2)/* cannot link into dir tree */ uint16_t flags; };
fs/xfs/scrub/tempfile.c +1 -1
@@ -43,7 +43,7 @@ xrep_tempfile_create(struct xfs_icreate_args args = { .pip = sc->mp->m_rootip, .mode = mode, - .flags =XFS_ICREATE_TMPFILE , + .flags =XFS_ICREATE_TMPFILE |XFS_ICREATE_UNLINKABLE , };struct xfs_mount *mp = sc->mp;struct xfs_trans *tp =NULL ;
fs/xfs/xfs_inode.c +0 -3
@@ -2512,9 +2512,6 @@ xfs_rename_alloc_whiteout(struct qstr name;int error; -if (xfs_has_parent (dp->i_mount)) - args.flags |=XFS_ICREATE_INIT_XATTRS ; - error =xfs_create_tmpfile (&args, &tmpfile);if (error)return error;
fs/xfs/xfs_iops.c +4 -7
@@ -158,8 +158,6 @@ xfs_create_need_xattr(if (dir->i_sb->s_security)return true;#endif -if (xfs_has_parent (XFS_I (dir)->i_mount)) -return true;return false; }
@@ -215,12 +213,11 @@ xfs_generic_create( args.flags |=XFS_ICREATE_TMPFILE ;/* -* If this temporary file will be linkable, set up the file -* with an attr fork to receive a parent pointer. +* If this temporary file will not be linkable, don't bother +* creating an attr fork to receive a parent pointer. */ -if (!(tmpfile->f_flags &O_EXCL ) && -xfs_has_parent (XFS_I (dir)->i_mount)) - args.flags |=XFS_ICREATE_INIT_XATTRS ; +if (tmpfile->f_flags &O_EXCL ) + args.flags |=XFS_ICREATE_UNLINKABLE ; error =xfs_create_tmpfile (&args, &ip); }
fs/xfs/xfs_qm.c +1 -0
@@ -795,6 +795,7 @@ xfs_qm_qino_alloc(if (need_alloc) {struct xfs_icreate_args args = { .mode =S_IFREG , + .flags =XFS_ICREATE_UNLINKABLE , };xfs_ino_t ino;
fs/xfs/xfs_symlink.c +0 -3
@@ -115,9 +115,6 @@ xfs_symlink(if (xfs_is_shutdown (mp))return -EIO ; -if (xfs_has_parent (mp)) - args.flags |=XFS_ICREATE_INIT_XATTRS ; -/* * Check component lengths of the target path name. */
Re: [PATCH 15/24] xfs: separate the icreate logic around INIT_XATTRS
Looks good:
PATCH 16/24 xfs: create libxfs helper to link a new inode into a directory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a new libxfs function to link a newly created inode into a directory. The upcoming metadata directory feature will need this to create a metadata directory tree.
--- fs/xfs/libxfs/xfs_dir2.c | 53 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 12 ++++++++++ fs/xfs/xfs_inode.c | 57 +++++++++++++++------------------------------- fs/xfs/xfs_symlink.c | 45 +++++++++++++++--------------------- 4 files changed, 102 insertions(+), 65 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +53 -0
@@ -19,6 +19,9 @@#include "xfs_error.h" #include "xfs_trace.h" #include "xfs_health.h" +#include "xfs_bmap_btree.h" +#include "xfs_trans_space.h" +#include "xfs_parent.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)".." ,
@@ -756,3 +759,53 @@ xfs_dir2_compname(return xfs_ascii_ci_compname (args, name, len);return xfs_da_compname (args, name, len); } + +/* +* Given a directory @dp, a newly allocated inode @ip, and a @name, link @ip +* into @dp under the given @name. If @ip is a directory, it will be +* initialized. Both inodes must have the ILOCK held and the transaction must +* have sufficient blocks reserved. +*/ +int +xfs_dir_create_child ( +struct xfs_trans *tp, +unsigned int resblks, +struct xfs_dir_update *du) +{ +struct xfs_inode *dp = du->dp; +const struct xfs_name *name = du->name; +struct xfs_inode *ip = du->ip; +int error; + +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL ); +xfs_assert_ilocked (dp,XFS_ILOCK_EXCL ); + + error =xfs_dir_createname (tp, dp, name, ip->i_ino, resblks); +if (error) { +ASSERT (error != -ENOSPC ); +return error; + } + +xfs_trans_ichgtime (tp, dp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); +xfs_trans_log_inode (tp, dp,XFS_ILOG_CORE ); + +if (S_ISDIR (VFS_I (ip)->i_mode)) { + error =xfs_dir_init (tp, ip, dp); +if (error) +return error; + +xfs_bumplink (tp, dp); + } + +/* +* If we have parent pointers, we need to add the attribute containing +* the parent information now. +*/ +if (du->ppargs) { + error =xfs_parent_addname (tp, du->ppargs, dp, name, ip); +if (error) +return error; + } + +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +12 -0
@@ -309,4 +309,16 @@ static inline unsigned char xfs_ascii_ci_xfrm(unsigned char c) return c; } +struct xfs_parent_args ; + +struct xfs_dir_update { +struct xfs_inode *dp; +const struct xfs_name *name; +struct xfs_inode *ip; +struct xfs_parent_args *ppargs; +}; + +int xfs_dir_create_child (struct xfs_trans *tp,unsigned int resblks, +struct xfs_dir_update *du); +#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +18 -39
114 lines not on this page · raw message
fs/xfs/xfs_symlink.c +19 -26
104 lines not on this page · raw message
Re: [PATCH 16/24] xfs: create libxfs helper to link a new inode into a directory
Looks good:
PATCH 17/24 xfs: create libxfs helper to link an existing inode into a directory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a new libxfs function to link an existing inode into a directory. The upcoming metadata directory feature will need this to create a metadata directory tree.
--- fs/xfs/libxfs/xfs_dir2.c | 71 ++++++++++++++++++++++++++++++++++++++++++++-- fs/xfs/libxfs/xfs_dir2.h | 4 ++- fs/xfs/xfs_inode.c | 52 ++++++---------------------------- 3 files changed, 81 insertions(+), 46 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +68 -3
@@ -22,6 +22,7 @@#include "xfs_bmap_btree.h" #include "xfs_trans_space.h" #include "xfs_parent.h" +#include "xfs_ag.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)".." ,
@@ -587,9 +588,9 @@ xfs_dir_replace(*/ int xfs_dir_canenter ( -xfs_trans_t *tp, -xfs_inode_t *dp, -struct xfs_name *name)/* name of entry to add */ +struct xfs_trans *tp, +struct xfs_inode *dp, +const struct xfs_name *name)/* name of entry to add */ {return xfs_dir_createname (tp, dp, name,0 ,0 ); }
@@ -809,3 +810,67 @@ xfs_dir_create_child(return 0 ; } + +/* +* Given a directory @dp, an existing non-directory inode @ip, and a @name, +* link @ip into @dp under the given @name. Both inodes must have the ILOCK +* held. +*/ +int +xfs_dir_add_child ( +struct xfs_trans *tp, +unsigned int resblks, +struct xfs_dir_update *du) +{ +struct xfs_inode *dp = du->dp; +const struct xfs_name *name = du->name; +struct xfs_inode *ip = du->ip; +struct xfs_mount *mp = tp->t_mountp; +int error; + +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL ); +xfs_assert_ilocked (dp,XFS_ILOCK_EXCL ); +ASSERT (!S_ISDIR (VFS_I (ip)->i_mode)); + +if (!resblks) { + error =xfs_dir_canenter (tp, dp, name); +if (error) +return error; + } + +/* +* Handle initial link state of O_TMPFILE inode +*/ +if (VFS_I (ip)->i_nlink ==0 ) { +struct xfs_perag *pag; + + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ip->i_ino)); + error =xfs_iunlink_remove (tp, pag, ip); +xfs_perag_put (pag); +if (error) +return error; + } + + error =xfs_dir_createname (tp, dp, name, ip->i_ino, resblks); +if (error) +return error; + +xfs_trans_ichgtime (tp, dp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); +xfs_trans_log_inode (tp, dp,XFS_ILOG_CORE ); + +xfs_bumplink (tp, ip); + +/* +* If we have parent pointers, we now need to add the parent record to +* the attribute fork of the inode. If this is the initial parent +* attribute, we need to create it correctly, otherwise we can just add +* the parent to the inode. +*/ +if (du->ppargs) { + error =xfs_parent_addname (tp, du->ppargs, dp, name, ip); +if (error) +return error; + } + +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +3 -1
@@ -74,7 +74,7 @@ extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum, xfs_extlen_t tot);extern int xfs_dir_canenter (struct xfs_trans *tp,struct xfs_inode *dp, -struct xfs_name *name); +const struct xfs_name *name);int xfs_dir_lookup_args (struct xfs_da_args *args);int xfs_dir_createname_args (struct xfs_da_args *args);
@@ -320,5 +320,7 @@ struct xfs_dir_update {int xfs_dir_create_child (struct xfs_trans *tp,unsigned int resblks,struct xfs_dir_update *du); +int xfs_dir_add_child (struct xfs_trans *tp,unsigned int resblks, +struct xfs_dir_update *du);#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +10 -42
94 lines not on this page · raw message
Re: [PATCH 17/24] xfs: create libxfs helper to link an existing inode into a directory
Looks good:
PATCH 18/24 xfs: hoist inode free function to libxfs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a libxfs helper function that marks an inode free on disk.
--- fs/xfs/libxfs/xfs_inode_util.c | 52 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 5 ++++ fs/xfs/xfs_inode.c | 35 +-------------------------- 3 files changed, 58 insertions(+), 34 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +52 -0
@@ -22,6 +22,7 @@#include "xfs_trace.h" #include "xfs_ag.h" #include "xfs_iunlink_item.h" +#include "xfs_inode_item.h" uint16_t xfs_flags2diflags(
@@ -695,3 +696,54 @@ xfs_bumplink(xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); } + +/* Free an inode in the ondisk index and zero it out. */ +int +xfs_inode_uninit ( +struct xfs_trans *tp, +struct xfs_perag *pag, +struct xfs_inode *ip, +struct xfs_icluster *xic) +{ +struct xfs_mount *mp = ip->i_mount; +int error; + +/* +* Free the inode first so that we guarantee that the AGI lock is going +* to be taken before we remove the inode from the unlinked list. This +* makes the AGI lock -> unlinked list modification order the same as +* used in O_TMPFILE creation. +*/ + error =xfs_difree (tp, pag, ip->i_ino, xic); +if (error) +return error; + + error =xfs_iunlink_remove (tp, pag, ip); +if (error) +return error; + +/* +* Free any local-format data sitting around before we reset the +* data fork to extents format. Note that the attr fork data has +* already been freed by xfs_attr_inactive. +*/ +if (ip->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { +kfree (ip->i_df.if_data); + ip->i_df.if_data =NULL ; + ip->i_df.if_bytes =0 ; + } + +VFS_I (ip)->i_mode =0 ;/* mark incore inode as free */ + ip->i_diflags =0 ; + ip->i_diflags2 = mp->m_ino_geo.new_diflags2; + ip->i_forkoff =0 ;/* mark the attr fork not in use */ + ip->i_df.if_format =XFS_DINODE_FMT_EXTENTS ; + +/* +* Bump the generation count so no one will be confused +* by reincarnations of this inode. +*/ +VFS_I (ip)->i_generation++; +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); +return 0 ; +}
fs/xfs/libxfs/xfs_inode_util.h +5 -0
@@ -6,6 +6,8 @@#ifndef __XFS_INODE_UTIL_H__#define __XFS_INODE_UTIL_H__ +struct xfs_icluster ; +uint16_t xfs_flags2diflags (struct xfs_inode *ip,unsigned int xflags);uint64_t xfs_flags2diflags2 (struct xfs_inode *ip,unsigned int xflags);uint32_t xfs_dic2xflags (struct xfs_inode *ip);
@@ -48,6 +50,9 @@ void xfs_trans_ichgtime(struct xfs_trans *tp, struct xfs_inode *ip, int flags);void xfs_inode_init (struct xfs_trans *tp,const struct xfs_icreate_args *args,struct xfs_inode *ip); +int xfs_inode_uninit (struct xfs_trans *tp,struct xfs_perag *pag, +struct xfs_inode *ip,struct xfs_icluster *xic); +int xfs_iunlink (struct xfs_trans *tp,struct xfs_inode *ip);int xfs_iunlink_remove (struct xfs_trans *tp,struct xfs_perag *pag,struct xfs_inode *ip);
fs/xfs/xfs_inode.c +1 -34
@@ -1930,36 +1930,10 @@ xfs_ifree( pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ip->i_ino)); -/* -* Free the inode first so that we guarantee that the AGI lock is going -* to be taken before we remove the inode from the unlinked list. This -* makes the AGI lock -> unlinked list modification order the same as -* used in O_TMPFILE creation. -*/ - error =xfs_difree (tp, pag, ip->i_ino, &xic); + error =xfs_inode_uninit (tp, pag, ip, &xic);if (error) goto out; - error =xfs_iunlink_remove (tp, pag, ip); -if (error) - goto out; - -/* -* Free any local-format data sitting around before we reset the -* data fork to extents format. Note that the attr fork data has -* already been freed by xfs_attr_inactive. -*/ -if (ip->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { -kfree (ip->i_df.if_data); - ip->i_df.if_data =NULL ; - ip->i_df.if_bytes =0 ; - } - -VFS_I (ip)->i_mode =0 ;/* mark incore inode as free */ - ip->i_diflags =0 ; - ip->i_diflags2 = mp->m_ino_geo.new_diflags2; - ip->i_forkoff =0 ;/* mark the attr fork not in use */ - ip->i_df.if_format =XFS_DINODE_FMT_EXTENTS ;if (xfs_iflags_test (ip,XFS_IPRESERVE_DM_FIELDS ))xfs_iflags_clear (ip,XFS_IPRESERVE_DM_FIELDS );
@@ -1968,13 +1942,6 @@ xfs_ifree( iip->ili_fields &= ~(XFS_ILOG_AOWNER |XFS_ILOG_DOWNER );spin_unlock (&iip->ili_lock); -/* -* Bump the generation count so no one will be confused -* by reincarnations of this inode. -*/ -VFS_I (ip)->i_generation++; -xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); -if (xic.deleted) error =xfs_ifree_cluster (tp, pag, ip, &xic); out:
Re: [PATCH 18/24] xfs: hoist inode free function to libxfs
Looks good:
PATCH 19/24 xfs: create libxfs helper to remove an existing inode/name from a directory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a new libxfs function to remove a (name, inode) entry from a directory. The upcoming metadata directory feature will need this to create a metadata directory tree.
--- fs/xfs/libxfs/xfs_dir2.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 2 + fs/xfs/xfs_inode.c | 74 +++++------------------------------------- 3 files changed, 92 insertions(+), 65 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +81 -0
@@ -874,3 +874,84 @@ xfs_dir_add_child(return 0 ; } + +/* +* Given a directory @dp, a child @ip, and a @name, remove the (@name, @ip) +* entry from the directory. Both inodes must have the ILOCK held. +*/ +int +xfs_dir_remove_child ( +struct xfs_trans *tp, +unsigned int resblks, +struct xfs_dir_update *du) +{ +struct xfs_inode *dp = du->dp; +const struct xfs_name *name = du->name; +struct xfs_inode *ip = du->ip; +int error; + +xfs_assert_ilocked (ip,XFS_ILOCK_EXCL ); +xfs_assert_ilocked (dp,XFS_ILOCK_EXCL ); + +/* +* If we're removing a directory perform some additional validation. +*/ +if (S_ISDIR (VFS_I (ip)->i_mode)) { +ASSERT (VFS_I (ip)->i_nlink >=2 ); +if (VFS_I (ip)->i_nlink !=2 ) +return -ENOTEMPTY ; +if (!xfs_dir_isempty (ip)) +return -ENOTEMPTY ; + +/* Drop the link from ip's "..". */ + error =xfs_droplink (tp, dp); +if (error) +return error; + +/* Drop the "." link from ip to self. */ + error =xfs_droplink (tp, ip); +if (error) +return error; + +/* +* Point the unlinked child directory's ".." entry to the root +* directory to eliminate back-references to inodes that may +* get freed before the child directory is closed. If the fs +* gets shrunk, this can lead to dirent inode validation errors. +*/ +if (dp->i_ino != tp->t_mountp->m_sb.sb_rootino) { + error =xfs_dir_replace (tp, ip, &xfs_name_dotdot, + tp->t_mountp->m_sb.sb_rootino,0 ); +if (error) +return error; + } + }else { +/* +* When removing a non-directory we need to log the parent +* inode here. For a directory this is done implicitly +* by the xfs_droplink call for the ".." entry. +*/ +xfs_trans_log_inode (tp, dp,XFS_ILOG_CORE ); + } +xfs_trans_ichgtime (tp, dp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); + +/* Drop the link from dp to ip. */ + error =xfs_droplink (tp, ip); +if (error) +return error; + + error =xfs_dir_removename (tp, dp, name, ip->i_ino, resblks); +if (error) { +ASSERT (error != -ENOENT ); +return error; + } + +/* Remove parent pointer. */ +if (du->ppargs) { + error =xfs_parent_removename (tp, du->ppargs, dp, name, ip); +if (error) +return error; + } + +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +2 -0
@@ -322,5 +322,7 @@ int xfs_dir_create_child(struct xfs_trans *tp, unsigned int resblks, struct xfs_dir_update *du);int xfs_dir_add_child (struct xfs_trans *tp,unsigned int resblks,struct xfs_dir_update *du); +int xfs_dir_remove_child (struct xfs_trans *tp,unsigned int resblks, +struct xfs_dir_update *du);#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +9 -65
113 lines not on this page · raw message
Re: [PATCH 19/24] xfs: create libxfs helper to remove an existing inode/name from a directory
Looks good:
PATCH 20/24 xfs: create libxfs helper to exchange two directory entries
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a new libxfs function to exchange two directory entries. The upcoming metadata directory feature will need this to replace a metadata inode directory entry.
--- fs/xfs/libxfs/xfs_dir2.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 3 + fs/xfs/xfs_inode.c | 114 ++++++------------------------------------ 3 files changed, 143 insertions(+), 99 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +125 -0
@@ -955,3 +955,128 @@ xfs_dir_remove_child(return 0 ; } + +/* +* Exchange the entry (@name1, @ip1) in directory @dp1 with the entry (@name2, +* @ip2) in directory @dp2, and update '..' @ip1 and @ip2's entries as needed. +* @ip1 and @ip2 need not be of the same type. +* +* All inodes must have the ILOCK held, and both entries must already exist. +*/ +int +xfs_dir_exchange_children ( +struct xfs_trans *tp, +struct xfs_dir_update *du1, +struct xfs_dir_update *du2, +unsigned int spaceres) +{ +struct xfs_inode *dp1 = du1->dp; +const struct xfs_name *name1 = du1->name; +struct xfs_inode *ip1 = du1->ip; +struct xfs_inode *dp2 = du2->dp; +const struct xfs_name *name2 = du2->name; +struct xfs_inode *ip2 = du2->ip; +int ip1_flags =0 ; +int ip2_flags =0 ; +int dp2_flags =0 ; +int error; + +/* Swap inode number for dirent in first parent */ + error =xfs_dir_replace (tp, dp1, name1, ip2->i_ino, spaceres); +if (error) +return error; + +/* Swap inode number for dirent in second parent */ + error =xfs_dir_replace (tp, dp2, name2, ip1->i_ino, spaceres); +if (error) +return error; + +/* +* If we're renaming one or more directories across different parents, +* update the respective ".." entries (and link counts) to match the new +* parents. +*/ +if (dp1 != dp2) { + dp2_flags =XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ; + +if (S_ISDIR (VFS_I (ip2)->i_mode)) { + error =xfs_dir_replace (tp, ip2, &xfs_name_dotdot, + dp1->i_ino, spaceres); +if (error) +return error; + +/* transfer ip2 ".." reference to dp1 */ +if (!S_ISDIR (VFS_I (ip1)->i_mode)) { + error =xfs_droplink (tp, dp2); +if (error) +return error; +xfs_bumplink (tp, dp1); + } + +/* +* Although ip1 isn't changed here, userspace needs +* to be warned about the change, so that applications +* relying on it (like backup ones), will properly +* notify the change +*/ + ip1_flags |=XFS_ICHGTIME_CHG ; + ip2_flags |=XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ; + } + +if (S_ISDIR (VFS_I (ip1)->i_mode)) { + error =xfs_dir_replace (tp, ip1, &xfs_name_dotdot, + dp2->i_ino, spaceres); +if (error) +return error; + +/* transfer ip1 ".." reference to dp2 */ +if (!S_ISDIR (VFS_I (ip2)->i_mode)) { + error =xfs_droplink (tp, dp1); +if (error) +return error; +xfs_bumplink (tp, dp2); + } + +/* +* Although ip2 isn't changed here, userspace needs +* to be warned about the change, so that applications +* relying on it (like backup ones), will properly +* notify the change +*/ + ip1_flags |=XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ; + ip2_flags |=XFS_ICHGTIME_CHG ; + } + } + +if (ip1_flags) { +xfs_trans_ichgtime (tp, ip1, ip1_flags); +xfs_trans_log_inode (tp, ip1,XFS_ILOG_CORE ); + } +if (ip2_flags) { +xfs_trans_ichgtime (tp, ip2, ip2_flags); +xfs_trans_log_inode (tp, ip2,XFS_ILOG_CORE ); + } +if (dp2_flags) { +xfs_trans_ichgtime (tp, dp2, dp2_flags); +xfs_trans_log_inode (tp, dp2,XFS_ILOG_CORE ); + } +xfs_trans_ichgtime (tp, dp1,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); +xfs_trans_log_inode (tp, dp1,XFS_ILOG_CORE ); + +/* Schedule parent pointer replacements */ +if (du1->ppargs) { + error =xfs_parent_replacename (tp, du1->ppargs, dp1, name1, + dp2, name2, ip1); +if (error) +return error; + } + +if (du2->ppargs) { + error =xfs_parent_replacename (tp, du2->ppargs, dp2, name2, + dp1, name1, ip2); +if (error) +return error; + } + +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +3 -0
@@ -325,4 +325,7 @@ int xfs_dir_add_child(struct xfs_trans *tp, unsigned int resblks,int xfs_dir_remove_child (struct xfs_trans *tp,unsigned int resblks,struct xfs_dir_update *du); +int xfs_dir_exchange_children (struct xfs_trans *tp,struct xfs_dir_update *du1, +struct xfs_dir_update *du2,unsigned int spaceres); +#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +15 -99
123 lines not on this page · raw message
Re: [PATCH 20/24] xfs: create libxfs helper to exchange two directory entries
Looks good:
PATCH 21/24 xfs: create libxfs helper to rename two directory entries
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a new libxfs function to rename two directory entries. The upcoming metadata directory feature will need this to replace a metadata inode directory entry.
--- fs/xfs/libxfs/xfs_dir2.c | 227 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 3 + fs/xfs/xfs_inode.c | 258 ++++++++-------------------------------------- 3 files changed, 273 insertions(+), 215 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +227 -0
@@ -23,6 +23,7 @@#include "xfs_trans_space.h" #include "xfs_parent.h" #include "xfs_ag.h" +#include "xfs_ialloc.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)".." ,
@@ -1080,3 +1081,229 @@ xfs_dir_exchange_children(return 0 ; } + +/* +* Given an entry (@src_name, @src_ip) in directory @src_dp, make the entry +* @target_name in directory @target_dp point to @src_ip and remove the +* original entry, cleaning up everything left behind. +* +* Cleanup involves dropping a link count on @target_ip, and either removing +* the (@src_name, @src_ip) entry from @src_dp or simply replacing the entry +* with (@src_name, @wip) if a whiteout inode @wip is supplied. +* +* All inodes must have the ILOCK held. We assume that if @src_ip is a +* directory then its '..' doesn't already point to @target_dp, and that @wip +* is a freshly allocated whiteout. +*/ +int +xfs_dir_rename_children ( +struct xfs_trans *tp, +struct xfs_dir_update *du_src, +struct xfs_dir_update *du_tgt, +unsigned int spaceres, +struct xfs_dir_update *du_wip) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_inode *src_dp = du_src->dp; +const struct xfs_name *src_name = du_src->name; +struct xfs_inode *src_ip = du_src->ip; +struct xfs_inode *target_dp = du_tgt->dp; +const struct xfs_name *target_name = du_tgt->name; +struct xfs_inode *target_ip = du_tgt->ip; +bool new_parent = (src_dp != target_dp); +bool src_is_directory; +int error; + + src_is_directory =S_ISDIR (VFS_I (src_ip)->i_mode); + +/* +* Check for expected errors before we dirty the transaction +* so we can return an error without a transaction abort. +*/ +if (target_ip ==NULL ) { +/* +* If there's no space reservation, check the entry will +* fit before actually inserting it. +*/ +if (!spaceres) { + error =xfs_dir_canenter (tp, target_dp, target_name); +if (error) +return error; + } + }else { +/* +* If target exists and it's a directory, check that whether +* it can be destroyed. +*/ +if (S_ISDIR (VFS_I (target_ip)->i_mode) && + (!xfs_dir_isempty (target_ip) || + (VFS_I (target_ip)->i_nlink >2 ))) +return -EEXIST ; + } + +/* +* Directory entry creation below may acquire the AGF. Remove +* the whiteout from the unlinked list first to preserve correct +* AGI/AGF locking order. This dirties the transaction so failures +* after this point will abort and log recovery will clean up the +* mess. +* +* For whiteouts, we need to bump the link count on the whiteout +* inode. After this point, we have a real link, clear the tmpfile +* state flag from the inode so it doesn't accidentally get misused +* in future. +*/ +if (du_wip->ip) { +struct xfs_perag *pag; + +ASSERT (VFS_I (du_wip->ip)->i_nlink ==0 ); + + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, du_wip->ip->i_ino)); + error =xfs_iunlink_remove (tp, pag, du_wip->ip); +xfs_perag_put (pag); +if (error) +return error; + +xfs_bumplink (tp, du_wip->ip); + } + +/* +* Set up the target. +*/ +if (target_ip ==NULL ) { +/* +* If target does not exist and the rename crosses +* directories, adjust the target directory link count +* to account for the ".." reference from the new entry. +*/ + error =xfs_dir_createname (tp, target_dp, target_name, + src_ip->i_ino, spaceres); +if (error) +return error; + +xfs_trans_ichgtime (tp, target_dp, +XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); + +if (new_parent && src_is_directory) { +xfs_bumplink (tp, target_dp); + } + }else {/* target_ip != NULL */ +/* +* Link the source inode under the target name. +* If the source inode is a directory and we are moving +* it across directories, its ".." entry will be +* inconsistent until we replace that down below. +* +* In case there is already an entry with the same +* name at the destination directory, remove it first. +*/ + error =xfs_dir_replace (tp, target_dp, target_name, + src_ip->i_ino, spaceres); +if (error) +return error; + +xfs_trans_ichgtime (tp, target_dp, +XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); + +/* +* Decrement the link count on the target since the target +* dir no longer points to it. +*/ + error =xfs_droplink (tp, target_ip); +if (error) +return error; + +if (src_is_directory) { +/* +* Drop the link from the old "." entry. +*/ + error =xfs_droplink (tp, target_ip); +if (error) +return error; + } + }/* target_ip != NULL */ + +/* +* Remove the source. +*/ +if (new_parent && src_is_directory) { +/* +* Rewrite the ".." entry to point to the new +* directory. +*/ + error =xfs_dir_replace (tp, src_ip, &xfs_name_dotdot, + target_dp->i_ino, spaceres); +ASSERT (error != -EEXIST ); +if (error) +return error; + } + +/* +* We always want to hit the ctime on the source inode. +* +* This isn't strictly required by the standards since the source +* inode isn't really being changed, but old unix file systems did +* it and some incremental backup programs won't work without it. +*/ +xfs_trans_ichgtime (tp, src_ip,XFS_ICHGTIME_CHG ); +xfs_trans_log_inode (tp, src_ip,XFS_ILOG_CORE ); + +/* +* Adjust the link count on src_dp. This is necessary when +* renaming a directory, either within one parent when +* the target existed, or across two parent directories. +*/ +if (src_is_directory && (new_parent || target_ip !=NULL )) { + +/* +* Decrement link count on src_directory since the +* entry that's moved no longer points to it. +*/ + error =xfs_droplink (tp, src_dp); +if (error) +return error; + } + +/* +* For whiteouts, we only need to update the source dirent with the +* inode number of the whiteout inode rather than removing it +* altogether. +*/ +if (du_wip->ip) + error =xfs_dir_replace (tp, src_dp, src_name, du_wip->ip->i_ino, + spaceres); +else + error =xfs_dir_removename (tp, src_dp, src_name, src_ip->i_ino, + spaceres); +if (error) +return error; + +xfs_trans_ichgtime (tp, src_dp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); +xfs_trans_log_inode (tp, src_dp,XFS_ILOG_CORE ); +if (new_parent) +xfs_trans_log_inode (tp, target_dp,XFS_ILOG_CORE ); + +/* Schedule parent pointer updates. */ +if (du_wip->ppargs) { + error =xfs_parent_addname (tp, du_wip->ppargs, src_dp, + src_name, du_wip->ip); +if (error) +return error; + } + +if (du_src->ppargs) { + error =xfs_parent_replacename (tp, du_src->ppargs, src_dp, + src_name, target_dp, target_name, src_ip); +if (error) +return error; + } + +if (du_tgt->ppargs) { + error =xfs_parent_removename (tp, du_tgt->ppargs, target_dp, + target_name, target_ip); +if (error) +return error; + } + +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +3 -0
@@ -327,5 +327,8 @@ int xfs_dir_remove_child(struct xfs_trans *tp, unsigned int resblks,int xfs_dir_exchange_children (struct xfs_trans *tp,struct xfs_dir_update *du1,struct xfs_dir_update *du2,unsigned int spaceres); +int xfs_dir_rename_children (struct xfs_trans *tp,struct xfs_dir_update *du_src, +struct xfs_dir_update *du_tgt,unsigned int spaceres, +struct xfs_dir_update *du_wip);#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +43 -215
354 lines not on this page · raw message
Re: [PATCH 21/24] xfs: create libxfs helper to rename two directory entries
Looks good:
PATCH 22/24 xfs: move dirent update hooks to xfs_dir2.c
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the directory entry update hook code to xfs_dir2 so that it is mostly consolidated with the higher level directory functions. Retain the exports so that online fsck can still send notifications through the hooks.
--- fs/xfs/libxfs/xfs_dir2.c | 104 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 25 ++++++++++ fs/xfs/scrub/common.c | 1 fs/xfs/xfs_inode.c | 117 ---------------------------------------------- fs/xfs/xfs_inode.h | 25 ---------- fs/xfs/xfs_symlink.c | 2 - 6 files changed, 130 insertions(+), 144 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +104 -0
@@ -762,6 +762,81 @@ xfs_dir2_compname(return xfs_da_compname (args, name, len); } +#ifdef CONFIG_XFS_LIVE_HOOKS +/* +* Use a static key here to reduce the overhead of directory live update hooks. +* 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_dir_hooks_switch); + +void +xfs_dir_hook_disable (void ) +{ +xfs_hooks_switch_off (&xfs_dir_hooks_switch); +} + +void +xfs_dir_hook_enable (void ) +{ +xfs_hooks_switch_on (&xfs_dir_hooks_switch); +} + +/* Call hooks for a directory update relating to a child dirent update. */ +inline void +xfs_dir_update_hook ( +struct xfs_inode *dp, +struct xfs_inode *ip, +int delta, +const struct xfs_name *name) +{ +if (xfs_hooks_switched_on (&xfs_dir_hooks_switch)) { +struct xfs_dir_update_params p = { + .dp = dp, + .ip = ip, + .delta = delta, + .name = name, + }; +struct xfs_mount *mp = ip->i_mount; + +xfs_hooks_call (&mp->m_dir_update_hooks,0 , &p); + } +} + +/* Call the specified function during a directory update. */ +int +xfs_dir_hook_add ( +struct xfs_mount *mp, +struct xfs_dir_hook *hook) +{ +return xfs_hooks_add (&mp->m_dir_update_hooks, &hook->dirent_hook); +} + +/* Stop calling the specified function during a directory update. */ +void +xfs_dir_hook_del ( +struct xfs_mount *mp, +struct xfs_dir_hook *hook) +{ +xfs_hooks_del (&mp->m_dir_update_hooks, &hook->dirent_hook); +} + +/* Configure directory update hook functions. */ +void +xfs_dir_hook_setup ( +struct xfs_dir_hook *hook, +notifier_fn_t mod_fn) +{ +xfs_hook_setup (&hook->dirent_hook, mod_fn); +} +#endif /* CONFIG_XFS_LIVE_HOOKS */ +/* * Given a directory @dp, a newly allocated inode @ip, and a @name, link @ip * into @dp under the given @name. If @ip is a directory, it will be
@@ -809,6 +884,7 @@ xfs_dir_create_child(return error; } +xfs_dir_update_hook (dp, ip,1 , name);return 0 ; }
@@ -873,6 +949,7 @@ xfs_dir_add_child(return error; } +xfs_dir_update_hook (dp, ip,1 , name);return 0 ; }
@@ -954,6 +1031,7 @@ xfs_dir_remove_child(return error; } +xfs_dir_update_hook (dp, ip,-1 , name);return 0 ; }
@@ -1079,6 +1157,18 @@ xfs_dir_exchange_children(return error; } +/* +* Inform our hook clients that we've finished an exchange operation as +* follows: removed the source and target files from their directories; +* added the target to the source directory; and added the source to +* the target directory. All inodes are locked, so it's ok to model a +* rename this way so long as we say we deleted entries before we add +* new ones. +*/ +xfs_dir_update_hook (dp1, ip1,-1 , name1); +xfs_dir_update_hook (dp2, ip2,-1 , name2); +xfs_dir_update_hook (dp1, ip2,1 , name1); +xfs_dir_update_hook (dp2, ip1,1 , name2);return 0 ; }
@@ -1305,5 +1395,19 @@ xfs_dir_rename_children(return error; } +/* +* Inform our hook clients that we've finished a rename operation as +* follows: removed the source and target files from their directories; +* that we've added the source to the target directory; and finally +* that we've added the whiteout, if there was one. All inodes are +* locked, so it's ok to model a rename this way so long as we say we +* deleted entries before we add new ones. +*/ +if (target_ip) +xfs_dir_update_hook (target_dp, target_ip,-1 , target_name); +xfs_dir_update_hook (src_dp, src_ip,-1 , src_name); +xfs_dir_update_hook (target_dp, src_ip,1 , target_name); +if (du_wip->ip) +xfs_dir_update_hook (src_dp, du_wip->ip,1 , src_name);return 0 ; }
fs/xfs/libxfs/xfs_dir2.h +25 -0
@@ -309,6 +309,31 @@ static inline unsigned char xfs_ascii_ci_xfrm(unsigned char c)return c; } +struct xfs_dir_update_params { +const struct xfs_inode *dp; +const struct xfs_inode *ip; +const struct xfs_name *name; +int delta; +}; + +#ifdef CONFIG_XFS_LIVE_HOOKS +void xfs_dir_update_hook (struct xfs_inode *dp,struct xfs_inode *ip, +int delta,const struct xfs_name *name); + +struct xfs_dir_hook { +struct xfs_hook dirent_hook; +}; + +void xfs_dir_hook_disable (void ); +void xfs_dir_hook_enable (void ); + +int xfs_dir_hook_add (struct xfs_mount *mp,struct xfs_dir_hook *hook); +void xfs_dir_hook_del (struct xfs_mount *mp,struct xfs_dir_hook *hook); +void xfs_dir_hook_setup (struct xfs_dir_hook *hook,notifier_fn_t mod_fn); +#else +# define xfs_dir_update_hook (dp, ip, delta, name) ((void)0) +#endif /* CONFIG_XFS_LIVE_HOOKS */ +struct xfs_parent_args ;struct xfs_dir_update {
fs/xfs/scrub/common.c +1 -0
@@ -26,6 +26,7 @@#include "xfs_da_format.h" #include "xfs_da_btree.h" #include "xfs_dir2_priv.h" +#include "xfs_dir2.h" #include "xfs_attr.h" #include "xfs_reflink.h" #include "xfs_ag.h"
fs/xfs/xfs_inode.c +0 -117
153 lines not on this page · raw message
fs/xfs/xfs_inode.h +0 -25
@@ -632,31 +632,6 @@ void xfs_inode_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip, xfs_filblks_t *dblocks, xfs_filblks_t *rblocks);unsigned int xfs_inode_alloc_unitsize (struct xfs_inode *ip); -struct xfs_dir_update_params { -const struct xfs_inode *dp; -const struct xfs_inode *ip; -const struct xfs_name *name; -int delta; -}; - -#ifdef CONFIG_XFS_LIVE_HOOKS -void xfs_dir_update_hook (struct xfs_inode *dp,struct xfs_inode *ip, -int delta,const struct xfs_name *name); - -struct xfs_dir_hook { -struct xfs_hook dirent_hook; -}; - -void xfs_dir_hook_disable (void ); -void xfs_dir_hook_enable (void ); - -int xfs_dir_hook_add (struct xfs_mount *mp,struct xfs_dir_hook *hook); -void xfs_dir_hook_del (struct xfs_mount *mp,struct xfs_dir_hook *hook); -void xfs_dir_hook_setup (struct xfs_dir_hook *hook,notifier_fn_t mod_fn); -#else -# define xfs_dir_update_hook (dp, ip, delta, name) ((void)0) -#endif /* CONFIG_XFS_LIVE_HOOKS */ -int xfs_icreate_dqalloc (const struct xfs_icreate_args *args,struct xfs_dquot **udqpp,struct xfs_dquot **gdqpp,struct xfs_dquot **pdqpp);
fs/xfs/xfs_symlink.c +0 -2
@@ -200,8 +200,6 @@ xfs_symlink(if (error) goto out_trans_cancel; -xfs_dir_update_hook (dp, du.ip,1 , link_name); -/* * If this is a synchronous mount, make sure that the * symlink transaction goes to disk before returning to
Re: [PATCH 22/24] xfs: move dirent update hooks to xfs_dir2.c
Looks good:
PATCH 23/24 xfs: get rid of trivial rename helpers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Get rid of the largely pointless xfs_cross_rename and xfs_finish_rename now that we've refactored its parent.
--- fs/xfs/xfs_inode.c | 77 +++++++++------------------------------------------- 1 file changed, 14 insertions(+), 63 deletions(-)
fs/xfs/xfs_inode.c +14 -63
@@ -2102,63 +2102,6 @@ xfs_sort_inodes( } } -static int -xfs_finish_rename ( -struct xfs_trans *tp) -{ -/* -* If this is a synchronous mount, make sure that the rename transaction -* goes to disk before returning to the user. -*/ -if (xfs_has_wsync (tp->t_mountp) ||xfs_has_dirsync (tp->t_mountp)) -xfs_trans_set_sync (tp); - -return xfs_trans_commit (tp); -} - -/* -* xfs_cross_rename() -* -* responsible for handling RENAME_EXCHANGE flag in renameat2() syscall -*/ -STATIC int -xfs_cross_rename ( -struct xfs_trans *tp, -struct xfs_inode *dp1, -struct xfs_name *name1, -struct xfs_inode *ip1, -struct xfs_parent_args *ip1_ppargs, -struct xfs_inode *dp2, -struct xfs_name *name2, -struct xfs_inode *ip2, -struct xfs_parent_args *ip2_ppargs, -int spaceres) -{ -struct xfs_dir_update du1 = { - .dp = dp1, - .name = name1, - .ip = ip1, - .ppargs = ip1_ppargs, - }; -struct xfs_dir_update du2 = { - .dp = dp2, - .name = name2, - .ip = ip2, - .ppargs = ip2_ppargs, - }; -int error; - - error =xfs_dir_exchange_children (tp, &du1, &du2, spaceres); -if (error) - goto out_trans_abort; - -return xfs_finish_rename (tp); - -out_trans_abort: -xfs_trans_cancel (tp); -return error; -} -/* * xfs_rename_alloc_whiteout() *
@@ -2351,11 +2294,11 @@ xfs_rename(/* RENAME_EXCHANGE is unique from here on. */ if (flags &RENAME_EXCHANGE ) { - error =xfs_cross_rename (tp, src_dp, src_name, src_ip, - du_src.ppargs, target_dp, target_name, - target_ip, du_tgt.ppargs, spaceres); - nospace_error =0 ; - goto out_unlock; + error =xfs_dir_exchange_children (tp, &du_src, &du_tgt, + spaceres); +if (error) + goto out_trans_cancel; + goto out_commit; }/*
@@ -2433,7 +2376,15 @@ xfs_rename(VFS_I (du_wip.ip)->i_state &= ~I_LINKABLE ; } - error =xfs_finish_rename (tp); +out_commit: +/* +* If this is a synchronous mount, make sure that the rename +* transaction goes to disk before returning to the user. +*/ +if (xfs_has_wsync (tp->t_mountp) ||xfs_has_dirsync (tp->t_mountp)) +xfs_trans_set_sync (tp); + + error =xfs_trans_commit (tp); nospace_error =0 ; goto out_unlock;
Re: [PATCH 23/24] xfs: get rid of trivial rename helpers
Looks good:
PATCH 24/24 xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Currently, the XFS_SB_CRC_OFF macro uses the incore superblock struct (xfs_sb) to compute the address of sb_crc within the ondisk superblock struct (xfs_dsb). This is a landmine if we ever change the layout of the incore superblock (as we're about to do), so redefine the macro to use xfs_dsb to compute the layout of xfs_dsb.
--- fs/xfs/libxfs/xfs_format.h | 9 ++++----- fs/xfs/libxfs/xfs_ondisk.h | 1 + 2 files changed, 5 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_format.h +4 -5
@@ -90,8 +90,7 @@ struct xfs_ifork;#define XFSLABEL_MAX 12/* -* Superblock - in core version. Must match the ondisk version below. -* Must be padded to 64 bit alignment. +* Superblock - in core version. Must be padded to 64 bit alignment. */ typedef struct xfs_sb { uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
@@ -178,10 +177,8 @@ typedef struct xfs_sb {/* must be padded to 64 bit alignment */ } xfs_sb_t; -#define XFS_SB_CRC_OFF offsetof(struct xfs_sb, sb_crc) -/* -* Superblock - on disk version. Must match the in core version above. +* Superblock - on disk version. * Must be padded to 64 bit alignment. */ struct xfs_dsb {
@@ -265,6 +262,8 @@ struct xfs_dsb {/* must be padded to 64 bit alignment */ }; +#define XFS_SB_CRC_OFF offsetof(struct xfs_dsb, sb_crc) +/* * Misc. Flags - warning - these will be cleared by xfs_repair unless * a feature bit is set when the flag is used.
fs/xfs/libxfs/xfs_ondisk.h +1 -0
@@ -85,6 +85,7 @@ xfs_check_ondisk_structs(void)XFS_CHECK_STRUCT_SIZE(xfs_attr_leaf_name_remote_t, 12); */ + XFS_CHECK_OFFSET(struct xfs_dsb, sb_crc, 224);XFS_CHECK_OFFSET (xfs_attr_leaf_name_local_t, valuelen,0 );XFS_CHECK_OFFSET (xfs_attr_leaf_name_local_t, namelen,2 );XFS_CHECK_OFFSET (xfs_attr_leaf_name_local_t, nameval,3 );
Re: [PATCH 24/24] xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb
Looks good:
PATCH 2/5 xfs: extent free log intent cleanups
In reply to Darrick J. WongHi all,
This series cleans up some warts in the extent freeing log intent code. We start by acknowledging that this mechanism does not have anything to do with the bmap code by moving it to xfs_alloc.c and giving the function a more descriptive name. Then we clean up the tracepoints and the _finish_one call paths to pass the intent structure around. This reduces the overhead when the tracepoints are disabled and will make things much cleaner when we start adding realtime support in the next patch. I also incorporated a bunch of cleanups from Christoph Hellwig.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=extfree-intent-cleanups
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=extfree-intent-cleanups
---
Commits in this patchset:
* xfs: clean up extent free log intent item tracepoint callsites
* xfs: convert "skip_discard" to a proper flags bitset
* xfs: pass the fsbno to xfs_perag_intent_get
* xfs: add a xefi_entry helper
* xfs: reuse xfs_extent_free_cancel_item
* xfs: factor out a xfs_efd_add_extent helper
* xfs: remove duplicate asserts in xfs_defer_extent_free
* xfs: remove xfs_defer_agfl_block
* xfs: move xfs_extent_free_defer_add to xfs_extfree_item.c
--- fs/xfs/libxfs/xfs_ag.c | 2 - fs/xfs/libxfs/xfs_alloc.c | 92 ++++++++--------------------- fs/xfs/libxfs/xfs_alloc.h | 12 ++-- fs/xfs/libxfs/xfs_bmap.c | 12 +++- fs/xfs/libxfs/xfs_bmap_btree.c | 2 - fs/xfs/libxfs/xfs_ialloc.c | 5 +- fs/xfs/libxfs/xfs_ialloc_btree.c | 2 - fs/xfs/libxfs/xfs_refcount.c | 6 +- fs/xfs/libxfs/xfs_refcount_btree.c | 2 - fs/xfs/scrub/newbt.c | 5 +- fs/xfs/scrub/reap.c | 7 +- fs/xfs/xfs_bmap_item.c | 6 -- fs/xfs/xfs_drain.c | 8 +-- fs/xfs/xfs_drain.h | 5 +- fs/xfs/xfs_extfree_item.c | 115 +++++++++++++++++------------------- fs/xfs/xfs_extfree_item.h | 6 ++ fs/xfs/xfs_refcount_item.c | 5 -- fs/xfs/xfs_reflink.c | 2 - fs/xfs/xfs_rmap_item.c | 5 -- fs/xfs/xfs_trace.h | 33 +++++----- 20 files changed, 141 insertions(+), 191 deletions(-)
PATCH 1/9 xfs: clean up extent free log intent item tracepoint callsites
From: Darrick J. Wong <[email protected]>
Pass the incore EFI structure to the tracepoints instead of open-coding the argument passing. This cleans up the call sites a bit.
--- fs/xfs/libxfs/xfs_alloc.c | 7 +++---- fs/xfs/xfs_extfree_item.c | 6 ++---- fs/xfs/xfs_trace.h | 33 +++++++++++++++------------------ 3 files changed, 20 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +3 -4
@@ -2570,7 +2570,7 @@ xfs_defer_agfl_block( xefi->xefi_owner = oinfo->oi_owner; xefi->xefi_agresv =XFS_AG_RESV_AGFL ; -trace_xfs_agfl_free_defer (mp, agno,0 , agbno,1 ); +trace_xfs_agfl_free_defer (mp, xefi);xfs_extent_free_get_group (mp, xefi);xfs_defer_add (tp, &xefi->xefi_list, &xfs_agfl_free_defer_type);
@@ -2632,9 +2632,8 @@ xfs_defer_extent_free( }else { xefi->xefi_owner =XFS_RMAP_OWN_NULL ; } -trace_xfs_bmap_free_defer (mp, -XFS_FSB_TO_AGNO (tp->t_mountp, bno),0 , -XFS_FSB_TO_AGBNO (tp->t_mountp, bno), len); + +trace_xfs_extent_free_defer (mp, xefi);xfs_extent_free_get_group (mp, xefi); *dfpp =xfs_defer_add (tp, &xefi->xefi_list, &xfs_extent_free_defer_type);
fs/xfs/xfs_extfree_item.c +2 -4
@@ -464,8 +464,7 @@ xfs_extent_free_finish_item(if (xefi->xefi_flags &XFS_EFI_BMBT_BLOCK ) oinfo.oi_flags |=XFS_OWNER_INFO_BMBT_BLOCK ; -trace_xfs_bmap_free_deferred (tp->t_mountp, xefi->xefi_pag->pag_agno,0 , - agbno, xefi->xefi_blockcount); +trace_xfs_extent_free_deferred (mp, xefi);/* * If we need a new transaction to make progress, the caller will log a
@@ -542,8 +541,7 @@ xfs_agfl_free_finish_item( agbno =XFS_FSB_TO_AGBNO (mp, xefi->xefi_startblock); oinfo.oi_owner = xefi->xefi_owner; -trace_xfs_agfl_free_deferred (mp, xefi->xefi_pag->pag_agno,0 , agbno, - xefi->xefi_blockcount); +trace_xfs_agfl_free_deferred (mp, xefi); error =xfs_alloc_read_agf (xefi->xefi_pag, tp,0 , &agbp);if (!error)
fs/xfs/xfs_trace.h +15 -18
@@ -90,6 +90,7 @@ struct xfs_exchrange;struct xfs_getparents ;struct xfs_parent_irec ;struct xfs_attrlist_cursor_kern ; +struct xfs_extent_free_item ;#define XFS_ATTR_FILTER_FLAGS \ { XFS_ATTR_ROOT, "ROOT" }, \
@@ -2681,41 +2682,37 @@ DEFINE_DEFER_PENDING_EVENT(xfs_defer_item_pause);DEFINE_DEFER_PENDING_EVENT (xfs_defer_item_unpause);DECLARE_EVENT_CLASS (xfs_free_extent_deferred_class, - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, - int type, xfs_agblock_t agbno, xfs_extlen_t len), -TP_ARGS (mp, agno, type, agbno, len), + TP_PROTO(struct xfs_mount *mp, struct xfs_extent_free_item *free), +TP_ARGS (mp, free),TP_STRUCT__entry ( __field(dev_t, dev) __field(xfs_agnumber_t, agno) - __field(int, type) __field(xfs_agblock_t, agbno) __field(xfs_extlen_t, len) + __field(unsigned int, flags) ),TP_fast_assign ( __entry->dev = mp->m_super->s_dev; - __entry->agno = agno; - __entry->type = type; - __entry->agbno = agbno; - __entry->len = len; + __entry->agno = XFS_FSB_TO_AGNO(mp, free->xefi_startblock); + __entry->agbno = XFS_FSB_TO_AGBNO(mp, free->xefi_startblock); + __entry->len = free->xefi_blockcount; + __entry->flags = free->xefi_flags; ), -TP_printk ("dev %d:%d op %d agno 0x%x agbno 0x%x fsbcount 0x%x" , +TP_printk ("dev %d:%d agno 0x%x agbno 0x%x fsbcount 0x%x flags 0x%x" ,MAJOR (__entry->dev),MINOR (__entry->dev), - __entry->type, __entry->agno, __entry->agbno, - __entry->len) + __entry->len, + __entry->flags) );#define DEFINE_FREE_EXTENT_DEFERRED_EVENT (name) \ DEFINE_EVENT(xfs_free_extent_deferred_class, name, \ - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \ - int type, \ - xfs_agblock_t bno, \ - xfs_extlen_t len), \ - TP_ARGS(mp, agno, type, bno, len)) -DEFINE_FREE_EXTENT_DEFERRED_EVENT (xfs_bmap_free_defer); -DEFINE_FREE_EXTENT_DEFERRED_EVENT (xfs_bmap_free_deferred); + TP_PROTO(struct xfs_mount *mp, struct xfs_extent_free_item *free), \ + TP_ARGS(mp, free))DEFINE_FREE_EXTENT_DEFERRED_EVENT (xfs_agfl_free_defer);DEFINE_FREE_EXTENT_DEFERRED_EVENT (xfs_agfl_free_deferred); +DEFINE_FREE_EXTENT_DEFERRED_EVENT (xfs_extent_free_defer); +DEFINE_FREE_EXTENT_DEFERRED_EVENT (xfs_extent_free_deferred); DECLARE_EVENT_CLASS(xfs_defer_pending_item_class, TP_PROTO(struct xfs_mount *mp, struct xfs_defer_pending *dfp,
Re: [PATCH 1/9] xfs: clean up extent free log intent item tracepoint callsites
Looks good:
PATCH 2/9 xfs: convert "skip_discard" to a proper flags bitset
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Convert the boolean to skip discard on free into a proper flags field so that we can add more flags in the next patch.
--- fs/xfs/libxfs/xfs_ag.c | 2 +- fs/xfs/libxfs/xfs_alloc.c | 13 +++++++------ fs/xfs/libxfs/xfs_alloc.h | 9 +++++++-- fs/xfs/libxfs/xfs_bmap.c | 12 ++++++++---- fs/xfs/libxfs/xfs_bmap_btree.c | 2 +- fs/xfs/libxfs/xfs_ialloc.c | 5 ++--- fs/xfs/libxfs/xfs_ialloc_btree.c | 2 +- fs/xfs/libxfs/xfs_refcount.c | 6 +++--- fs/xfs/libxfs/xfs_refcount_btree.c | 2 +- fs/xfs/scrub/newbt.c | 5 +++-- fs/xfs/scrub/reap.c | 7 ++++--- fs/xfs/xfs_reflink.c | 2 +- 12 files changed, 39 insertions(+), 28 deletions(-)
fs/xfs/libxfs/xfs_ag.c +1 -1
@@ -1008,7 +1008,7 @@ xfs_ag_shrink_space( goto resv_err; err2 =xfs_free_extent_later (*tpp, args.fsbno, delta,NULL , -XFS_AG_RESV_NONE , true); +XFS_AG_RESV_NONE ,XFS_FREE_EXTENT_SKIP_DISCARD );if (err2) goto resv_err;
fs/xfs/libxfs/xfs_alloc.c +7 -6
@@ -2588,7 +2588,7 @@ xfs_defer_extent_free(xfs_filblks_t len, const struct xfs_owner_info *oinfo, enum xfs_ag_resv_type type, - bool skip_discard, + unsigned int free_flags, struct xfs_defer_pending **dfpp) { struct xfs_extent_free_item *xefi;
@@ -2608,6 +2608,7 @@ xfs_defer_extent_free(ASSERT (len < mp->m_sb.sb_agblocks);ASSERT (agbno + len <= mp->m_sb.sb_agblocks);#endif +ASSERT (!(free_flags & ~XFS_FREE_EXTENT_ALL_FLAGS ));ASSERT (xfs_extfree_item_cache !=NULL );ASSERT (type !=XFS_AG_RESV_AGFL );
@@ -2619,7 +2620,7 @@ xfs_defer_extent_free( xefi->xefi_startblock = bno; xefi->xefi_blockcount = (xfs_extlen_t )len; xefi->xefi_agresv = type; -if (skip_discard) +if (free_flags &XFS_FREE_EXTENT_SKIP_DISCARD ) xefi->xefi_flags |=XFS_EFI_SKIP_DISCARD ;if (oinfo) {ASSERT (oinfo->oi_offset ==0 );
@@ -2647,11 +2648,11 @@ xfs_free_extent_later(xfs_filblks_t len, const struct xfs_owner_info *oinfo, enum xfs_ag_resv_type type, - bool skip_discard) + unsigned int free_flags) { struct xfs_defer_pending *dontcare = NULL; -return xfs_defer_extent_free (tp, bno, len, oinfo, type, skip_discard, +return xfs_defer_extent_free (tp, bno, len, oinfo, type, free_flags, &dontcare); }
@@ -2676,13 +2677,13 @@ xfs_free_extent_later(int xfs_alloc_schedule_autoreap (const struct xfs_alloc_arg *args, -bool skip_discard, +unsigned int free_flags,struct xfs_alloc_autoreap *aarp) {int error; error =xfs_defer_extent_free (args->tp, args->fsbno, args->len, - &args->oinfo, args->resv, skip_discard, &aarp->dfp); + &args->oinfo, args->resv, free_flags, &aarp->dfp);if (error)return error;
fs/xfs/libxfs/xfs_alloc.h +7 -2
@@ -233,7 +233,12 @@ xfs_buf_to_agfl_bno(int xfs_free_extent_later (struct xfs_trans *tp,xfs_fsblock_t bno,xfs_filblks_t len,const struct xfs_owner_info *oinfo, -enum xfs_ag_resv_type type,bool skip_discard); +enum xfs_ag_resv_type type,unsigned int free_flags); + +/* Don't issue a discard for the blocks freed. */ +#define XFS_FREE_EXTENT_SKIP_DISCARD (1U << 0) + +#define XFS_FREE_EXTENT_ALL_FLAGS (XFS_FREE_EXTENT_SKIP_DISCARD)/* * List of extents to be free "later".
@@ -262,7 +267,7 @@ struct xfs_alloc_autoreap { };int xfs_alloc_schedule_autoreap (const struct xfs_alloc_arg *args, -bool skip_discard,struct xfs_alloc_autoreap *aarp); +unsigned int free_flags,struct xfs_alloc_autoreap *aarp);void xfs_alloc_cancel_autoreap (struct xfs_trans *tp,struct xfs_alloc_autoreap *aarp); void xfs_alloc_commit_autoreap(struct xfs_trans *tp,
fs/xfs/libxfs/xfs_bmap.c +8 -4
@@ -605,7 +605,7 @@ xfs_bmap_btree_to_extents(xfs_rmap_ino_bmbt_owner (&oinfo, ip->i_ino, whichfork); error =xfs_free_extent_later (cur->bc_tp, cbno,1 , &oinfo, -XFS_AG_RESV_NONE , false); +XFS_AG_RESV_NONE ,0 );if (error)return error;
@@ -5381,11 +5381,15 @@ xfs_bmap_del_extent_real( error =xfs_rtfree_blocks (tp, del->br_startblock, del->br_blockcount); }else { +unsigned int efi_flags =0 ; + +if ((bflags &XFS_BMAPI_NODISCARD ) || + del->br_state ==XFS_EXT_UNWRITTEN ) + efi_flags |=XFS_FREE_EXTENT_SKIP_DISCARD ; + error =xfs_free_extent_later (tp, del->br_startblock, del->br_blockcount,NULL , -XFS_AG_RESV_NONE , - ((bflags &XFS_BMAPI_NODISCARD ) || - del->br_state ==XFS_EXT_UNWRITTEN )); +XFS_AG_RESV_NONE , efi_flags); }if (error)return error;
fs/xfs/libxfs/xfs_bmap_btree.c +1 -1
@@ -282,7 +282,7 @@ xfs_bmbt_free_block(xfs_rmap_ino_bmbt_owner (&oinfo, ip->i_ino, cur->bc_ino.whichfork); error =xfs_free_extent_later (cur->bc_tp, fsbno,1 , &oinfo, -XFS_AG_RESV_NONE , false); +XFS_AG_RESV_NONE ,0 );if (error)return error;
fs/xfs/libxfs/xfs_ialloc.c +2 -3
@@ -1990,7 +1990,7 @@ xfs_difree_inode_chunk(return xfs_free_extent_later (tp,XFS_AGB_TO_FSB (mp, agno, sagbno),M_IGEO (mp)->ialloc_blks, &XFS_RMAP_OINFO_INODES , -XFS_AG_RESV_NONE , false); +XFS_AG_RESV_NONE ,0 ); }/* holemask is only 16-bits (fits in an unsigned long) */
@@ -2036,8 +2036,7 @@ xfs_difree_inode_chunk(ASSERT (contigblk % mp->m_sb.sb_spino_align ==0 ); error =xfs_free_extent_later (tp,XFS_AGB_TO_FSB (mp, agno, agbno), contigblk, - &XFS_RMAP_OINFO_INODES ,XFS_AG_RESV_NONE , - false); + &XFS_RMAP_OINFO_INODES ,XFS_AG_RESV_NONE ,0 );if (error)return error;
fs/xfs/libxfs/xfs_ialloc_btree.c +1 -1
@@ -170,7 +170,7 @@ __xfs_inobt_free_block(xfs_inobt_mod_blockcount (cur,-1 ); fsbno =XFS_DADDR_TO_FSB (cur->bc_mp,xfs_buf_daddr (bp));return xfs_free_extent_later (cur->bc_tp, fsbno,1 , - &XFS_RMAP_OINFO_INOBT , resv, false); + &XFS_RMAP_OINFO_INOBT , resv,0 ); }STATIC int
fs/xfs/libxfs/xfs_refcount.c +3 -3
@@ -1173,7 +1173,7 @@ xfs_refcount_adjust_extents( tmp.rc_startblock); error =xfs_free_extent_later (cur->bc_tp, fsbno, tmp.rc_blockcount,NULL , -XFS_AG_RESV_NONE , false); +XFS_AG_RESV_NONE ,0 );if (error) goto out_error; }
@@ -1237,7 +1237,7 @@ xfs_refcount_adjust_extents( ext.rc_startblock); error =xfs_free_extent_later (cur->bc_tp, fsbno, ext.rc_blockcount,NULL , -XFS_AG_RESV_NONE , false); +XFS_AG_RESV_NONE ,0 );if (error) goto out_error; }
@@ -2022,7 +2022,7 @@ xfs_refcount_recover_cow_leftovers(/* Free the block. */ error =xfs_free_extent_later (tp, fsb, rr->rr_rrec.rc_blockcount,NULL , -XFS_AG_RESV_NONE , false); +XFS_AG_RESV_NONE ,0 );if (error) goto out_trans;
fs/xfs/libxfs/xfs_refcount_btree.c +1 -1
@@ -109,7 +109,7 @@ xfs_refcountbt_free_block(be32_add_cpu (&agf->agf_refcount_blocks,-1 );xfs_alloc_log_agf (cur->bc_tp, agbp,XFS_AGF_REFCOUNT_BLOCKS );return xfs_free_extent_later (cur->bc_tp, fsbno,1 , - &XFS_RMAP_OINFO_REFC ,XFS_AG_RESV_METADATA , false); + &XFS_RMAP_OINFO_REFC ,XFS_AG_RESV_METADATA ,0 ); }STATIC int
fs/xfs/scrub/newbt.c +3 -2
@@ -160,7 +160,8 @@ xrep_newbt_add_blocks(if (args->tp) {ASSERT (xnr->oinfo.oi_offset ==0 ); - error =xfs_alloc_schedule_autoreap (args, true, &resv->autoreap); + error =xfs_alloc_schedule_autoreap (args, +XFS_FREE_EXTENT_SKIP_DISCARD , &resv->autoreap);if (error) goto out_pag; }
@@ -414,7 +415,7 @@ xrep_newbt_free_extent(*/ fsbno =XFS_AGB_TO_FSB (sc->mp, resv->pag->pag_agno, free_agbno); error =xfs_free_extent_later (sc->tp, fsbno, free_aglen, &xnr->oinfo, - xnr->resv, true); + xnr->resv,XFS_FREE_EXTENT_SKIP_DISCARD );if (error)return error;
fs/xfs/scrub/reap.c +4 -3
@@ -451,7 +451,7 @@ xreap_agextent_iter(xfs_refcount_free_cow_extent (sc->tp, fsbno, *aglenp); error =xfs_free_extent_later (sc->tp, fsbno, *aglenp,NULL , - rs->resv, true); + rs->resv,XFS_FREE_EXTENT_SKIP_DISCARD );if (error)return error;
@@ -477,7 +477,7 @@ xreap_agextent_iter(* system with large EFIs. */ error =xfs_free_extent_later (sc->tp, fsbno, *aglenp, rs->oinfo, - rs->resv, true); + rs->resv,XFS_FREE_EXTENT_SKIP_DISCARD );if (error)return error;
@@ -943,7 +943,8 @@ xrep_reap_bmapi_iter(xfs_trans_mod_dquot_byino (sc->tp, ip,XFS_TRANS_DQ_BCOUNT , -(int64_t )imap->br_blockcount);return xfs_free_extent_later (sc->tp, imap->br_startblock, - imap->br_blockcount,NULL ,XFS_AG_RESV_NONE , true); + imap->br_blockcount,NULL ,XFS_AG_RESV_NONE , +XFS_FREE_EXTENT_SKIP_DISCARD ); }/*
fs/xfs/xfs_reflink.c +1 -1
@@ -603,7 +603,7 @@ xfs_reflink_cancel_cow_blocks( error =xfs_free_extent_later (*tpp, del.br_startblock, del.br_blockcount,NULL , -XFS_AG_RESV_NONE , false); +XFS_AG_RESV_NONE ,0 );if (error)break ;
Re: [PATCH 2/9] xfs: convert "skip_discard" to a proper flags bitset
Looks good:
PATCH 3/9 xfs: pass the fsbno to xfs_perag_intent_get
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
All callers of xfs_perag_intent_get have a fsbno and need boilerplate code to turn that into an agno. Just pass the fsbno to xfs_perag_intent_get and look up the agno there.
--- fs/xfs/xfs_bmap_item.c | 6 +----- fs/xfs/xfs_drain.c | 8 ++++---- fs/xfs/xfs_drain.h | 5 +++-- fs/xfs/xfs_extfree_item.c | 5 +---- fs/xfs/xfs_refcount_item.c | 5 +---- fs/xfs/xfs_rmap_item.c | 5 +---- 6 files changed, 11 insertions(+), 23 deletions(-)
fs/xfs/xfs_bmap_item.c +1 -5
@@ -324,13 +324,9 @@ xfs_bmap_update_get_group( struct xfs_mount *mp, struct xfs_bmap_intent *bi) { - xfs_agnumber_t agno; - if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) return; - agno =XFS_FSB_TO_AGNO (mp, bi->bi_bmap.br_startblock); -/* * Bump the intent count on behalf of the deferred rmap and refcount * intent items that that we can queue when we finish this bmap work.
@@ -338,7 +334,7 @@ xfs_bmap_update_get_group(* intent drops the intent count, ensuring that the intent count * remains nonzero across the transaction roll. */ - bi->bi_pag =xfs_perag_intent_get (mp, agno); + bi->bi_pag =xfs_perag_intent_get (mp, bi->bi_bmap.br_startblock); }/* Add this deferred BUI to the transaction. */
fs/xfs/xfs_drain.c +4 -4
@@ -94,17 +94,17 @@ static inline int xfs_defer_drain_wait(struct xfs_defer_drain *dr) }/* -* Get a passive reference to an AG and declare an intent to update its -* metadata. +* Get a passive reference to the AG that contains a fsbno and declare an intent +* to update its metadata. */ struct xfs_perag *xfs_perag_intent_get (struct xfs_mount *mp, -xfs_agnumber_t agno) +xfs_fsblock_t fsbno) {struct xfs_perag *pag; - pag =xfs_perag_get (mp, agno); + pag =xfs_perag_get (mp,XFS_FSB_TO_AGNO (mp, fsbno));if (!pag)return NULL ;
fs/xfs/xfs_drain.h +3 -2
@@ -62,7 +62,7 @@ void xfs_drain_wait_enable(void);* until the item is finished or cancelled. */ struct xfs_perag *xfs_perag_intent_get (struct xfs_mount *mp, -xfs_agnumber_t agno); +xfs_fsblock_t fsbno);void xfs_perag_intent_put (struct xfs_perag *pag);void xfs_perag_intent_hold (struct xfs_perag *pag);
@@ -76,7 +76,8 @@ struct xfs_defer_drain { /* empty */ };#define xfs_defer_drain_free (dr) ((void)0)#define xfs_defer_drain_init (dr) ((void)0) -#define xfs_perag_intent_get (mp, agno) xfs_perag_get((mp), (agno)) +#define xfs_perag_intent_get (mp, fsbno) \ + xfs_perag_get((mp), XFS_FSB_TO_AGNO(mp, fsbno))#define xfs_perag_intent_put (pag) xfs_perag_put(pag)static inline void xfs_perag_intent_hold (struct xfs_perag *pag) { }
fs/xfs/xfs_extfree_item.c +1 -4
@@ -424,10 +424,7 @@ xfs_extent_free_get_group(struct xfs_mount *mp, struct xfs_extent_free_item *xefi) { - xfs_agnumber_t agno; - - agno =XFS_FSB_TO_AGNO (mp, xefi->xefi_startblock); - xefi->xefi_pag =xfs_perag_intent_get (mp, agno); + xefi->xefi_pag = xfs_perag_intent_get(mp, xefi->xefi_startblock); }/* Release a passive AG ref after some freeing work. */
fs/xfs/xfs_refcount_item.c +1 -4
@@ -330,10 +330,7 @@ xfs_refcount_update_get_group(struct xfs_mount *mp, struct xfs_refcount_intent *ri) { - xfs_agnumber_t agno; - - agno =XFS_FSB_TO_AGNO (mp, ri->ri_startblock); - ri->ri_pag =xfs_perag_intent_get (mp, agno); + ri->ri_pag = xfs_perag_intent_get(mp, ri->ri_startblock); }/* Release a passive AG ref after finishing refcounting work. */
fs/xfs/xfs_rmap_item.c +1 -4
@@ -356,10 +356,7 @@ xfs_rmap_update_get_group(struct xfs_mount *mp, struct xfs_rmap_intent *ri) { - xfs_agnumber_t agno; - - agno =XFS_FSB_TO_AGNO (mp, ri->ri_bmap.br_startblock); - ri->ri_pag =xfs_perag_intent_get (mp, agno); + ri->ri_pag = xfs_perag_intent_get(mp, ri->ri_bmap.br_startblock); }/* Release a passive AG ref after finishing rmapping work. */
PATCH 4/9 xfs: add a xefi_entry helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Add a helper to translate from the item list head to the xfs_extent_free_item structure and use it so shorten assignments and avoid the need for extra local variables.
--- fs/xfs/xfs_extfree_item.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
fs/xfs/xfs_extfree_item.c +10 -12
@@ -303,6 +303,11 @@ static const struct xfs_item_ops xfs_efd_item_ops = { .iop_intent = xfs_efd_item_intent, }; +static inline struct xfs_extent_free_item *xefi_entry (const struct list_head *e) +{ + return list_entry(e, struct xfs_extent_free_item, xefi_list); +} +/* * Fill the EFD with all extents from the EFI when we need to roll the * transaction and continue with a new EFI.
@@ -338,11 +343,8 @@ xfs_extent_free_diff_items(const struct list_head *a, const struct list_head *b) { - struct xfs_extent_free_item *ra; -struct xfs_extent_free_item *rb; - - ra = container_of(a, struct xfs_extent_free_item, xefi_list); - rb = container_of(b, struct xfs_extent_free_item, xefi_list); + struct xfs_extent_free_item *ra = xefi_entry(a); +struct xfs_extent_free_item *rb =xefi_entry (b);return ra->xefi_pag->pag_agno - rb->xefi_pag->pag_agno; }
@@ -444,7 +446,7 @@ xfs_extent_free_finish_item( struct xfs_btree_cur **state) {struct xfs_owner_info oinfo = { }; -struct xfs_extent_free_item *xefi; +struct xfs_extent_free_item *xefi =xefi_entry (item);struct xfs_efd_log_item *efdp =EFD_ITEM (done);struct xfs_mount *mp = tp->t_mountp;struct xfs_extent *extp;
@@ -452,7 +454,6 @@ xfs_extent_free_finish_item(xfs_agblock_t agbno;int error =0 ; - xefi = container_of(item, struct xfs_extent_free_item, xefi_list); agbno =XFS_FSB_TO_AGBNO (mp, xefi->xefi_startblock); oinfo.oi_owner = xefi->xefi_owner;
@@ -504,9 +505,7 @@ STATIC voidxfs_extent_free_cancel_item ( struct list_head *item) { -struct xfs_extent_free_item *xefi; - - xefi = container_of(item, struct xfs_extent_free_item, xefi_list); +struct xfs_extent_free_item *xefi =xefi_entry (item);xfs_extent_free_put_group (xefi);kmem_cache_free (xfs_extfree_item_cache, xefi);
@@ -526,14 +525,13 @@ xfs_agfl_free_finish_item(struct xfs_owner_info oinfo = { };struct xfs_mount *mp = tp->t_mountp;struct xfs_efd_log_item *efdp =EFD_ITEM (done); -struct xfs_extent_free_item *xefi; +struct xfs_extent_free_item *xefi =xefi_entry (item);struct xfs_extent *extp;struct xfs_buf *agbp;int error;xfs_agblock_t agbno;uint next_extent; - xefi = container_of(item, struct xfs_extent_free_item, xefi_list);ASSERT (xefi->xefi_blockcount ==1 ); agbno =XFS_FSB_TO_AGBNO (mp, xefi->xefi_startblock); oinfo.oi_owner = xefi->xefi_owner;
PATCH 5/9 xfs: reuse xfs_extent_free_cancel_item
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Reuse xfs_extent_free_cancel_item to put the AG/RTG and free the item in a few places that currently open code the logic.
--- fs/xfs/xfs_extfree_item.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-)
fs/xfs/xfs_extfree_item.c +13 -15
@@ -437,6 +437,17 @@ xfs_extent_free_put_group(xfs_perag_intent_put (xefi->xefi_pag); } +/* Cancel a free extent. */ +STATIC void +xfs_extent_free_cancel_item ( +struct list_head *item) +{ +struct xfs_extent_free_item *xefi =xefi_entry (item); + +xfs_extent_free_put_group (xefi); +kmem_cache_free (xfs_extfree_item_cache, xefi); +} +/* Process a free extent. */ STATIC int xfs_extent_free_finish_item(
@@ -487,8 +498,7 @@ xfs_extent_free_finish_item( extp->ext_len = xefi->xefi_blockcount; efdp->efd_next_extent++; -xfs_extent_free_put_group (xefi); -kmem_cache_free (xfs_extfree_item_cache, xefi); +xfs_extent_free_cancel_item (item);return error; }
@@ -500,17 +510,6 @@ xfs_extent_free_abort_intent(xfs_efi_release (EFI_ITEM (intent)); } -/* Cancel a free extent. */ -STATIC void -xfs_extent_free_cancel_item ( -struct list_head *item) -{ -struct xfs_extent_free_item *xefi =xefi_entry (item); - -xfs_extent_free_put_group (xefi); -kmem_cache_free (xfs_extfree_item_cache, xefi); -} -/* * AGFL blocks are accounted differently in the reserve pools and are not * inserted into the busy extent list.
@@ -550,8 +549,7 @@ xfs_agfl_free_finish_item( extp->ext_len = xefi->xefi_blockcount; efdp->efd_next_extent++; -xfs_extent_free_put_group (xefi); -kmem_cache_free (xfs_extfree_item_cache, xefi); +xfs_extent_free_cancel_item (&xefi->xefi_list);return error; }
PATCH 6/9 xfs: factor out a xfs_efd_add_extent helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Factor out a helper to add an extent to and EFD instead of duplicating the logic in two places.
--- fs/xfs/xfs_extfree_item.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-)
fs/xfs/xfs_extfree_item.c +18 -19
@@ -336,6 +336,22 @@ xfs_efd_from_efi( efdp->efd_next_extent = efip->efi_format.efi_nextents; } +static void +xfs_efd_add_extent ( +struct xfs_efd_log_item *efdp, +struct xfs_extent_free_item *xefi) +{ +struct xfs_extent *extp; + +ASSERT (efdp->efd_next_extent < efdp->efd_format.efd_nextents); + + extp = &efdp->efd_format.efd_extents[efdp->efd_next_extent]; + extp->ext_start = xefi->xefi_startblock; + extp->ext_len = xefi->xefi_blockcount; + + efdp->efd_next_extent++; +} +/* Sort bmap items by AG. */ static int xfs_extent_free_diff_items(
@@ -460,8 +476,6 @@ xfs_extent_free_finish_item(struct xfs_extent_free_item *xefi =xefi_entry (item);struct xfs_efd_log_item *efdp =EFD_ITEM (done);struct xfs_mount *mp = tp->t_mountp; -struct xfs_extent *extp; -uint next_extent;xfs_agblock_t agbno;int error =0 ;
@@ -490,14 +504,7 @@ xfs_extent_free_finish_item(return error; } -/* Add the work we finished to the EFD, even though nobody uses that */ - next_extent = efdp->efd_next_extent; -ASSERT (next_extent < efdp->efd_format.efd_nextents); - extp = &(efdp->efd_format.efd_extents[next_extent]); - extp->ext_start = xefi->xefi_startblock; - extp->ext_len = xefi->xefi_blockcount; - efdp->efd_next_extent++; - +xfs_efd_add_extent (efdp, xefi);xfs_extent_free_cancel_item (item);return error; }
@@ -525,11 +532,9 @@ xfs_agfl_free_finish_item(struct xfs_mount *mp = tp->t_mountp;struct xfs_efd_log_item *efdp =EFD_ITEM (done);struct xfs_extent_free_item *xefi =xefi_entry (item); -struct xfs_extent *extp;struct xfs_buf *agbp;int error;xfs_agblock_t agbno; -uint next_extent;ASSERT (xefi->xefi_blockcount ==1 ); agbno =XFS_FSB_TO_AGBNO (mp, xefi->xefi_startblock);
@@ -542,13 +547,7 @@ xfs_agfl_free_finish_item( error =xfs_free_agfl_block (tp, xefi->xefi_pag->pag_agno, agbno, agbp, &oinfo); - next_extent = efdp->efd_next_extent; -ASSERT (next_extent < efdp->efd_format.efd_nextents); - extp = &(efdp->efd_format.efd_extents[next_extent]); - extp->ext_start = xefi->xefi_startblock; - extp->ext_len = xefi->xefi_blockcount; - efdp->efd_next_extent++; - +xfs_efd_add_extent (efdp, xefi);xfs_extent_free_cancel_item (&xefi->xefi_list);return error; }
PATCH 7/9 xfs: remove duplicate asserts in xfs_defer_extent_free
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
The bno/len verification is already done by the calls to xfs_verify_rtbext / xfs_verify_fsbext, and reporting a corruption error seem like the better handling than tripping an assert anyway.
--- fs/xfs/libxfs/xfs_alloc.c | 13 ------------- 1 file changed, 13 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +0 -13
@@ -2593,23 +2593,10 @@ xfs_defer_extent_free( {struct xfs_extent_free_item *xefi;struct xfs_mount *mp = tp->t_mountp; -#ifdef DEBUG -xfs_agnumber_t agno; -xfs_agblock_t agbno; -ASSERT (bno !=NULLFSBLOCK ); -ASSERT (len >0 );ASSERT (len <=XFS_MAX_BMBT_EXTLEN );ASSERT (!isnullstartblock (bno)); - agno =XFS_FSB_TO_AGNO (mp, bno); - agbno =XFS_FSB_TO_AGBNO (mp, bno); -ASSERT (agno < mp->m_sb.sb_agcount); -ASSERT (agbno < mp->m_sb.sb_agblocks); -ASSERT (len < mp->m_sb.sb_agblocks); -ASSERT (agbno + len <= mp->m_sb.sb_agblocks); -#endif ASSERT (!(free_flags & ~XFS_FREE_EXTENT_ALL_FLAGS )); -ASSERT (xfs_extfree_item_cache !=NULL );ASSERT (type !=XFS_AG_RESV_AGFL );if (XFS_IS_CORRUPT (mp, !xfs_verify_fsbext (mp, bno, len)))
PATCH 8/9 xfs: remove xfs_defer_agfl_block
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
xfs_free_extent_later can handle the extra AGFL special casing with very little extra logic.
--- fs/xfs/libxfs/xfs_alloc.c | 67 +++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 45 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +22 -45
@@ -2535,48 +2535,6 @@ xfs_agfl_reset(clear_bit (XFS_AGSTATE_AGFL_NEEDS_RESET , &pag->pag_opstate); } -/* -* Defer an AGFL block free. This is effectively equivalent to -* xfs_free_extent_later() with some special handling particular to AGFL blocks. -* -* Deferring AGFL frees helps prevent log reservation overruns due to too many -* allocation operations in a transaction. AGFL frees are prone to this problem -* because for one they are always freed one at a time. Further, an immediate -* AGFL block free can cause a btree join and require another block free before -* the real allocation can proceed. Deferring the free disconnects freeing up -* the AGFL slot from freeing the block. -*/ -static int -xfs_defer_agfl_block ( -struct xfs_trans *tp, -xfs_agnumber_t agno, -xfs_agblock_t agbno, -struct xfs_owner_info *oinfo) -{ -struct xfs_mount *mp = tp->t_mountp; -struct xfs_extent_free_item *xefi; -xfs_fsblock_t fsbno =XFS_AGB_TO_FSB (mp, agno, agbno); - -ASSERT (xfs_extfree_item_cache !=NULL ); -ASSERT (oinfo !=NULL ); - -if (XFS_IS_CORRUPT (mp, !xfs_verify_fsbno (mp, fsbno))) -return -EFSCORRUPTED ; - - xefi =kmem_cache_zalloc (xfs_extfree_item_cache, -GFP_KERNEL | __GFP_NOFAIL); - xefi->xefi_startblock = fsbno; - xefi->xefi_blockcount =1 ; - xefi->xefi_owner = oinfo->oi_owner; - xefi->xefi_agresv =XFS_AG_RESV_AGFL ; - -trace_xfs_agfl_free_defer (mp, xefi); - -xfs_extent_free_get_group (mp, xefi); -xfs_defer_add (tp, &xefi->xefi_list, &xfs_agfl_free_defer_type); -return 0 ; -} -/* * Add the extent to the list of extents to be free at transaction end. * The list is maintained sorted (by block number).
@@ -2624,7 +2582,13 @@ xfs_defer_extent_free(trace_xfs_extent_free_defer (mp, xefi);xfs_extent_free_get_group (mp, xefi); - *dfpp =xfs_defer_add (tp, &xefi->xefi_list, &xfs_extent_free_defer_type); + +if (xefi->xefi_agresv ==XFS_AG_RESV_AGFL ) + *dfpp =xfs_defer_add (tp, &xefi->xefi_list, + &xfs_agfl_free_defer_type); +else + *dfpp =xfs_defer_add (tp, &xefi->xefi_list, + &xfs_extent_free_defer_type);return 0 ; }
@@ -2882,8 +2846,21 @@ xfs_alloc_fix_freelist(if (error) goto out_agbp_relse; -/* defer agfl frees */ - error =xfs_defer_agfl_block (tp, args->agno, bno, &targs.oinfo); +/* +* Defer the AGFL block free. +* +* This helps to prevent log reservation overruns due to too +* many allocation operations in a transaction. AGFL frees are +* prone to this problem because for one they are always freed +* one at a time. Further, an immediate AGFL block free can +* cause a btree join and require another block free before the +* real allocation can proceed. +* Deferring the free disconnects freeing up the AGFL slot from +* freeing the block. +*/ + error =xfs_free_extent_later (tp, +XFS_AGB_TO_FSB (mp, args->agno, bno),1 , + &targs.oinfo,XFS_AG_RESV_AGFL ,0 );if (error) goto out_agbp_relse; }
kernel test robot
build botRe: [PATCH 8/9] xfs: remove xfs_defer_agfl_block
kernel test robot noticed "Assertion_failed" on:
Hello,
kernel test robot noticed "Assertion_failed" on:
commit: f53305b8c490815f244c0d44b096abd4f2a63aeb ("[PATCH 8/9] xfs: remove xfs_defer_agfl_block")
url: https://github.com/intel-lab-lkp/linux/commits/Darrick-J-Wong/xfs-convert-skip_discard-to-a-proper-flags-bitset/20240625-204930
base: https://git.kernel.org/cgit/fs/xfs/xfs-linux.git for-next
patch link: https://lore.kernel.org/all/171892418834.3183906.376857417040987772.stgit@frogsfrogsfrogs/
patch subject: [PATCH 8/9] xfs: remove xfs_defer_agfl_block
in testcase: stress-ng
version: stress-ng-x86_64-ecd3fe291-1_20240612
with following parameters:
nr_threads: 100% disk: 1HDD testtime: 60s fs: xfs test: copy-file cpufreq_governor: performance
compiler: gcc-13
test machine: 64 threads 2 sockets Intel(R) Xeon(R) Gold 6346 CPU @ 3.10GHz (Ice Lake) with 256G memory
(please refer to attached dmesg/kmsg for entire log/backtrace)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]
user :err : [ 88.899876] [ perf record: Woken up 5 times to write data ]
user :err : [ 88.979592] [ perf record: Captured and wrote 9.304 MB /tmp/lkp/perf_c2c.data (5470 samples) ]
kern :warn : [ 101.832173] XFS: Assertion failed: type != XFS_AG_RESV_AGFL, file: fs/xfs/libxfs/xfs_alloc.c, line: 2558 kern :warn : [ 101.842834] ------------[ cut here ]------------ kern :warn : [ 101.848538] WARNING: CPU: 22 PID: 536 at fs/xfs/xfs_message.c:89 asswarn (kbuild/src/consumer/fs/xfs/xfs_message.c:89 (discriminator 1)) xfs kern :warn : [ 101.857842] Modules linked in: xfs intel_rapl_msr intel_rapl_common x86_pkg_temp_thermal coretemp btrfs blake2b_generic kvm_intel ipmi_ssif xor raid6_pq libcrc32c kvm crct10dif_pclmul crc32_pclmul crc32c_intel sd_mod ghash_clmulni_intel sg sha512_ssse3 nvme ahci rapl libahci ast nvme_core binfmt_misc t10_pi intel_cstate mei_me drm_shmem_helper acpi_power_meter intel_th_gth crc64_rocksoft_generic i2c_i801 crc64_rocksoft ioatdma intel_th_pci libata intel_uncore drm_kms_helper megaraid_sas i2c_smbus ipmi_si mei intel_pch_thermal acpi_ipmi dax_hmem crc64 intel_th dca wmi ipmi_devintf ipmi_msghandler joydev drm fuse loop dm_mod ip_tables user :notice: [ 101.860115] stress-ng: metrc: [2914] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s CPU used per RSS Max kern :warn : [ 101.914497] CPU: 22 PID: 536 Comm: kworker/22:1 Not tainted 6.10.0-rc4-00009-gf53305b8c490 #1
kern :warn : [ 101.929361] Hardware name: Inspur NF5180M6/NF5180M6, BIOS 06.00.04 04/12/2022 user :notice: [ 101.940509] stress-ng: metrc: [2914] (secs) (secs) (secs) (real time) (usr+sys time) instance (%) (KB) kern :warn : [ 101.940764] Workqueue: xfs-inodegc/sdb1 xfs_inodegc_worker [xfs]
kern :warn : [ 101.962311] RIP: 0010:asswarn (kbuild/src/consumer/fs/xfs/xfs_message.c:89 (discriminator 1)) xfs
user :notice: [ 101.970762] stress-ng: metrc: [2914] copy-file 10938 60.17 0.14 4.61 181.79 2300.90 0.12 3244
kern :warn : [ 101.971200] Code: 90 90 66 0f 1f 00 0f 1f 44 00 00 49 89 d0 41 89 c9 48 c7 c2 90 ed 01 c1 48 89 f1 48 89 fe 48 c7 c7 20 07 01 c1 e8 18 fd ff ff <0f> 0b c3 cc cc cc cc 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 All code
========
0: 90 nop 1: 90 nop 2: 66 0f 1f 00 nopw (%rax) 6: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) b: 49 89 d0 mov %rdx,%r8 e: 41 89 c9 mov %ecx,%r9d 11: 48 c7 c2 90 ed 01 c1 mov $0xffffffffc101ed90,%rdx 18: 48 89 f1 mov %rsi,%rcx 1b: 48 89 fe mov %rdi,%rsi 1e: 48 c7 c7 20 07 01 c1 mov $0xffffffffc1010720,%rdi 25: e8 18 fd ff ff callq 0xfffffffffffffd42 2a:* 0f 0b ud2 <-- trapping instruction 2c: c3 retq 2d: cc int3 2e: cc int3 2f: cc int3 30: cc int3 31: 90 nop 32: 90 nop 33: 90 nop 34: 90 nop 35: 90 nop 36: 90 nop 37: 90 nop 38: 90 nop 39: 90 nop 3a: 90 nop 3b: 90 nop 3c: 90 nop 3d: 90 nop 3e: 90 nop 3f: 90 nop
Code starting with the faulting instruction
===========================================
0: 0f 0b ud2 2: c3 retq 3: cc int3 4: cc int3 5: cc int3 6: cc int3 7: 90 nop 8: 90 nop 9: 90 nop a: 90 nop b: 90 nop c: 90 nop d: 90 nop e: 90 nop f: 90 nop 10: 90 nop 11: 90 nop 12: 90 nop 13: 90 nop 14: 90 nop 15: 90 nop
user :notice: [ 101.974008] stress-ng: metrc: [2914] miscellaneous metrics: kern :warn : [ 101.978448] RSP: 0018:ffa000000db6f9b8 EFLAGS: 00010246
user :notice: [ 101.993576] stress-ng: metrc: [2914] copy-file 2629.63 MB per sec copy rate (harmonic mean of 64 instances)
kern :warn : [ 102.020066] RAX: 0000000000000000 RBX: 0000000000000001 RCX: 000000007fffffff kern :warn : [ 102.020067] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffffffffc1010720 user :notice: [ 102.026590] stress-ng: info: [2914] for a 60.26s run time: kern :warn : [ 102.028177] RBP: ffa000000db6f9f8 R08: 0000000000000000 R09: 000000000000000a kern :warn : [ 102.028178] R10: 000000000000000a R11: 0fffffffffffffff R12: ffa000000db6faa0 kern :warn : [ 102.028179] R13: ff11004060da7790 R14: 0000000000000000 R15: 0000000000000001
user :notice: [ 102.040178] stress-ng: info: [2914] 3856.62s available CPU time kern :warn : [ 102.041662] FS: 0000000000000000(0000) GS:ff11003fc0900000(0000) knlGS:0000000000000000
user :notice: [ 102.044574] stress-ng: info: [2914] 0.14s user time ( 0.00%) kern :warn : [ 102.051679] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 kern :warn : [ 102.051681] CR2: 000056061f02f700 CR3: 000000407de1c002 CR4: 0000000000771ef0
user :notice: [ 102.060248] stress-ng: info: [2914] 4.63s system time ( 0.12%) kern :warn : [ 102.065773] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kern :warn : [ 102.081424] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 kern :warn : [ 102.081426] PKRU: 55555554 user :notice: [ 102.089981] stress-ng: info: [2914] 4.77s total time ( 0.12%) kern :warn : [ 102.091444] Call Trace: kern :warn : [ 102.091446] <TASK>
user :notice: [ 102.099108] stress-ng: info: [2914] load average: 42.09 12.22 4.21 kern :warn : [ 102.107184] ? __warn (kbuild/src/consumer/kernel/panic.c:693)
The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20240703/[email protected]
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 9/9 xfs: move xfs_extent_free_defer_add to xfs_extfree_item.c
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the code that adds the incore xfs_extent_free_item deferred work data to a transaction live with the EFI log item code. This means that the allocator code no longer has to know about the inner workings of the EFI log items.
As a consequence, we can get rid of the _{get,put}_group helpers.
--- fs/xfs/libxfs/xfs_alloc.c | 12 ++---------- fs/xfs/libxfs/xfs_alloc.h | 3 --- fs/xfs/xfs_extfree_item.c | 31 +++++++++++++++++-------------- fs/xfs/xfs_extfree_item.h | 6 ++++++ 4 files changed, 25 insertions(+), 27 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +2 -10
@@ -27,6 +27,7 @@#include "xfs_ag_resv.h" #include "xfs_bmap.h" #include "xfs_health.h" +#include "xfs_extfree_item.h" struct kmem_cache *xfs_extfree_item_cache;
@@ -2579,16 +2580,7 @@ xfs_defer_extent_free( xefi->xefi_owner =XFS_RMAP_OWN_NULL ; } -trace_xfs_extent_free_defer (mp, xefi); - -xfs_extent_free_get_group (mp, xefi); - -if (xefi->xefi_agresv ==XFS_AG_RESV_AGFL ) - *dfpp =xfs_defer_add (tp, &xefi->xefi_list, - &xfs_agfl_free_defer_type); -else - *dfpp =xfs_defer_add (tp, &xefi->xefi_list, - &xfs_extent_free_defer_type); +xfs_extent_free_defer_add (tp, xefi, dfpp);return 0 ; }
fs/xfs/libxfs/xfs_alloc.h +0 -3
@@ -254,9 +254,6 @@ struct xfs_extent_free_item {enum xfs_ag_resv_type xefi_agresv; }; -void xfs_extent_free_get_group (struct xfs_mount *mp, -struct xfs_extent_free_item *xefi); -#define XFS_EFI_SKIP_DISCARD (1U << 0)/* don't issue discard */ #define XFS_EFI_ATTR_FORK (1U << 1)/* freeing attr fork block */ #define XFS_EFI_BMBT_BLOCK (1U << 2)/* freeing bmap btree block */
fs/xfs/xfs_extfree_item.c +17 -14
@@ -436,21 +436,24 @@ xfs_extent_free_create_done(return &efdp->efd_item; } -/* Take a passive ref to the AG containing the space we're freeing. */ +/* Add this deferred EFI to the transaction. */ void -xfs_extent_free_get_group ( -struct xfs_mount *mp, -struct xfs_extent_free_item *xefi) +xfs_extent_free_defer_add ( +struct xfs_trans *tp, +struct xfs_extent_free_item *xefi, +struct xfs_defer_pending **dfpp) { +struct xfs_mount *mp = tp->t_mountp; + +trace_xfs_extent_free_defer (mp, xefi); + xefi->xefi_pag =xfs_perag_intent_get (mp, xefi->xefi_startblock); -} - -/* Release a passive AG ref after some freeing work. */ -static inline void -xfs_extent_free_put_group ( -struct xfs_extent_free_item *xefi) -{ -xfs_perag_intent_put (xefi->xefi_pag); +if (xefi->xefi_agresv ==XFS_AG_RESV_AGFL ) + *dfpp =xfs_defer_add (tp, &xefi->xefi_list, + &xfs_agfl_free_defer_type); +else + *dfpp =xfs_defer_add (tp, &xefi->xefi_list, + &xfs_extent_free_defer_type); }/* Cancel a free extent. */
@@ -460,7 +463,7 @@ xfs_extent_free_cancel_item( {struct xfs_extent_free_item *xefi =xefi_entry (item); -xfs_extent_free_put_group (xefi); +xfs_perag_intent_put (xefi->xefi_pag);kmem_cache_free (xfs_extfree_item_cache, xefi); }
@@ -575,7 +578,7 @@ xfs_efi_recover_work( xefi->xefi_blockcount = extp->ext_len; xefi->xefi_agresv =XFS_AG_RESV_NONE ; xefi->xefi_owner =XFS_RMAP_OWN_UNKNOWN ; -xfs_extent_free_get_group (mp, xefi); + xefi->xefi_pag =xfs_perag_intent_get (mp, extp->ext_start);xfs_defer_add_item (dfp, &xefi->xefi_list); }
fs/xfs/xfs_extfree_item.h +6 -0
@@ -88,4 +88,10 @@ xfs_efd_log_item_sizeof(extern struct kmem_cache *xfs_efi_cache;extern struct kmem_cache *xfs_efd_cache; +struct xfs_extent_free_item ; + +void xfs_extent_free_defer_add (struct xfs_trans *tp, +struct xfs_extent_free_item *xefi, +struct xfs_defer_pending **dfpp); +#endif /* __XFS_EXTFREE_ITEM_H__ */
Re: [PATCH 9/9] xfs: move xfs_extent_free_defer_add to xfs_extfree_item.c
Quoted 4 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Move the code that adds the incore
xfs_extent_free_itemdeferred work data to a transaction live with the EFI log item code. This means that
s/live/to live/ ?
Otherwise looks good:
PATCH 3/5 xfs: rmap log intent cleanups
In reply to Darrick J. WongHi all,
This series cleans up the rmap intent code before we start adding support for realtime devices. Similar to previous intent cleanup patchsets, we start transforming the tracepoints so that the data extraction are done inside the tracepoint code, and then we start passing the intent itself to the _finish_one function. This reduces the boxing and unboxing of parameters.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=rmap-intent-cleanups
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=rmap-intent-cleanups
---
Commits in this patchset:
* xfs: give rmap btree cursor error tracepoints their own class
* xfs: prepare rmap btree tracepoints for widening
* xfs: clean up rmap log intent item tracepoint callsites
* xfs: remove xfs_trans_set_rmap_flags
* xfs: add a ri_entry helper
* xfs: reuse xfs_rmap_update_cancel_item
* xfs: don't bother calling xfs_rmap_finish_one_cleanup in xfs_rmap_finish_one
* xfs: simplify usage of the rcur local variable in xfs_rmap_finish_one
* xfs: move xfs_rmap_update_defer_add to xfs_rmap_item.c
--- fs/xfs/libxfs/xfs_rmap.c | 268 ++++++++++++++++------------------------------ fs/xfs/libxfs/xfs_rmap.h | 15 ++- fs/xfs/xfs_rmap_item.c | 148 +++++++++++++------------ fs/xfs/xfs_rmap_item.h | 4 + fs/xfs/xfs_trace.c | 1 fs/xfs/xfs_trace.h | 198 ++++++++++++++++++++++++---------- 6 files changed, 321 insertions(+), 313 deletions(-)
PATCH 1/9 xfs: give rmap btree cursor error tracepoints their own class
From: Darrick J. Wong <[email protected]>
Create a new tracepoint class for btree-related errors, then convert all the rmap tracepoints to use it. Also fix the one tracepoint that was abusing the old class by making it a separate tracepoint.
--- fs/xfs/libxfs/xfs_rmap.c | 33 ++++--------- fs/xfs/xfs_trace.h | 117 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 110 insertions(+), 40 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +11 -22
@@ -111,8 +111,7 @@ xfs_rmap_update( xfs_rmap_irec_offset_pack(irec)); error =xfs_btree_update (cur, &rec);if (error) -trace_xfs_rmap_update_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_rmap_update_error (cur, error, _RET_IP_);return error; }
@@ -155,8 +154,7 @@ xfs_rmap_insert( } done:if (error) -trace_xfs_rmap_insert_error (rcur->bc_mp, - rcur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_rmap_insert_error (rcur, error, _RET_IP_);return error; }
@@ -194,8 +192,7 @@ xfs_rmap_delete( } done:if (error) -trace_xfs_rmap_delete_error (rcur->bc_mp, - rcur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_rmap_delete_error (rcur, error, _RET_IP_);return error; }
@@ -816,8 +813,7 @@ xfs_rmap_unmap( unwritten, oinfo); out_error:if (error) -trace_xfs_rmap_unmap_error (mp, cur->bc_ag.pag->pag_agno, - error, _RET_IP_); +trace_xfs_rmap_unmap_error (cur, error, _RET_IP_);return error; }
@@ -1148,8 +1144,7 @@ xfs_rmap_map( unwritten, oinfo); out_error:if (error) -trace_xfs_rmap_map_error (mp, cur->bc_ag.pag->pag_agno, - error, _RET_IP_); +trace_xfs_rmap_map_error (cur, error, _RET_IP_);return error; }
@@ -1344,8 +1339,7 @@ xfs_rmap_convert( RIGHT.rm_blockcount > XFS_RMAP_LEN_MAX) state &= ~RMAP_RIGHT_CONTIG ; -trace_xfs_rmap_convert_state (mp, cur->bc_ag.pag->pag_agno, state, - _RET_IP_); +trace_xfs_rmap_convert_state (cur, state, _RET_IP_);/* reset the cursor back to PREV */ error =xfs_rmap_lookup_le (cur, bno, owner, offset, oldext,NULL , &i);
@@ -1698,8 +1692,7 @@ xfs_rmap_convert( unwritten, oinfo); done:if (error) -trace_xfs_rmap_convert_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_rmap_convert_error (cur, error, _RET_IP_);return error; }
@@ -1822,8 +1815,7 @@ xfs_rmap_convert_shared( RIGHT.rm_blockcount > XFS_RMAP_LEN_MAX) state &= ~RMAP_RIGHT_CONTIG ; -trace_xfs_rmap_convert_state (mp, cur->bc_ag.pag->pag_agno, state, - _RET_IP_); +trace_xfs_rmap_convert_state (cur, state, _RET_IP_);/* * Switch out based on the FILLING and CONTIG state bits. */
@@ -2125,8 +2117,7 @@ xfs_rmap_convert_shared( unwritten, oinfo); done:if (error) -trace_xfs_rmap_convert_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_rmap_convert_error (cur, error, _RET_IP_);return error; }
@@ -2325,8 +2316,7 @@ xfs_rmap_unmap_shared( unwritten, oinfo); out_error:if (error) -trace_xfs_rmap_unmap_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_rmap_unmap_error (cur, error, _RET_IP_);return error; }
@@ -2486,8 +2476,7 @@ xfs_rmap_map_shared( unwritten, oinfo); out_error:if (error) -trace_xfs_rmap_map_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_rmap_map_error (cur, error, _RET_IP_);return error; }
fs/xfs/xfs_trace.h +99 -18
160 lines not on this page · raw message
Re: [PATCH 1/9] xfs: give rmap btree cursor error tracepoints their own class
Looks good:
PATCH 2/9 xfs: prepare rmap btree tracepoints for widening
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Prepare the rmap btree tracepoints for use with realtime rmap btrees by making them take the btree cursor object as a parameter. This will save us a lot of trouble later on.
--- fs/xfs/libxfs/xfs_rmap.c | 184 ++++++++++++++++++---------------------------- fs/xfs/xfs_trace.h | 24 +++--- 2 files changed, 85 insertions(+), 123 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +73 -111
@@ -100,8 +100,7 @@ xfs_rmap_update(union xfs_btree_rec rec;int error; -trace_xfs_rmap_update (cur->bc_mp, cur->bc_ag.pag->pag_agno, - irec->rm_startblock, irec->rm_blockcount, +trace_xfs_rmap_update (cur, irec->rm_startblock, irec->rm_blockcount, irec->rm_owner, irec->rm_offset, irec->rm_flags); rec.rmap.rm_startblock =cpu_to_be32 (irec->rm_startblock);
@@ -127,8 +126,7 @@ xfs_rmap_insert(int i;int error; -trace_xfs_rmap_insert (rcur->bc_mp, rcur->bc_ag.pag->pag_agno, agbno, - len, owner, offset, flags); +trace_xfs_rmap_insert (rcur, agbno, len, owner, offset, flags); error =xfs_rmap_lookup_eq (rcur, agbno, len, owner, offset, flags, &i);if (error)
@@ -170,8 +168,7 @@ xfs_rmap_delete(int i;int error; -trace_xfs_rmap_delete (rcur->bc_mp, rcur->bc_ag.pag->pag_agno, agbno, - len, owner, offset, flags); +trace_xfs_rmap_delete (rcur, agbno, len, owner, offset, flags); error =xfs_rmap_lookup_eq (rcur, agbno, len, owner, offset, flags, &i);if (error)
@@ -339,8 +336,7 @@ xfs_rmap_find_left_neighbor_helper( {struct xfs_find_left_neighbor_info *info = priv; -trace_xfs_rmap_find_left_neighbor_candidate (cur->bc_mp, - cur->bc_ag.pag->pag_agno, rec->rm_startblock, +trace_xfs_rmap_find_left_neighbor_candidate (cur, rec->rm_startblock, rec->rm_blockcount, rec->rm_owner, rec->rm_offset, rec->rm_flags);
@@ -390,8 +386,8 @@ xfs_rmap_find_left_neighbor( info.high.rm_blockcount =0 ; info.irec = irec; -trace_xfs_rmap_find_left_neighbor_query (cur->bc_mp, - cur->bc_ag.pag->pag_agno, bno,0 , owner, offset, flags); +trace_xfs_rmap_find_left_neighbor_query (cur, bno,0 , owner, offset, + flags);/* * Historically, we always used the range query to walk every reverse
@@ -422,8 +418,7 @@ xfs_rmap_find_left_neighbor(return error; *stat =1 ; -trace_xfs_rmap_find_left_neighbor_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno, irec->rm_startblock, +trace_xfs_rmap_find_left_neighbor_result (cur, irec->rm_startblock, irec->rm_blockcount, irec->rm_owner, irec->rm_offset, irec->rm_flags);return 0 ;
@@ -438,8 +433,7 @@ xfs_rmap_lookup_le_range_helper( {struct xfs_find_left_neighbor_info *info = priv; -trace_xfs_rmap_lookup_le_range_candidate (cur->bc_mp, - cur->bc_ag.pag->pag_agno, rec->rm_startblock, +trace_xfs_rmap_lookup_le_range_candidate (cur, rec->rm_startblock, rec->rm_blockcount, rec->rm_owner, rec->rm_offset, rec->rm_flags);
@@ -486,8 +480,7 @@ xfs_rmap_lookup_le_range( *stat =0 ; info.irec = irec; -trace_xfs_rmap_lookup_le_range (cur->bc_mp, cur->bc_ag.pag->pag_agno, - bno,0 , owner, offset, flags); +trace_xfs_rmap_lookup_le_range (cur, bno,0 , owner, offset, flags);/* * Historically, we always used the range query to walk every reverse
@@ -518,8 +511,7 @@ xfs_rmap_lookup_le_range(return error; *stat =1 ; -trace_xfs_rmap_lookup_le_range_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno, irec->rm_startblock, +trace_xfs_rmap_lookup_le_range_result (cur, irec->rm_startblock, irec->rm_blockcount, irec->rm_owner, irec->rm_offset, irec->rm_flags);return 0 ;
@@ -631,8 +623,7 @@ xfs_rmap_unmap( (flags &XFS_RMAP_BMBT_BLOCK );if (unwritten) flags |=XFS_RMAP_UNWRITTEN ; -trace_xfs_rmap_unmap (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_unmap (cur, bno, len, unwritten, oinfo);/* * We should always have a left record because there's a static record
@@ -648,10 +639,9 @@ xfs_rmap_unmap( goto out_error; } -trace_xfs_rmap_lookup_le_range_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno, ltrec.rm_startblock, - ltrec.rm_blockcount, ltrec.rm_owner, - ltrec.rm_offset, ltrec.rm_flags); +trace_xfs_rmap_lookup_le_range_result (cur, ltrec.rm_startblock, + ltrec.rm_blockcount, ltrec.rm_owner, ltrec.rm_offset, + ltrec.rm_flags); ltoff = ltrec.rm_offset;/*
@@ -718,10 +708,9 @@ xfs_rmap_unmap(if (ltrec.rm_startblock == bno && ltrec.rm_blockcount == len) {/* exact match, simply remove the record from rmap tree */ -trace_xfs_rmap_delete (mp, cur->bc_ag.pag->pag_agno, - ltrec.rm_startblock, ltrec.rm_blockcount, - ltrec.rm_owner, ltrec.rm_offset, - ltrec.rm_flags); +trace_xfs_rmap_delete (cur, ltrec.rm_startblock, + ltrec.rm_blockcount, ltrec.rm_owner, + ltrec.rm_offset, ltrec.rm_flags); error =xfs_btree_delete (cur, &i);if (error) goto out_error;
@@ -797,8 +786,7 @@ xfs_rmap_unmap(else cur->bc_rec.r.rm_offset = offset + len; cur->bc_rec.r.rm_flags = flags; - trace_xfs_rmap_insert(mp, cur->bc_ag.pag->pag_agno, - cur->bc_rec.r.rm_startblock, + trace_xfs_rmap_insert(cur, cur->bc_rec.r.rm_startblock, cur->bc_rec.r.rm_blockcount, cur->bc_rec.r.rm_owner, cur->bc_rec.r.rm_offset,
@@ -809,8 +797,7 @@ xfs_rmap_unmap( } out_done: -trace_xfs_rmap_unmap_done (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_unmap_done (cur, bno, len, unwritten, oinfo); out_error:if (error)trace_xfs_rmap_unmap_error (cur, error, _RET_IP_);
@@ -983,8 +970,7 @@ xfs_rmap_map( (flags &XFS_RMAP_BMBT_BLOCK );if (unwritten) flags |=XFS_RMAP_UNWRITTEN ; -trace_xfs_rmap_map (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_map (cur, bno, len, unwritten, oinfo);ASSERT (!xfs_rmap_should_skip_owner_update (oinfo));/*
@@ -997,8 +983,7 @@ xfs_rmap_map(if (error) goto out_error;if (have_lt) { -trace_xfs_rmap_lookup_le_range_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno, ltrec.rm_startblock, +trace_xfs_rmap_lookup_le_range_result (cur, ltrec.rm_startblock, ltrec.rm_blockcount, ltrec.rm_owner, ltrec.rm_offset, ltrec.rm_flags);
@@ -1036,10 +1021,10 @@ xfs_rmap_map( error = -EFSCORRUPTED ; goto out_error; } -trace_xfs_rmap_find_right_neighbor_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno, gtrec.rm_startblock, - gtrec.rm_blockcount, gtrec.rm_owner, - gtrec.rm_offset, gtrec.rm_flags); +trace_xfs_rmap_find_right_neighbor_result (cur, + gtrec.rm_startblock, gtrec.rm_blockcount, + gtrec.rm_owner, gtrec.rm_offset, + gtrec.rm_flags);if (!xfs_rmap_is_mergeable (>rec, owner, flags)) have_gt =0 ; }
@@ -1076,12 +1061,9 @@ xfs_rmap_map(* result: |rrrrrrrrrrrrrrrrrrrrrrrrrrrrr| */ ltrec.rm_blockcount += gtrec.rm_blockcount; -trace_xfs_rmap_delete (mp, cur->bc_ag.pag->pag_agno, - gtrec.rm_startblock, - gtrec.rm_blockcount, - gtrec.rm_owner, - gtrec.rm_offset, - gtrec.rm_flags); +trace_xfs_rmap_delete (cur, gtrec.rm_startblock, + gtrec.rm_blockcount, gtrec.rm_owner, + gtrec.rm_offset, gtrec.rm_flags); error =xfs_btree_delete (cur, &i);if (error) goto out_error;
@@ -1128,8 +1110,7 @@ xfs_rmap_map( cur->bc_rec.r.rm_owner = owner; cur->bc_rec.r.rm_offset = offset; cur->bc_rec.r.rm_flags = flags; -trace_xfs_rmap_insert (mp, cur->bc_ag.pag->pag_agno, bno, len, - owner, offset, flags); +trace_xfs_rmap_insert (cur, bno, len, owner, offset, flags); error =xfs_btree_insert (cur, &i);if (error) goto out_error;
@@ -1140,8 +1121,7 @@ xfs_rmap_map( } } -trace_xfs_rmap_map_done (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_map_done (cur, bno, len, unwritten, oinfo); out_error:if (error)trace_xfs_rmap_map_error (cur, error, _RET_IP_);
@@ -1218,8 +1198,7 @@ xfs_rmap_convert( (flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK)))); oldext = unwritten ?XFS_RMAP_UNWRITTEN :0 ; new_endoff = offset + len; -trace_xfs_rmap_convert (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_convert (cur, bno, len, unwritten, oinfo);/* * For the initial lookup, look for an exact match or the left-adjacent
@@ -1235,10 +1214,9 @@ xfs_rmap_convert( goto done; } -trace_xfs_rmap_lookup_le_range_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno,PREV .rm_startblock, -PREV .rm_blockcount,PREV .rm_owner, -PREV .rm_offset,PREV .rm_flags); +trace_xfs_rmap_lookup_le_range_result (cur,PREV .rm_startblock, +PREV .rm_blockcount,PREV .rm_owner,PREV .rm_offset, +PREV .rm_flags);ASSERT (PREV .rm_offset <= offset);ASSERT (PREV .rm_offset +PREV .rm_blockcount >= new_endoff);
@@ -1279,10 +1257,9 @@ xfs_rmap_convert( error = -EFSCORRUPTED ; goto done; } -trace_xfs_rmap_find_left_neighbor_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno,LEFT .rm_startblock, -LEFT .rm_blockcount,LEFT .rm_owner, -LEFT .rm_offset,LEFT .rm_flags); +trace_xfs_rmap_find_left_neighbor_result (cur, +LEFT .rm_startblock,LEFT .rm_blockcount, +LEFT .rm_owner,LEFT .rm_offset,LEFT .rm_flags);if (LEFT .rm_startblock +LEFT .rm_blockcount == bno &&LEFT .rm_offset +LEFT .rm_blockcount == offset &&xfs_rmap_is_mergeable (&LEFT , owner, newext))
@@ -1320,10 +1297,10 @@ xfs_rmap_convert( error = -EFSCORRUPTED ; goto done; } -trace_xfs_rmap_find_right_neighbor_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno,RIGHT .rm_startblock, -RIGHT .rm_blockcount,RIGHT .rm_owner, -RIGHT .rm_offset,RIGHT .rm_flags); +trace_xfs_rmap_find_right_neighbor_result (cur, +RIGHT .rm_startblock,RIGHT .rm_blockcount, +RIGHT .rm_owner,RIGHT .rm_offset, +RIGHT .rm_flags);if (bno + len ==RIGHT .rm_startblock && offset + len ==RIGHT .rm_offset &&xfs_rmap_is_mergeable (&RIGHT , owner, newext))
@@ -1370,10 +1347,9 @@ xfs_rmap_convert( error = -EFSCORRUPTED ; goto done; } -trace_xfs_rmap_delete (mp, cur->bc_ag.pag->pag_agno, -RIGHT .rm_startblock,RIGHT .rm_blockcount, -RIGHT .rm_owner,RIGHT .rm_offset, -RIGHT .rm_flags); +trace_xfs_rmap_delete (cur,RIGHT .rm_startblock, +RIGHT .rm_blockcount,RIGHT .rm_owner, +RIGHT .rm_offset,RIGHT .rm_flags); error =xfs_btree_delete (cur, &i);if (error) goto done;
@@ -1390,10 +1366,9 @@ xfs_rmap_convert( error = -EFSCORRUPTED ; goto done; } -trace_xfs_rmap_delete (mp, cur->bc_ag.pag->pag_agno, -PREV .rm_startblock,PREV .rm_blockcount, -PREV .rm_owner,PREV .rm_offset, -PREV .rm_flags); +trace_xfs_rmap_delete (cur,PREV .rm_startblock, +PREV .rm_blockcount,PREV .rm_owner, +PREV .rm_offset,PREV .rm_flags); error =xfs_btree_delete (cur, &i);if (error) goto done;
@@ -1422,10 +1397,9 @@ xfs_rmap_convert(* Setting all of a previous oldext extent to newext. * The left neighbor is contiguous, the right is not. */ -trace_xfs_rmap_delete (mp, cur->bc_ag.pag->pag_agno, -PREV .rm_startblock,PREV .rm_blockcount, -PREV .rm_owner,PREV .rm_offset, -PREV .rm_flags); +trace_xfs_rmap_delete (cur,PREV .rm_startblock, +PREV .rm_blockcount,PREV .rm_owner, +PREV .rm_offset,PREV .rm_flags); error =xfs_btree_delete (cur, &i);if (error) goto done;
@@ -1462,10 +1436,9 @@ xfs_rmap_convert( error = -EFSCORRUPTED ; goto done; } -trace_xfs_rmap_delete (mp, cur->bc_ag.pag->pag_agno, -RIGHT .rm_startblock,RIGHT .rm_blockcount, -RIGHT .rm_owner,RIGHT .rm_offset, -RIGHT .rm_flags); +trace_xfs_rmap_delete (cur,RIGHT .rm_startblock, +RIGHT .rm_blockcount,RIGHT .rm_owner, +RIGHT .rm_offset,RIGHT .rm_flags); error =xfs_btree_delete (cur, &i);if (error) goto done;
@@ -1543,8 +1516,7 @@ xfs_rmap_convert(NEW .rm_blockcount = len;NEW .rm_flags = newext; cur->bc_rec.r =NEW ; -trace_xfs_rmap_insert (mp, cur->bc_ag.pag->pag_agno, bno, - len, owner, offset, newext); +trace_xfs_rmap_insert (cur, bno, len, owner, offset, newext); error =xfs_btree_insert (cur, &i);if (error) goto done;
@@ -1602,8 +1574,7 @@ xfs_rmap_convert(NEW .rm_blockcount = len;NEW .rm_flags = newext; cur->bc_rec.r =NEW ; -trace_xfs_rmap_insert (mp, cur->bc_ag.pag->pag_agno, bno, - len, owner, offset, newext); +trace_xfs_rmap_insert (cur, bno, len, owner, offset, newext); error =xfs_btree_insert (cur, &i);if (error) goto done;
@@ -1634,9 +1605,8 @@ xfs_rmap_convert(NEW =PREV ;NEW .rm_blockcount = offset -PREV .rm_offset; cur->bc_rec.r =NEW ; -trace_xfs_rmap_insert (mp, cur->bc_ag.pag->pag_agno, -NEW .rm_startblock,NEW .rm_blockcount, -NEW .rm_owner,NEW .rm_offset, +trace_xfs_rmap_insert (cur,NEW .rm_startblock, +NEW .rm_blockcount,NEW .rm_owner,NEW .rm_offset,NEW .rm_flags); error =xfs_btree_insert (cur, &i);if (error)
@@ -1663,8 +1633,7 @@ xfs_rmap_convert(/* new middle extent - newext */ cur->bc_rec.r.rm_flags &= ~XFS_RMAP_UNWRITTEN ; cur->bc_rec.r.rm_flags |= newext; -trace_xfs_rmap_insert (mp, cur->bc_ag.pag->pag_agno, bno, len, - owner, offset, newext); +trace_xfs_rmap_insert (cur, bno, len, owner, offset, newext); error =xfs_btree_insert (cur, &i);if (error) goto done;
@@ -1688,8 +1657,7 @@ xfs_rmap_convert(ASSERT (0 ); } -trace_xfs_rmap_convert_done (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_convert_done (cur, bno, len, unwritten, oinfo); done:if (error)trace_xfs_rmap_convert_error (cur, error, _RET_IP_);
@@ -1728,8 +1696,7 @@ xfs_rmap_convert_shared( (flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK)))); oldext = unwritten ?XFS_RMAP_UNWRITTEN :0 ; new_endoff = offset + len; -trace_xfs_rmap_convert (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_convert (cur, bno, len, unwritten, oinfo);/* * For the initial lookup, look for and exact match or the left-adjacent
@@ -1798,10 +1765,10 @@ xfs_rmap_convert_shared( error = -EFSCORRUPTED ; goto done; } -trace_xfs_rmap_find_right_neighbor_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno,RIGHT .rm_startblock, -RIGHT .rm_blockcount,RIGHT .rm_owner, -RIGHT .rm_offset,RIGHT .rm_flags); +trace_xfs_rmap_find_right_neighbor_result (cur, +RIGHT .rm_startblock,RIGHT .rm_blockcount, +RIGHT .rm_owner,RIGHT .rm_offset, +RIGHT .rm_flags);if (xfs_rmap_is_mergeable (&RIGHT , owner, newext)) state |=RMAP_RIGHT_CONTIG ; }
@@ -2113,8 +2080,7 @@ xfs_rmap_convert_shared(ASSERT (0 ); } -trace_xfs_rmap_convert_done (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_convert_done (cur, bno, len, unwritten, oinfo); done:if (error)trace_xfs_rmap_convert_error (cur, error, _RET_IP_);
@@ -2155,8 +2121,7 @@ xfs_rmap_unmap_shared(xfs_owner_info_unpack (oinfo, &owner, &offset, &flags);if (unwritten) flags |=XFS_RMAP_UNWRITTEN ; -trace_xfs_rmap_unmap (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_unmap (cur, bno, len, unwritten, oinfo);/* * We should always have a left record because there's a static record
@@ -2312,8 +2277,7 @@ xfs_rmap_unmap_shared( goto out_error; } -trace_xfs_rmap_unmap_done (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_unmap_done (cur, bno, len, unwritten, oinfo); out_error:if (error)trace_xfs_rmap_unmap_error (cur, error, _RET_IP_);
@@ -2351,8 +2315,7 @@ xfs_rmap_map_shared(xfs_owner_info_unpack (oinfo, &owner, &offset, &flags);if (unwritten) flags |=XFS_RMAP_UNWRITTEN ; -trace_xfs_rmap_map (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_map (cur, bno, len, unwritten, oinfo);/* Is there a left record that abuts our range? */ error = xfs_rmap_find_left_neighbor(cur, bno, owner, offset, flags,
@@ -2377,10 +2340,10 @@ xfs_rmap_map_shared( error = -EFSCORRUPTED ; goto out_error; } -trace_xfs_rmap_find_right_neighbor_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno, gtrec.rm_startblock, - gtrec.rm_blockcount, gtrec.rm_owner, - gtrec.rm_offset, gtrec.rm_flags); +trace_xfs_rmap_find_right_neighbor_result (cur, + gtrec.rm_startblock, gtrec.rm_blockcount, + gtrec.rm_owner, gtrec.rm_offset, + gtrec.rm_flags);if (!xfs_rmap_is_mergeable (>rec, owner, flags)) have_gt =0 ;
@@ -2472,8 +2435,7 @@ xfs_rmap_map_shared( goto out_error; } -trace_xfs_rmap_map_done (mp, cur->bc_ag.pag->pag_agno, bno, len, - unwritten, oinfo); +trace_xfs_rmap_map_done (cur, bno, len, unwritten, oinfo); out_error:if (error)trace_xfs_rmap_map_error (cur, error, _RET_IP_);
fs/xfs/xfs_trace.h +12 -12
@@ -2757,10 +2757,10 @@ DEFINE_DEFER_PENDING_ITEM_EVENT(xfs_defer_finish_item);/* rmap tracepoints */ DECLARE_EVENT_CLASS(xfs_rmap_class, - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, + TP_PROTO(struct xfs_btree_cur *cur, xfs_agblock_t agbno, xfs_extlen_t len, bool unwritten, const struct xfs_owner_info *oinfo), - TP_ARGS(mp, agno, agbno, len, unwritten, oinfo), + TP_ARGS(cur, agbno, len, unwritten, oinfo), TP_STRUCT__entry( __field(dev_t, dev) __field(xfs_agnumber_t, agno)
@@ -2771,8 +2771,8 @@ DECLARE_EVENT_CLASS(xfs_rmap_class, __field(unsigned long, flags) ),TP_fast_assign ( - __entry->dev = mp->m_super->s_dev; - __entry->agno = agno; + __entry->dev = cur->bc_mp->m_super->s_dev; + __entry->agno = cur->bc_ag.pag->pag_agno; __entry->agbno = agbno; __entry->len = len; __entry->owner = oinfo->oi_owner;
@@ -2792,10 +2792,10 @@ DECLARE_EVENT_CLASS(xfs_rmap_class, );#define DEFINE_RMAP_EVENT (name) \ DEFINE_EVENT(xfs_rmap_class, name, \ - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \ + TP_PROTO(struct xfs_btree_cur *cur, \ xfs_agblock_t agbno, xfs_extlen_t len, bool unwritten, \ const struct xfs_owner_info *oinfo), \ - TP_ARGS(mp, agno, agbno, len, unwritten, oinfo)) + TP_ARGS(cur, agbno, len, unwritten, oinfo))/* btree cursor error/%ip tracepoint class */ DECLARE_EVENT_CLASS(xfs_btree_error_class,
@@ -2891,10 +2891,10 @@ TRACE_EVENT(xfs_rmap_convert_state, ); DECLARE_EVENT_CLASS(xfs_rmapbt_class, - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, + TP_PROTO(struct xfs_btree_cur *cur, xfs_agblock_t agbno, xfs_extlen_t len, uint64_t owner, uint64_t offset, unsigned int flags), - TP_ARGS(mp, agno, agbno, len, owner, offset, flags), + TP_ARGS(cur, agbno, len, owner, offset, flags), TP_STRUCT__entry( __field(dev_t, dev) __field(xfs_agnumber_t, agno)
@@ -2905,8 +2905,8 @@ DECLARE_EVENT_CLASS(xfs_rmapbt_class, __field(unsigned int, flags) ),TP_fast_assign ( - __entry->dev = mp->m_super->s_dev; - __entry->agno = agno; + __entry->dev = cur->bc_mp->m_super->s_dev; + __entry->agno = cur->bc_ag.pag->pag_agno; __entry->agbno = agbno; __entry->len = len; __entry->owner = owner;
@@ -2924,10 +2924,10 @@ DECLARE_EVENT_CLASS(xfs_rmapbt_class, );#define DEFINE_RMAPBT_EVENT (name) \ DEFINE_EVENT(xfs_rmapbt_class, name, \ - TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \ + TP_PROTO(struct xfs_btree_cur *cur, \ xfs_agblock_t agbno, xfs_extlen_t len, \ uint64_t owner, uint64_t offset, unsigned int flags), \ - TP_ARGS(mp, agno, agbno, len, owner, offset, flags)) + TP_ARGS(cur, agbno, len, owner, offset, flags)) DECLARE_EVENT_CLASS(xfs_rmap_deferred_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno,
Re: [PATCH 2/9] xfs: prepare rmap btree tracepoints for widening
If find the widening term a bit odd here and would have said:
"xfs: pass btree cursors to rmap btree tracepoints"
But except for that this looks good to me:
Re: [PATCH 2/9] xfs: prepare rmap btree tracepoints for widening
Quoted 5 lines · Christoph Hellwig
If find the widening term a bit odd here and would have said:
"xfs: pass btree cursors to rmap btree tracepoints"
But except for that this looks good to me:
Done. I think the subject line is left over from the really old days when there was one rmap btree for the entire rt device and we actually had to handle 64-bit values.
Quoted 1 line
Reviewed-by Christoph Hellwig <[email protected]>
Thanks!
--D
PATCH 3/9 xfs: clean up rmap log intent item tracepoint callsites
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Pass the incore rmap structure to the tracepoints instead of open-coding the argument passing.
--- fs/xfs/libxfs/xfs_rmap.c | 22 ++++-------------- fs/xfs/libxfs/xfs_rmap.h | 10 ++++++++ fs/xfs/xfs_trace.c | 1 + fs/xfs/xfs_trace.h | 57 ++++++++++++++++++++++------------------------ 4 files changed, 43 insertions(+), 47 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +5 -17
@@ -2585,20 +2585,15 @@ xfs_rmap_finish_one(struct xfs_rmap_intent *ri, struct xfs_btree_cur **pcur) { + struct xfs_owner_info oinfo;struct xfs_mount *mp = tp->t_mountp;struct xfs_btree_cur *rcur;struct xfs_buf *agbp =NULL ; -int error =0 ; -struct xfs_owner_info oinfo;xfs_agblock_t bno;bool unwritten; +int error =0 ; - bno =XFS_FSB_TO_AGBNO (mp, ri->ri_bmap.br_startblock); - -trace_xfs_rmap_deferred (mp, ri->ri_pag->pag_agno, ri->ri_type, bno, - ri->ri_owner, ri->ri_whichfork, - ri->ri_bmap.br_startoff, ri->ri_bmap.br_blockcount, - ri->ri_bmap.br_state); +trace_xfs_rmap_deferred (mp, ri);if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_RMAP_FINISH_ONE ))return -EIO ;
@@ -2673,15 +2668,6 @@ __xfs_rmap_add( {struct xfs_rmap_intent *ri; -trace_xfs_rmap_defer (tp->t_mountp, -XFS_FSB_TO_AGNO (tp->t_mountp, bmap->br_startblock), - type, -XFS_FSB_TO_AGBNO (tp->t_mountp, bmap->br_startblock), - owner, whichfork, - bmap->br_startoff, - bmap->br_blockcount, - bmap->br_state); - ri =kmem_cache_alloc (xfs_rmap_intent_cache,GFP_KERNEL | __GFP_NOFAIL);INIT_LIST_HEAD (&ri->ri_list); ri->ri_type = type;
@@ -2689,6 +2675,8 @@ __xfs_rmap_add( ri->ri_whichfork = whichfork; ri->ri_bmap = *bmap; +trace_xfs_rmap_defer (tp->t_mountp, ri); +xfs_rmap_update_get_group (tp->t_mountp, ri);xfs_defer_add (tp, &ri->ri_list, &xfs_rmap_update_defer_type); }
fs/xfs/libxfs/xfs_rmap.h +10 -0
@@ -157,6 +157,16 @@ enum xfs_rmap_intent_type { XFS_RMAP_FREE, }; +#define XFS_RMAP_INTENT_STRINGS \ + { XFS_RMAP_MAP, "map" }, \ + { XFS_RMAP_MAP_SHARED, "map_shared" }, \ + { XFS_RMAP_UNMAP, "unmap" }, \ + { XFS_RMAP_UNMAP_SHARED, "unmap_shared" }, \ + { XFS_RMAP_CONVERT, "cvt" }, \ + { XFS_RMAP_CONVERT_SHARED, "cvt_shared" }, \ + { XFS_RMAP_ALLOC, "alloc" }, \ + { XFS_RMAP_FREE, "free" } +struct xfs_rmap_intent {struct list_head ri_list;enum xfs_rmap_intent_type ri_type;
fs/xfs/xfs_trace.c +1 -0
@@ -42,6 +42,7 @@#include "xfs_exchmaps.h" #include "xfs_exchrange.h" #include "xfs_parent.h" +#include "xfs_rmap.h" /* * We include this last to have the helpers above available for the trace
fs/xfs/xfs_trace.h +27 -30
89 lines not on this page · raw message
Re: [PATCH 3/9] xfs: clean up rmap log intent item tracepoint callsites
Looks good:
PATCH 4/9 xfs: remove xfs_trans_set_rmap_flags
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Remove this single-use helper.
--- fs/xfs/xfs_rmap_item.c | 79 +++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 45 deletions(-)
fs/xfs/xfs_rmap_item.c +34 -45
@@ -226,49 +226,6 @@ static const struct xfs_item_ops xfs_rud_item_ops = { .iop_intent = xfs_rud_item_intent, }; -/* Set the map extent flags for this reverse mapping. */ -static void -xfs_trans_set_rmap_flags ( -struct xfs_map_extent *map, -enum xfs_rmap_intent_type type, -int whichfork, -xfs_exntst_t state) -{ - map->me_flags =0 ; -if (state ==XFS_EXT_UNWRITTEN ) - map->me_flags |=XFS_RMAP_EXTENT_UNWRITTEN ; -if (whichfork ==XFS_ATTR_FORK ) - map->me_flags |=XFS_RMAP_EXTENT_ATTR_FORK ; -switch (type) { -case XFS_RMAP_MAP : - map->me_flags |=XFS_RMAP_EXTENT_MAP ; -break ; -case XFS_RMAP_MAP_SHARED : - map->me_flags |=XFS_RMAP_EXTENT_MAP_SHARED ; -break ; -case XFS_RMAP_UNMAP : - map->me_flags |=XFS_RMAP_EXTENT_UNMAP ; -break ; -case XFS_RMAP_UNMAP_SHARED : - map->me_flags |=XFS_RMAP_EXTENT_UNMAP_SHARED ; -break ; -case XFS_RMAP_CONVERT : - map->me_flags |=XFS_RMAP_EXTENT_CONVERT ; -break ; -case XFS_RMAP_CONVERT_SHARED : - map->me_flags |=XFS_RMAP_EXTENT_CONVERT_SHARED ; -break ; -case XFS_RMAP_ALLOC : - map->me_flags |=XFS_RMAP_EXTENT_ALLOC ; -break ; -case XFS_RMAP_FREE : - map->me_flags |=XFS_RMAP_EXTENT_FREE ; -break ; -default : -ASSERT (0 ); - } -} -/* Sort rmap intents by AG. */ static int xfs_rmap_update_diff_items(
@@ -307,8 +264,40 @@ xfs_rmap_update_log_item( map->me_startblock = ri->ri_bmap.br_startblock; map->me_startoff = ri->ri_bmap.br_startoff; map->me_len = ri->ri_bmap.br_blockcount; -xfs_trans_set_rmap_flags (map, ri->ri_type, ri->ri_whichfork, - ri->ri_bmap.br_state); + + map->me_flags =0 ; +if (ri->ri_bmap.br_state ==XFS_EXT_UNWRITTEN ) + map->me_flags |=XFS_RMAP_EXTENT_UNWRITTEN ; +if (ri->ri_whichfork ==XFS_ATTR_FORK ) + map->me_flags |=XFS_RMAP_EXTENT_ATTR_FORK ; +switch (ri->ri_type) { +case XFS_RMAP_MAP : + map->me_flags |=XFS_RMAP_EXTENT_MAP ; +break ; +case XFS_RMAP_MAP_SHARED : + map->me_flags |=XFS_RMAP_EXTENT_MAP_SHARED ; +break ; +case XFS_RMAP_UNMAP : + map->me_flags |=XFS_RMAP_EXTENT_UNMAP ; +break ; +case XFS_RMAP_UNMAP_SHARED : + map->me_flags |=XFS_RMAP_EXTENT_UNMAP_SHARED ; +break ; +case XFS_RMAP_CONVERT : + map->me_flags |=XFS_RMAP_EXTENT_CONVERT ; +break ; +case XFS_RMAP_CONVERT_SHARED : + map->me_flags |=XFS_RMAP_EXTENT_CONVERT_SHARED ; +break ; +case XFS_RMAP_ALLOC : + map->me_flags |=XFS_RMAP_EXTENT_ALLOC ; +break ; +case XFS_RMAP_FREE : + map->me_flags |=XFS_RMAP_EXTENT_FREE ; +break ; +default : +ASSERT (0 ); + } } static struct xfs_log_item *
Re: [PATCH 4/9] xfs: remove xfs_trans_set_rmap_flags
Looks good:
PATCH 5/9 xfs: add a ri_entry helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Add a helper to translate from the item list head to the rmap_intent_item structure and use it so shorten assignments and avoid the need for extra local variables.
--- fs/xfs/xfs_rmap_item.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
fs/xfs/xfs_rmap_item.c +9 -11
@@ -226,6 +226,11 @@ static const struct xfs_item_ops xfs_rud_item_ops = { .iop_intent = xfs_rud_item_intent, }; +static inline struct xfs_rmap_intent *ri_entry (const struct list_head *e) +{ + return list_entry(e, struct xfs_rmap_intent, ri_list); +} +/* Sort rmap intents by AG. */ static int xfs_rmap_update_diff_items(
@@ -233,11 +238,8 @@ xfs_rmap_update_diff_items(const struct list_head *a, const struct list_head *b) { - struct xfs_rmap_intent *ra; -struct xfs_rmap_intent *rb; - - ra = container_of(a, struct xfs_rmap_intent, ri_list); - rb = container_of(b, struct xfs_rmap_intent, ri_list); + struct xfs_rmap_intent *ra = ri_entry(a); +struct xfs_rmap_intent *rb =ri_entry (b);return ra->ri_pag->pag_agno - rb->ri_pag->pag_agno; }
@@ -364,11 +366,9 @@ xfs_rmap_update_finish_item(struct list_head *item, struct xfs_btree_cur **state) { - struct xfs_rmap_intent *ri; + struct xfs_rmap_intent *ri = ri_entry(item);int error; - ri = container_of(item, struct xfs_rmap_intent, ri_list); - error =xfs_rmap_finish_one (tp, ri, state);xfs_rmap_update_put_group (ri);
@@ -389,9 +389,7 @@ STATIC voidxfs_rmap_update_cancel_item ( struct list_head *item) { -struct xfs_rmap_intent *ri; - - ri = container_of(item, struct xfs_rmap_intent, ri_list); +struct xfs_rmap_intent *ri =ri_entry (item);xfs_rmap_update_put_group (ri);kmem_cache_free (xfs_rmap_intent_cache, ri);
PATCH 6/9 xfs: reuse xfs_rmap_update_cancel_item
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Reuse xfs_rmap_update_cancel_item to put the AG/RTG and free the item in a few places that currently open code the logic.
--- fs/xfs/xfs_rmap_item.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
fs/xfs/xfs_rmap_item.c +12 -13
@@ -358,6 +358,17 @@ xfs_rmap_update_put_group(xfs_perag_intent_put (ri->ri_pag); } +/* Cancel a deferred rmap update. */ +STATIC void +xfs_rmap_update_cancel_item ( +struct list_head *item) +{ +struct xfs_rmap_intent *ri =ri_entry (item); + +xfs_rmap_update_put_group (ri); +kmem_cache_free (xfs_rmap_intent_cache, ri); +} +/* Process a deferred rmap update. */ STATIC int xfs_rmap_update_finish_item(
@@ -371,8 +382,7 @@ xfs_rmap_update_finish_item( error =xfs_rmap_finish_one (tp, ri, state); -xfs_rmap_update_put_group (ri); -kmem_cache_free (xfs_rmap_intent_cache, ri); +xfs_rmap_update_cancel_item (item);return error; }
@@ -384,17 +394,6 @@ xfs_rmap_update_abort_intent(xfs_rui_release (RUI_ITEM (intent)); } -/* Cancel a deferred rmap update. */ -STATIC void -xfs_rmap_update_cancel_item ( -struct list_head *item) -{ -struct xfs_rmap_intent *ri =ri_entry (item); - -xfs_rmap_update_put_group (ri); -kmem_cache_free (xfs_rmap_intent_cache, ri); -} -/* Is this recovered RUI ok? */ static inline bool xfs_rui_validate_map(
PATCH 7/9 xfs: don't bother calling xfs_rmap_finish_one_cleanup in xfs_rmap_finish_one
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
In xfs_rmap_finish_one we known the cursor is non-zero when calling xfs_rmap_finish_one_cleanup and we pass a 0 error variable. This means xfs_rmap_finish_one_cleanup is just doing a xfs_btree_del_cursor.
Open code that and move xfs_rmap_finish_one_cleanup to fs/xfs/xfs_rmap_item.c.
--- fs/xfs/libxfs/xfs_rmap.c | 19 +------------------ fs/xfs/libxfs/xfs_rmap.h | 2 -- fs/xfs/xfs_rmap_item.c | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +1 -18
@@ -2523,23 +2523,6 @@ xfs_rmap_query_all(return xfs_btree_query_all (cur, xfs_rmap_query_range_helper, &query); } -/* Clean up after calling xfs_rmap_finish_one. */ -void -xfs_rmap_finish_one_cleanup ( -struct xfs_trans *tp, -struct xfs_btree_cur *rcur, -int error) -{ -struct xfs_buf *agbp; - -if (rcur ==NULL ) -return ; - agbp = rcur->bc_ag.agbp; -xfs_btree_del_cursor (rcur, error); -if (error) -xfs_trans_brelse (tp, agbp); -} -/* Commit an rmap operation into the ondisk tree. */ int __xfs_rmap_finish_intent(
@@ -2604,7 +2587,7 @@ xfs_rmap_finish_one(*/ rcur = *pcur;if (rcur !=NULL && rcur->bc_ag.pag != ri->ri_pag) { -xfs_rmap_finish_one_cleanup (tp, rcur,0 ); +xfs_btree_del_cursor (rcur,0 ); rcur =NULL ; *pcur =NULL ; }
fs/xfs/libxfs/xfs_rmap.h +0 -2
@@ -192,8 +192,6 @@ void xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno,void xfs_rmap_free_extent (struct xfs_trans *tp,xfs_agnumber_t agno,xfs_agblock_t bno,xfs_extlen_t len,uint64_t owner); -void xfs_rmap_finish_one_cleanup (struct xfs_trans *tp, -struct xfs_btree_cur *rcur,int error);int xfs_rmap_finish_one (struct xfs_trans *tp,struct xfs_rmap_intent *ri,struct xfs_btree_cur **pcur); int __xfs_rmap_finish_intent(struct xfs_btree_cur *rcur,
fs/xfs/xfs_rmap_item.c +18 -0
@@ -21,6 +21,7 @@#include "xfs_log_priv.h" #include "xfs_log_recover.h" #include "xfs_ag.h" +#include "xfs_btree.h" struct kmem_cache *xfs_rui_cache;struct kmem_cache *xfs_rud_cache;
@@ -386,6 +387,23 @@ xfs_rmap_update_finish_item(return error; } +/* Clean up after calling xfs_rmap_finish_one. */ +STATIC void +xfs_rmap_finish_one_cleanup ( +struct xfs_trans *tp, +struct xfs_btree_cur *rcur, +int error) +{ +struct xfs_buf *agbp =NULL ; + +if (rcur ==NULL ) +return ; + agbp = rcur->bc_ag.agbp; +xfs_btree_del_cursor (rcur, error); +if (error && agbp) +xfs_trans_brelse (tp, agbp); +} +/* Abort all pending RUIs. */ STATIC void xfs_rmap_update_abort_intent(
PATCH 8/9 xfs: simplify usage of the rcur local variable in xfs_rmap_finish_one
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Only update rcur when we know the final *pcur value.
--- fs/xfs/libxfs/xfs_rmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +2 -4
@@ -2570,7 +2570,7 @@ xfs_rmap_finish_one( {struct xfs_owner_info oinfo;struct xfs_mount *mp = tp->t_mountp; -struct xfs_btree_cur *rcur; +struct xfs_btree_cur *rcur = *pcur;struct xfs_buf *agbp =NULL ;xfs_agblock_t bno;bool unwritten;
@@ -2585,7 +2585,6 @@ xfs_rmap_finish_one(* If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ - rcur = *pcur;if (rcur !=NULL && rcur->bc_ag.pag != ri->ri_pag) {xfs_btree_del_cursor (rcur,0 ); rcur =NULL ;
@@ -2607,9 +2606,8 @@ xfs_rmap_finish_one(return -EFSCORRUPTED ; } - rcur =xfs_rmapbt_init_cursor (mp, tp, agbp, ri->ri_pag); + *pcur = rcur =xfs_rmapbt_init_cursor (mp, tp, agbp, ri->ri_pag); } - *pcur = rcur;xfs_rmap_ino_owner (&oinfo, ri->ri_owner, ri->ri_whichfork, ri->ri_bmap.br_startoff);
PATCH 9/9 xfs: move xfs_rmap_update_defer_add to xfs_rmap_item.c
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the code that adds the incore xfs_rmap_update_item deferred work data to a transaction live with the RUI log item code. This means that the rmap code no longer has to know about the inner workings of the RUI log items.
As a consequence, we can get rid of the _{get,put}_group helpers.
--- fs/xfs/libxfs/xfs_rmap.c | 6 ++---- fs/xfs/libxfs/xfs_rmap.h | 3 --- fs/xfs/xfs_rmap_item.c | 24 +++++++++++------------- fs/xfs/xfs_rmap_item.h | 4 ++++ 4 files changed, 17 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_rmap.c +2 -4
@@ -24,6 +24,7 @@#include "xfs_inode.h" #include "xfs_ag.h" #include "xfs_health.h" +#include "xfs_rmap_item.h" struct kmem_cache *xfs_rmap_intent_cache;
@@ -2656,10 +2657,7 @@ __xfs_rmap_add( ri->ri_whichfork = whichfork; ri->ri_bmap = *bmap; -trace_xfs_rmap_defer (tp->t_mountp, ri); - -xfs_rmap_update_get_group (tp->t_mountp, ri); -xfs_defer_add (tp, &ri->ri_list, &xfs_rmap_update_defer_type); +xfs_rmap_defer_add (tp, ri); }/* Map an extent into a file. */
fs/xfs/libxfs/xfs_rmap.h +0 -3
@@ -176,9 +176,6 @@ struct xfs_rmap_intent {struct xfs_perag *ri_pag; }; -void xfs_rmap_update_get_group (struct xfs_mount *mp, -struct xfs_rmap_intent *ri); -/* functions for updating the rmapbt based on bmbt map/unmap operations */ void xfs_rmap_map_extent (struct xfs_trans *tp,struct xfs_inode *ip,int whichfork,struct xfs_bmbt_irec *imap);
fs/xfs/xfs_rmap_item.c +11 -13
@@ -22,6 +22,7 @@#include "xfs_log_recover.h" #include "xfs_ag.h" #include "xfs_btree.h" +#include "xfs_trace.h" struct kmem_cache *xfs_rui_cache;struct kmem_cache *xfs_rud_cache;
@@ -342,21 +343,18 @@ xfs_rmap_update_create_done(return &rudp->rud_item; } -/* Take a passive ref to the AG containing the space we're rmapping. */ +/* Add this deferred RUI to the transaction. */ void -xfs_rmap_update_get_group ( -struct xfs_mount *mp, +xfs_rmap_defer_add ( +struct xfs_trans *tp,struct xfs_rmap_intent *ri) { +struct xfs_mount *mp = tp->t_mountp; + +trace_xfs_rmap_defer (mp, ri); + ri->ri_pag =xfs_perag_intent_get (mp, ri->ri_bmap.br_startblock); -} - -/* Release a passive AG ref after finishing rmapping work. */ -static inline void -xfs_rmap_update_put_group ( -struct xfs_rmap_intent *ri) -{ -xfs_perag_intent_put (ri->ri_pag); +xfs_defer_add (tp, &ri->ri_list, &xfs_rmap_update_defer_type); }/* Cancel a deferred rmap update. */
@@ -366,7 +364,7 @@ xfs_rmap_update_cancel_item( {struct xfs_rmap_intent *ri =ri_entry (item); -xfs_rmap_update_put_group (ri); +xfs_perag_intent_put (ri->ri_pag);kmem_cache_free (xfs_rmap_intent_cache, ri); }
@@ -496,7 +494,7 @@ xfs_rui_recover_work( ri->ri_bmap.br_blockcount = map->me_len; ri->ri_bmap.br_state = (map->me_flags &XFS_RMAP_EXTENT_UNWRITTEN ) ?XFS_EXT_UNWRITTEN :XFS_EXT_NORM ; -xfs_rmap_update_get_group (mp, ri); + ri->ri_pag =xfs_perag_intent_get (mp, map->me_startblock);xfs_defer_add_item (dfp, &ri->ri_list); }
fs/xfs/xfs_rmap_item.h +4 -0
@@ -71,4 +71,8 @@ struct xfs_rud_log_item {extern struct kmem_cache *xfs_rui_cache;extern struct kmem_cache *xfs_rud_cache; +struct xfs_rmap_intent ; + +void xfs_rmap_defer_add (struct xfs_trans *tp,struct xfs_rmap_intent *ri); +#endif /* __XFS_RMAP_ITEM_H__ */
Re: [PATCH 9/9] xfs: move xfs_rmap_update_defer_add to xfs_rmap_item.c
Quoted 4 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Move the code that adds the incore
xfs_rmap_update_itemdeferred work data to a transaction live with the RUI log item code. This means that
s/live/to live/?
Otherwise:
PATCH 4/5 xfs: refcount log intent cleanups
In reply to Darrick J. WongHi all,
This series cleans up the refcount intent code before we start adding support for realtime devices. Similar to previous intent cleanup patchsets, we start transforming the tracepoints so that the data extraction are done inside the tracepoint code, and then we start passing the intent itself to the _finish_one function. This reduces the boxing and unboxing of parameters.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=refcount-intent-cleanups
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=refcount-intent-cleanups
---
Commits in this patchset:
* xfs: give refcount btree cursor error tracepoints their own class
* xfs: create specialized classes for refcount tracepoints
* xfs: prepare refcount btree tracepoints for widening
* xfs: clean up refcount log intent item tracepoint callsites
* xfs: remove xfs_trans_set_refcount_flags
* xfs: add a ci_entry helper
* xfs: reuse xfs_refcount_update_cancel_item
* xfs: don't bother calling xfs_refcount_finish_one_cleanup in xfs_refcount_finish_one
* xfs: simplify usage of the rcur local variable in xfs_refcount_finish_one
* xfs: move xfs_refcount_update_defer_add to xfs_refcount_item.c
--- fs/xfs/libxfs/xfs_refcount.c | 150 ++++++++-------------------- fs/xfs/libxfs/xfs_refcount.h | 11 +- fs/xfs/xfs_refcount_item.c | 107 ++++++++++---------- fs/xfs/xfs_refcount_item.h | 5 + fs/xfs/xfs_trace.c | 1 fs/xfs/xfs_trace.h | 229 ++++++++++++++++++++---------------------- 6 files changed, 222 insertions(+), 281 deletions(-)
PATCH 1/10 xfs: give refcount btree cursor error tracepoints their own class
From: Darrick J. Wong <[email protected]>
Convert all the refcount tracepoints to use the btree error tracepoint class.
--- fs/xfs/libxfs/xfs_refcount.c | 42 ++++++++++++++---------------------------- fs/xfs/xfs_trace.h | 26 +++++++++++++------------- 2 files changed, 27 insertions(+), 41 deletions(-)
fs/xfs/libxfs/xfs_refcount.c +14 -28
@@ -211,8 +211,7 @@ xfs_refcount_update( error =xfs_btree_update (cur, &rec);if (error) -trace_xfs_refcount_update_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_update_error (cur, error, _RET_IP_);return error; }
@@ -247,8 +246,7 @@ xfs_refcount_insert( out_error:if (error) -trace_xfs_refcount_insert_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_insert_error (cur, error, _RET_IP_);return error; }
@@ -288,8 +286,7 @@ xfs_refcount_delete( &found_rec); out_error:if (error) -trace_xfs_refcount_delete_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_delete_error (cur, error, _RET_IP_);return error; }
@@ -438,8 +435,7 @@ xfs_refcount_split_extent(return error; out_error: -trace_xfs_refcount_split_extent_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_split_extent_error (cur, error, _RET_IP_);return error; }
@@ -522,8 +518,7 @@ xfs_refcount_merge_center_extents(return error; out_error: -trace_xfs_refcount_merge_center_extents_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_merge_center_extents_error (cur, error, _RET_IP_);return error; }
@@ -589,8 +584,7 @@ xfs_refcount_merge_left_extent(return error; out_error: -trace_xfs_refcount_merge_left_extent_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_merge_left_extent_error (cur, error, _RET_IP_);return error; }
@@ -658,8 +652,7 @@ xfs_refcount_merge_right_extent(return error; out_error: -trace_xfs_refcount_merge_right_extent_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_merge_right_extent_error (cur, error, _RET_IP_);return error; }
@@ -753,8 +746,7 @@ xfs_refcount_find_left_extents(return error; out_error: -trace_xfs_refcount_find_left_extent_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_find_left_extent_error (cur, error, _RET_IP_);return error; }
@@ -848,8 +840,7 @@ xfs_refcount_find_right_extents(return error; out_error: -trace_xfs_refcount_find_right_extent_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_find_right_extent_error (cur, error, _RET_IP_);return error; }
@@ -1254,8 +1245,7 @@ xfs_refcount_adjust_extents(return error; out_error: -trace_xfs_refcount_modify_extent_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_modify_extent_error (cur, error, _RET_IP_);return error; }
@@ -1315,8 +1305,7 @@ xfs_refcount_adjust(return 0 ; out_error: -trace_xfs_refcount_adjust_error (cur->bc_mp, cur->bc_ag.pag->pag_agno, - error, _RET_IP_); +trace_xfs_refcount_adjust_error (cur, error, _RET_IP_);return error; }
@@ -1630,8 +1619,7 @@ xfs_refcount_find_shared( out_error:if (error) -trace_xfs_refcount_find_shared_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_find_shared_error (cur, error, _RET_IP_);return error; }
@@ -1786,8 +1774,7 @@ xfs_refcount_adjust_cow_extents(return error; out_error: -trace_xfs_refcount_modify_extent_error (cur->bc_mp, - cur->bc_ag.pag->pag_agno, error, _RET_IP_); +trace_xfs_refcount_modify_extent_error (cur, error, _RET_IP_);return error; }
@@ -1833,8 +1820,7 @@ xfs_refcount_adjust_cow(return 0 ; out_error: -trace_xfs_refcount_adjust_cow_error (cur->bc_mp, cur->bc_ag.pag->pag_agno, - error, _RET_IP_); +trace_xfs_refcount_adjust_cow_error (cur, error, _RET_IP_);return error; }
fs/xfs/xfs_trace.h +13 -13
@@ -3432,9 +3432,9 @@ DEFINE_REFCOUNT_EXTENT_EVENT(xfs_refcount_get);DEFINE_REFCOUNT_EXTENT_EVENT (xfs_refcount_update);DEFINE_REFCOUNT_EXTENT_EVENT (xfs_refcount_insert);DEFINE_REFCOUNT_EXTENT_EVENT (xfs_refcount_delete); -DEFINE_AG_ERROR_EVENT (xfs_refcount_insert_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_delete_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_update_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_insert_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_delete_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_update_error);/* refcount adjustment tracepoints */ DEFINE_AG_EXTENT_EVENT (xfs_refcount_increase);
@@ -3449,20 +3449,20 @@ DEFINE_REFCOUNT_DOUBLE_EXTENT_EVENT(xfs_refcount_merge_left_extent);DEFINE_REFCOUNT_DOUBLE_EXTENT_EVENT (xfs_refcount_merge_right_extent);DEFINE_REFCOUNT_DOUBLE_EXTENT_AT_EVENT (xfs_refcount_find_left_extent);DEFINE_REFCOUNT_DOUBLE_EXTENT_AT_EVENT (xfs_refcount_find_right_extent); -DEFINE_AG_ERROR_EVENT (xfs_refcount_adjust_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_adjust_cow_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_merge_center_extents_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_modify_extent_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_split_extent_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_merge_left_extent_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_merge_right_extent_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_find_left_extent_error); -DEFINE_AG_ERROR_EVENT (xfs_refcount_find_right_extent_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_adjust_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_adjust_cow_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_merge_center_extents_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_modify_extent_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_split_extent_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_merge_left_extent_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_merge_right_extent_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_find_left_extent_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_find_right_extent_error);/* reflink helpers */ DEFINE_AG_EXTENT_EVENT (xfs_refcount_find_shared);DEFINE_AG_EXTENT_EVENT (xfs_refcount_find_shared_result); -DEFINE_AG_ERROR_EVENT (xfs_refcount_find_shared_error); +DEFINE_BTREE_ERROR_EVENT (xfs_refcount_find_shared_error); DECLARE_EVENT_CLASS(xfs_refcount_deferred_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno,
Re: [PATCH 01/10] xfs: give refcount btree cursor error tracepoints their own class
Looks good:
PATCH 2/10 xfs: create specialized classes for refcount tracepoints
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The only user of the "ag" tracepoint event classes is the refcount btree, so rename them to make that obvious and make them take the btree cursor to simplify the arguments. This will save us a lot of trouble later on.
--- fs/xfs/libxfs/xfs_refcount.c | 24 ++++++----------- fs/xfs/xfs_trace.h | 61 +++++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 37 deletions(-)
fs/xfs/libxfs/xfs_refcount.c +9 -15
@@ -51,7 +51,7 @@ xfs_refcount_lookup_le(xfs_agblock_t bno, int *stat) { - trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, +trace_xfs_refcount_lookup (cur ,xfs_refcount_encode_startblock (bno ,domain ),XFS_LOOKUP_LE ); cur->bc_rec.rc.rc_startblock = bno;
@@ -71,7 +71,7 @@ xfs_refcount_lookup_ge(xfs_agblock_t bno, int *stat) { - trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, +trace_xfs_refcount_lookup (cur ,xfs_refcount_encode_startblock (bno ,domain ),XFS_LOOKUP_GE ); cur->bc_rec.rc.rc_startblock = bno;
@@ -91,7 +91,7 @@ xfs_refcount_lookup_eq(xfs_agblock_t bno, int *stat) { - trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, +trace_xfs_refcount_lookup (cur ,xfs_refcount_encode_startblock (bno ,domain ),XFS_LOOKUP_LE ); cur->bc_rec.rc.rc_startblock = bno;
@@ -1262,11 +1262,9 @@ xfs_refcount_adjust(int error;if (adj ==XFS_REFCOUNT_ADJUST_INCREASE ) -trace_xfs_refcount_increase (cur->bc_mp, - cur->bc_ag.pag->pag_agno, *agbno, *aglen); +trace_xfs_refcount_increase (cur, *agbno, *aglen);else -trace_xfs_refcount_decrease (cur->bc_mp, - cur->bc_ag.pag->pag_agno, *agbno, *aglen); +trace_xfs_refcount_decrease (cur, *agbno, *aglen);/* * Ensure that no rcextents cross the boundary of the adjustment range.
@@ -1526,8 +1524,7 @@ xfs_refcount_find_shared(int have;int error; -trace_xfs_refcount_find_shared (cur->bc_mp, cur->bc_ag.pag->pag_agno, - agbno, aglen); +trace_xfs_refcount_find_shared (cur, agbno, aglen);/* By default, skip the whole range */ *fbno =NULLAGBLOCK ;
@@ -1614,8 +1611,7 @@ xfs_refcount_find_shared( } done: -trace_xfs_refcount_find_shared_result (cur->bc_mp, - cur->bc_ag.pag->pag_agno, *fbno, *flen); +trace_xfs_refcount_find_shared_result (cur, *fbno, *flen); out_error:if (error)
@@ -1833,8 +1829,7 @@ __xfs_refcount_cow_alloc(xfs_agblock_t agbno, xfs_extlen_t aglen) { -trace_xfs_refcount_cow_increase (rcur->bc_mp, rcur->bc_ag.pag->pag_agno, - agbno, aglen); +trace_xfs_refcount_cow_increase (rcur ,agbno ,aglen );/* Add refcount btree reservation */ return xfs_refcount_adjust_cow(rcur, agbno, aglen,
@@ -1850,8 +1845,7 @@ __xfs_refcount_cow_free(xfs_agblock_t agbno, xfs_extlen_t aglen) { -trace_xfs_refcount_cow_decrease (rcur->bc_mp, rcur->bc_ag.pag->pag_agno, - agbno, aglen); +trace_xfs_refcount_cow_decrease (rcur ,agbno ,aglen );/* Remove refcount btree reservation */ return xfs_refcount_adjust_cow(rcur, agbno, aglen,
fs/xfs/xfs_trace.h +39 -22
101 lines not on this page · raw message
Re: [PATCH 02/10] xfs: create specialized classes for refcount tracepoints
Looks good:
PATCH 3/10 xfs: prepare refcount btree tracepoints for widening
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Prepare the rest of refcount btree tracepoints for use with realtime reflink by making them take the btree cursor object as a parameter. This will save us a lot of trouble later on.
Remove the xfs_refcount_recover_extent tracepoint since it's already covered by other refcount tracepoints.
--- fs/xfs/libxfs/xfs_refcount.c | 42 ++++++++------------- fs/xfs/xfs_trace.h | 83 +++++++++++++++++++----------------------- 2 files changed, 53 insertions(+), 72 deletions(-)
fs/xfs/libxfs/xfs_refcount.c +15 -27
@@ -183,7 +183,7 @@ xfs_refcount_get_rec(if (fa)return xfs_refcount_complain_bad_rec (cur, fa, irec); -trace_xfs_refcount_get (cur->bc_mp, cur->bc_ag.pag->pag_agno, irec); +trace_xfs_refcount_get (cur, irec);return 0 ; }
@@ -201,7 +201,7 @@ xfs_refcount_update(uint32_t start;int error; -trace_xfs_refcount_update (cur->bc_mp, cur->bc_ag.pag->pag_agno, irec); +trace_xfs_refcount_update (cur, irec); start =xfs_refcount_encode_startblock (irec->rc_startblock, irec->rc_domain);
@@ -228,7 +228,7 @@ xfs_refcount_insert( {int error; -trace_xfs_refcount_insert (cur->bc_mp, cur->bc_ag.pag->pag_agno, irec); +trace_xfs_refcount_insert (cur, irec); cur->bc_rec.rc.rc_startblock = irec->rc_startblock; cur->bc_rec.rc.rc_blockcount = irec->rc_blockcount;
@@ -273,7 +273,7 @@ xfs_refcount_delete( error = -EFSCORRUPTED ; goto out_error; } -trace_xfs_refcount_delete (cur->bc_mp, cur->bc_ag.pag->pag_agno, &irec); +trace_xfs_refcount_delete (cur, &irec); error =xfs_btree_delete (cur, i);if (XFS_IS_CORRUPT (cur->bc_mp, *i !=1 )) {xfs_btree_mark_sick (cur);
@@ -410,8 +410,7 @@ xfs_refcount_split_extent(return 0 ; *shape_changed = true; -trace_xfs_refcount_split_extent (cur->bc_mp, cur->bc_ag.pag->pag_agno, - &rcext, agbno); +trace_xfs_refcount_split_extent (cur, &rcext, agbno);/* Establish the right extent. */ tmp = rcext;
@@ -454,8 +453,7 @@ xfs_refcount_merge_center_extents(int error;int found_rec; -trace_xfs_refcount_merge_center_extents (cur->bc_mp, - cur->bc_ag.pag->pag_agno, left, center, right); +trace_xfs_refcount_merge_center_extents (cur, left, center, right);ASSERT (left->rc_domain == center->rc_domain);ASSERT (right->rc_domain == center->rc_domain);
@@ -536,8 +534,7 @@ xfs_refcount_merge_left_extent(int error;int found_rec; -trace_xfs_refcount_merge_left_extent (cur->bc_mp, - cur->bc_ag.pag->pag_agno, left, cleft); +trace_xfs_refcount_merge_left_extent (cur, left, cleft);ASSERT (left->rc_domain == cleft->rc_domain);
@@ -601,8 +598,7 @@ xfs_refcount_merge_right_extent(int error;int found_rec; -trace_xfs_refcount_merge_right_extent (cur->bc_mp, - cur->bc_ag.pag->pag_agno, cright, right); +trace_xfs_refcount_merge_right_extent (cur, cright, right);ASSERT (right->rc_domain == cright->rc_domain);
@@ -741,8 +737,7 @@ xfs_refcount_find_left_extents( cleft->rc_refcount =1 ; cleft->rc_domain = domain; } -trace_xfs_refcount_find_left_extent (cur->bc_mp, cur->bc_ag.pag->pag_agno, - left, cleft, agbno); +trace_xfs_refcount_find_left_extent (cur, left, cleft, agbno);return error; out_error:
@@ -835,8 +830,8 @@ xfs_refcount_find_right_extents( cright->rc_refcount =1 ; cright->rc_domain = domain; } -trace_xfs_refcount_find_right_extent (cur->bc_mp, cur->bc_ag.pag->pag_agno, - cright, right, agbno + aglen); +trace_xfs_refcount_find_right_extent (cur, cright, right, + agbno + aglen);return error; out_error:
@@ -1139,8 +1134,7 @@ xfs_refcount_adjust_extents( tmp.rc_refcount =1 + adj; tmp.rc_domain =XFS_REFC_DOMAIN_SHARED ; -trace_xfs_refcount_modify_extent (cur->bc_mp, - cur->bc_ag.pag->pag_agno, &tmp); +trace_xfs_refcount_modify_extent (cur, &tmp);/* * Either cover the hole (increment) or
@@ -1205,8 +1199,7 @@ xfs_refcount_adjust_extents(if (ext.rc_refcount ==MAXREFCOUNT ) goto skip; ext.rc_refcount += adj; -trace_xfs_refcount_modify_extent (cur->bc_mp, - cur->bc_ag.pag->pag_agno, &ext); +trace_xfs_refcount_modify_extent (cur, &ext); cur->bc_refc.nr_ops++;if (ext.rc_refcount >1 ) { error =xfs_refcount_update (cur, &ext);
@@ -1721,8 +1714,7 @@ xfs_refcount_adjust_cow_extents( tmp.rc_refcount =1 ; tmp.rc_domain =XFS_REFC_DOMAIN_COW ; -trace_xfs_refcount_modify_extent (cur->bc_mp, - cur->bc_ag.pag->pag_agno, &tmp); +trace_xfs_refcount_modify_extent (cur, &tmp); error =xfs_refcount_insert (cur, &tmp, &found_tmp);
@@ -1753,8 +1745,7 @@ xfs_refcount_adjust_cow_extents( } ext.rc_refcount =0 ; -trace_xfs_refcount_modify_extent (cur->bc_mp, - cur->bc_ag.pag->pag_agno, &ext); +trace_xfs_refcount_modify_extent (cur, &ext); error =xfs_refcount_delete (cur, &found_rec);if (error) goto out_error;
@@ -1990,9 +1981,6 @@ xfs_refcount_recover_cow_leftovers(if (error) goto out_free; -trace_xfs_refcount_recover_extent (mp, pag->pag_agno, - &rr->rr_rrec); -/* Free the orphan record */ fsb =XFS_AGB_TO_FSB (mp, pag->pag_agno, rr->rr_rrec.rc_startblock);
fs/xfs/xfs_trace.h +38 -45
167 lines not on this page · raw message
Re: [PATCH 03/10] xfs: prepare refcount btree tracepoints for widening
Same widening comment as for the rmap one. Otherwise:
PATCH 4/10 xfs: clean up refcount log intent item tracepoint callsites
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Pass the incore refcount intent structure to the tracepoints instead of open-coding the argument passing.
--- fs/xfs/libxfs/xfs_refcount.c | 14 +++------- fs/xfs/libxfs/xfs_refcount.h | 6 ++++ fs/xfs/xfs_trace.c | 1 + fs/xfs/xfs_trace.h | 59 +++++++++++++----------------------------- 4 files changed, 29 insertions(+), 51 deletions(-)
fs/xfs/libxfs/xfs_refcount.c +4 -10
@@ -1367,9 +1367,7 @@ xfs_refcount_finish_one( bno =XFS_FSB_TO_AGBNO (mp, ri->ri_startblock); -trace_xfs_refcount_deferred (mp,XFS_FSB_TO_AGNO (mp, ri->ri_startblock), - ri->ri_type,XFS_FSB_TO_AGBNO (mp, ri->ri_startblock), - ri->ri_blockcount); +trace_xfs_refcount_deferred (mp, ri);if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_REFCOUNT_FINISH_ONE ))return -EIO ;
@@ -1432,8 +1430,7 @@ xfs_refcount_finish_one(return -EFSCORRUPTED ; }if (!error && ri->ri_blockcount >0 ) -trace_xfs_refcount_finish_one_leftover (mp, ri->ri_pag->pag_agno, - ri->ri_type, bno, ri->ri_blockcount); +trace_xfs_refcount_finish_one_leftover (mp, ri);return error; }
@@ -1449,11 +1446,6 @@ __xfs_refcount_add( {struct xfs_refcount_intent *ri; -trace_xfs_refcount_defer (tp->t_mountp, -XFS_FSB_TO_AGNO (tp->t_mountp, startblock), - type,XFS_FSB_TO_AGBNO (tp->t_mountp, startblock), - blockcount); - ri =kmem_cache_alloc (xfs_refcount_intent_cache,GFP_KERNEL | __GFP_NOFAIL);INIT_LIST_HEAD (&ri->ri_list);
@@ -1461,6 +1453,8 @@ __xfs_refcount_add( ri->ri_startblock = startblock; ri->ri_blockcount = blockcount; +trace_xfs_refcount_defer (tp->t_mountp, ri); +xfs_refcount_update_get_group (tp->t_mountp, ri);xfs_defer_add (tp, &ri->ri_list, &xfs_refcount_update_defer_type); }
fs/xfs/libxfs/xfs_refcount.h +6 -0
@@ -48,6 +48,12 @@ enum xfs_refcount_intent_type { XFS_REFCOUNT_FREE_COW, }; +#define XFS_REFCOUNT_INTENT_STRINGS \ + { XFS_REFCOUNT_INCREASE, "incr" }, \ + { XFS_REFCOUNT_DECREASE, "decr" }, \ + { XFS_REFCOUNT_ALLOC_COW, "alloc_cow" }, \ + { XFS_REFCOUNT_FREE_COW, "free_cow" } +struct xfs_refcount_intent {struct list_head ri_list;struct xfs_perag *ri_pag;
fs/xfs/xfs_trace.c +1 -0
@@ -43,6 +43,7 @@#include "xfs_exchrange.h" #include "xfs_parent.h" #include "xfs_rmap.h" +#include "xfs_refcount.h" /* * We include this last to have the helpers above available for the trace
fs/xfs/xfs_trace.h +18 -41
90 lines not on this page · raw message
Re: [PATCH 04/10] xfs: clean up refcount log intent item tracepoint callsites
Looks good:
PATCH 5/10 xfs: remove xfs_trans_set_refcount_flags
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Remove this single-use helper.
--- fs/xfs/xfs_refcount_item.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-)
fs/xfs/xfs_refcount_item.c +12 -20
@@ -243,25 +243,6 @@ xfs_refcount_update_diff_items(return ra->ri_pag->pag_agno - rb->ri_pag->pag_agno; } -/* Set the phys extent flags for this reverse mapping. */ -static void -xfs_trans_set_refcount_flags ( -struct xfs_phys_extent *pmap, -enum xfs_refcount_intent_type type) -{ - pmap->pe_flags =0 ; -switch (type) { -case XFS_REFCOUNT_INCREASE : -case XFS_REFCOUNT_DECREASE : -case XFS_REFCOUNT_ALLOC_COW : -case XFS_REFCOUNT_FREE_COW : - pmap->pe_flags |= type; -break ; -default : -ASSERT (0 ); - } -} -/* Log refcount updates in the intent item. */ STATIC void xfs_refcount_update_log_item(
@@ -282,7 +263,18 @@ xfs_refcount_update_log_item( pmap = &cuip->cui_format.cui_extents[next_extent]; pmap->pe_startblock = ri->ri_startblock; pmap->pe_len = ri->ri_blockcount; -xfs_trans_set_refcount_flags (pmap, ri->ri_type); + + pmap->pe_flags =0 ; +switch (ri->ri_type) { +case XFS_REFCOUNT_INCREASE : +case XFS_REFCOUNT_DECREASE : +case XFS_REFCOUNT_ALLOC_COW : +case XFS_REFCOUNT_FREE_COW : + pmap->pe_flags |= ri->ri_type; +break ; +default : +ASSERT (0 ); + } } static struct xfs_log_item *
Re: [PATCH 05/10] xfs: remove xfs_trans_set_refcount_flags
Looks good:
PATCH 6/10 xfs: add a ci_entry helper
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a helper to translate from the item list head to the refcount_intent_item structure and use it so shorten assignments and avoid the need for extra local variables.
--- fs/xfs/xfs_refcount_item.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
fs/xfs/xfs_refcount_item.c +9 -11
@@ -227,6 +227,11 @@ static const struct xfs_item_ops xfs_cud_item_ops = { .iop_intent = xfs_cud_item_intent, }; +static inline struct xfs_refcount_intent *ci_entry (const struct list_head *e) +{ + return list_entry(e, struct xfs_refcount_intent, ri_list); +} +/* Sort refcount intents by AG. */ static int xfs_refcount_update_diff_items(
@@ -234,11 +239,8 @@ xfs_refcount_update_diff_items(const struct list_head *a, const struct list_head *b) { - struct xfs_refcount_intent *ra; -struct xfs_refcount_intent *rb; - - ra = container_of(a, struct xfs_refcount_intent, ri_list); - rb = container_of(b, struct xfs_refcount_intent, ri_list); + struct xfs_refcount_intent *ra = ci_entry(a); +struct xfs_refcount_intent *rb =ci_entry (b);return ra->ri_pag->pag_agno - rb->ri_pag->pag_agno; }
@@ -341,11 +343,9 @@ xfs_refcount_update_finish_item(struct list_head *item, struct xfs_btree_cur **state) { - struct xfs_refcount_intent *ri; + struct xfs_refcount_intent *ri = ci_entry(item);int error; - ri = container_of(item, struct xfs_refcount_intent, ri_list); -/* Did we run out of reservation? Requeue what we didn't finish. */ error =xfs_refcount_finish_one (tp, ri, state);if (!error && ri->ri_blockcount >0 ) {
@@ -372,9 +372,7 @@ STATIC voidxfs_refcount_update_cancel_item ( struct list_head *item) { -struct xfs_refcount_intent *ri; - - ri = container_of(item, struct xfs_refcount_intent, ri_list); +struct xfs_refcount_intent *ri =ci_entry (item);xfs_refcount_update_put_group (ri);kmem_cache_free (xfs_refcount_intent_cache, ri);
Re: [PATCH 06/10] xfs: add a ci_entry helper
Looks good:
PATCH 7/10 xfs: reuse xfs_refcount_update_cancel_item
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Reuse xfs_refcount_update_cancel_item to put the AG/RTG and free the item in a few places that currently open code the logic.
--- fs/xfs/xfs_refcount_item.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
fs/xfs/xfs_refcount_item.c +12 -13
@@ -335,6 +335,17 @@ xfs_refcount_update_put_group(xfs_perag_intent_put (ri->ri_pag); } +/* Cancel a deferred refcount update. */ +STATIC void +xfs_refcount_update_cancel_item ( +struct list_head *item) +{ +struct xfs_refcount_intent *ri =ci_entry (item); + +xfs_refcount_update_put_group (ri); +kmem_cache_free (xfs_refcount_intent_cache, ri); +} +/* Process a deferred refcount update. */ STATIC int xfs_refcount_update_finish_item(
@@ -354,8 +365,7 @@ xfs_refcount_update_finish_item(return -EAGAIN ; } -xfs_refcount_update_put_group (ri); -kmem_cache_free (xfs_refcount_intent_cache, ri); +xfs_refcount_update_cancel_item (item);return error; }
@@ -367,17 +377,6 @@ xfs_refcount_update_abort_intent(xfs_cui_release (CUI_ITEM (intent)); } -/* Cancel a deferred refcount update. */ -STATIC void -xfs_refcount_update_cancel_item ( -struct list_head *item) -{ -struct xfs_refcount_intent *ri =ci_entry (item); - -xfs_refcount_update_put_group (ri); -kmem_cache_free (xfs_refcount_intent_cache, ri); -} -/* Is this recovered CUI ok? */ static inline bool xfs_cui_validate_phys(
Re: [PATCH 07/10] xfs: reuse xfs_refcount_update_cancel_item
Looks good:
PATCH 8/10 xfs: don't bother calling xfs_refcount_finish_one_cleanup in xfs_refcount_finish_one
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In xfs_refcount_finish_one we know the cursor is non-zero when calling xfs_refcount_finish_one_cleanup and we pass a 0 error variable. This means xfs_refcount_finish_one_cleanup is just doing a xfs_btree_del_cursor.
Open code that and move xfs_refcount_finish_one_cleanup to fs/xfs/xfs_refcount_item.c.
--- fs/xfs/libxfs/xfs_refcount.c | 19 +------------------ fs/xfs/libxfs/xfs_refcount.h | 2 -- fs/xfs/xfs_refcount_item.c | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_refcount.c +1 -18
@@ -1300,23 +1300,6 @@ xfs_refcount_adjust(return error; } -/* Clean up after calling xfs_refcount_finish_one. */ -void -xfs_refcount_finish_one_cleanup ( -struct xfs_trans *tp, -struct xfs_btree_cur *rcur, -int error) -{ -struct xfs_buf *agbp; - -if (rcur ==NULL ) -return ; - agbp = rcur->bc_ag.agbp; -xfs_btree_del_cursor (rcur, error); -if (error) -xfs_trans_brelse (tp, agbp); -} -/* * Set up a continuation a deferred refcount operation by updating the intent. * Checks to make sure we're not going to run off the end of the AG.
@@ -1380,7 +1363,7 @@ xfs_refcount_finish_one(if (rcur !=NULL && rcur->bc_ag.pag != ri->ri_pag) { nr_ops = rcur->bc_refc.nr_ops; shape_changes = rcur->bc_refc.shape_changes; -xfs_refcount_finish_one_cleanup (tp, rcur,0 ); +xfs_btree_del_cursor (rcur,0 ); rcur =NULL ; *pcur =NULL ; }
fs/xfs/libxfs/xfs_refcount.h +0 -2
@@ -82,8 +82,6 @@ void xfs_refcount_increase_extent(struct xfs_trans *tp,void xfs_refcount_decrease_extent (struct xfs_trans *tp,struct xfs_bmbt_irec *irec); -extern void xfs_refcount_finish_one_cleanup (struct xfs_trans *tp, -struct xfs_btree_cur *rcur,int error);extern int xfs_refcount_finish_one (struct xfs_trans *tp,struct xfs_refcount_intent *ri,struct xfs_btree_cur **pcur);
fs/xfs/xfs_refcount_item.c +18 -0
@@ -21,6 +21,7 @@#include "xfs_log_priv.h" #include "xfs_log_recover.h" #include "xfs_ag.h" +#include "xfs_btree.h" struct kmem_cache *xfs_cui_cache;struct kmem_cache *xfs_cud_cache;
@@ -369,6 +370,23 @@ xfs_refcount_update_finish_item(return error; } +/* Clean up after calling xfs_refcount_finish_one. */ +STATIC void +xfs_refcount_finish_one_cleanup ( +struct xfs_trans *tp, +struct xfs_btree_cur *rcur, +int error) +{ +struct xfs_buf *agbp; + +if (rcur ==NULL ) +return ; + agbp = rcur->bc_ag.agbp; +xfs_btree_del_cursor (rcur, error); +if (error) +xfs_trans_brelse (tp, agbp); +} +/* Abort all pending CUIs. */ STATIC void xfs_refcount_update_abort_intent(
Re: [PATCH 08/10] xfs: don't bother calling xfs_refcount_finish_one_cleanup in xfs_refcount_finish_one
Looks good:
PATCH 9/10 xfs: simplify usage of the rcur local variable in xfs_refcount_finish_one
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Only update rcur when we know the final *pcur value.
--- fs/xfs/libxfs/xfs_refcount.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_refcount.c +3 -4
@@ -1341,7 +1341,7 @@ xfs_refcount_finish_one( struct xfs_btree_cur **pcur) {struct xfs_mount *mp = tp->t_mountp; -struct xfs_btree_cur *rcur; +struct xfs_btree_cur *rcur = *pcur;struct xfs_buf *agbp =NULL ;int error =0 ;xfs_agblock_t bno;
@@ -1359,7 +1359,6 @@ xfs_refcount_finish_one(* If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ - rcur = *pcur;if (rcur !=NULL && rcur->bc_ag.pag != ri->ri_pag) { nr_ops = rcur->bc_refc.nr_ops; shape_changes = rcur->bc_refc.shape_changes;
@@ -1373,11 +1372,11 @@ xfs_refcount_finish_one(if (error)return error; - rcur =xfs_refcountbt_init_cursor (mp, tp, agbp, ri->ri_pag); + *pcur = rcur =xfs_refcountbt_init_cursor (mp, tp, agbp, + ri->ri_pag); rcur->bc_refc.nr_ops = nr_ops; rcur->bc_refc.shape_changes = shape_changes; } - *pcur = rcur;switch (ri->ri_type) {case XFS_REFCOUNT_INCREASE :
Re: [PATCH 09/10] xfs: simplify usage of the rcur local variable in xfs_refcount_finish_one
Looks good:
PATCH 10/10 xfs: move xfs_refcount_update_defer_add to xfs_refcount_item.c
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the code that adds the incore xfs_refcount_update_item deferred work data to a transaction live with the CUI log item code. This means that the refcount code no longer has to know about the inner workings of the CUI log items.
As a consequence, we can get rid of the _{get,put}_group helpers.
--- fs/xfs/libxfs/xfs_refcount.c | 6 ++---- fs/xfs/libxfs/xfs_refcount.h | 3 --- fs/xfs/xfs_refcount_item.c | 24 +++++++++++------------- fs/xfs/xfs_refcount_item.h | 5 +++++ 4 files changed, 18 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_refcount.c +2 -4
@@ -24,6 +24,7 @@#include "xfs_rmap.h" #include "xfs_ag.h" #include "xfs_health.h" +#include "xfs_refcount_item.h" struct kmem_cache *xfs_refcount_intent_cache;
@@ -1435,10 +1436,7 @@ __xfs_refcount_add( ri->ri_startblock = startblock; ri->ri_blockcount = blockcount; -trace_xfs_refcount_defer (tp->t_mountp, ri); - -xfs_refcount_update_get_group (tp->t_mountp, ri); -xfs_defer_add (tp, &ri->ri_list, &xfs_refcount_update_defer_type); +xfs_refcount_defer_add (tp, ri); }/*
fs/xfs/libxfs/xfs_refcount.h +0 -3
@@ -74,9 +74,6 @@ xfs_refcount_check_domain(return true; } -void xfs_refcount_update_get_group (struct xfs_mount *mp, -struct xfs_refcount_intent *ri); -void xfs_refcount_increase_extent (struct xfs_trans *tp,struct xfs_bmbt_irec *irec); void xfs_refcount_decrease_extent(struct xfs_trans *tp,
fs/xfs/xfs_refcount_item.c +11 -13
@@ -22,6 +22,7 @@#include "xfs_log_recover.h" #include "xfs_ag.h" #include "xfs_btree.h" +#include "xfs_trace.h" struct kmem_cache *xfs_cui_cache;struct kmem_cache *xfs_cud_cache;
@@ -319,21 +320,18 @@ xfs_refcount_update_create_done(return &cudp->cud_item; } -/* Take a passive ref to the AG containing the space we're refcounting. */ +/* Add this deferred CUI to the transaction. */ void -xfs_refcount_update_get_group ( -struct xfs_mount *mp, +xfs_refcount_defer_add ( +struct xfs_trans *tp,struct xfs_refcount_intent *ri) { +struct xfs_mount *mp = tp->t_mountp; + +trace_xfs_refcount_defer (mp, ri); + ri->ri_pag =xfs_perag_intent_get (mp, ri->ri_startblock); -} - -/* Release a passive AG ref after finishing refcounting work. */ -static inline void -xfs_refcount_update_put_group ( -struct xfs_refcount_intent *ri) -{ -xfs_perag_intent_put (ri->ri_pag); +xfs_defer_add (tp, &ri->ri_list, &xfs_refcount_update_defer_type); }/* Cancel a deferred refcount update. */
@@ -343,7 +341,7 @@ xfs_refcount_update_cancel_item( {struct xfs_refcount_intent *ri =ci_entry (item); -xfs_refcount_update_put_group (ri); +xfs_perag_intent_put (ri->ri_pag);kmem_cache_free (xfs_refcount_intent_cache, ri); }
@@ -433,7 +431,7 @@ xfs_cui_recover_work( ri->ri_type = pmap->pe_flags &XFS_REFCOUNT_EXTENT_TYPE_MASK ; ri->ri_startblock = pmap->pe_startblock; ri->ri_blockcount = pmap->pe_len; -xfs_refcount_update_get_group (mp, ri); + ri->ri_pag =xfs_perag_intent_get (mp, pmap->pe_startblock);xfs_defer_add_item (dfp, &ri->ri_list); }
fs/xfs/xfs_refcount_item.h +5 -0
@@ -71,4 +71,9 @@ struct xfs_cud_log_item {extern struct kmem_cache *xfs_cui_cache;extern struct kmem_cache *xfs_cud_cache; +struct xfs_refcount_intent ; + +void xfs_refcount_defer_add (struct xfs_trans *tp, +struct xfs_refcount_intent *ri); +#endif /* __XFS_REFCOUNT_ITEM_H__ */
Re: [PATCH 10/10] xfs: move xfs_refcount_update_defer_add to xfs_refcount_item.c
Looks good:
PATCH 5/5 xfs: enable FITRIM for the realtime section
In reply to Darrick J. WongHi all,
One thing that's been missing for a long time is the ability to tell underlying storage that it can unmap the unused space on the realtime device. This short series exposes this functionality through FITRIM. Callers that want ranged FITRIM should be aware that the realtime space exists in the offset range after the data device. However, it is anticipated that most callers pass in offset=0 len=-1ULL and will not notice or care.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=realtime-discard
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=realtime-discard
---
Commits in this patchset:
* xfs: enable FITRIM on the realtime device
--- fs/xfs/xfs_discard.c | 252 +++++++++++++++++++++++++++++++++++++++++++++++++- fs/xfs/xfs_trace.h | 29 ++++++ 2 files changed, 274 insertions(+), 7 deletions(-)
PATCH 1/1 xfs: enable FITRIM on the realtime device
From: Darrick J. Wong <[email protected]>
Implement FITRIM for the realtime device by pretending that it's "space" immediately after the data device. We have to hold the rtbitmap ILOCK while the discard operations are ongoing because there's no busy extent tracking to prevent reallocations.
--- fs/xfs/xfs_discard.c | 252 +++++++++++++++++++++++++++++++++++++++++++++++++- fs/xfs/xfs_trace.h | 29 ++++++ 2 files changed, 274 insertions(+), 7 deletions(-)
fs/xfs/xfs_discard.c +245 -7
@@ -20,6 +20,7 @@#include "xfs_log.h" #include "xfs_ag.h" #include "xfs_health.h" +#include "xfs_rtbitmap.h" /* * Notes on an efficient, low latency fstrim algorithm
@@ -383,6 +384,217 @@ xfs_trim_extents( } +#ifdef CONFIG_XFS_RT +struct xfs_trim_rtdev { +/* list of rt extents to free */ +struct list_head extent_list; + +/* pointer to count of blocks trimmed */ +uint64_t *blocks_trimmed; + +/* minimum length that caller allows us to trim */ +xfs_rtblock_t minlen_fsb; + +/* restart point for the rtbitmap walk */ +xfs_rtxnum_t restart_rtx; + +/* stopping point for the current rtbitmap walk */ +xfs_rtxnum_t stop_rtx; +}; + +struct xfs_rtx_busy { +struct list_head list; +xfs_rtblock_t bno; +xfs_rtblock_t length; +}; + +static void +xfs_discard_free_rtdev_extents ( +struct xfs_trim_rtdev *tr) +{ +struct xfs_rtx_busy *busyp, *n; + +list_for_each_entry_safe (busyp, n, &tr->extent_list, list) { +list_del_init (&busyp->list); +kfree (busyp); + } +} + +/* +* Walk the discard list and issue discards on all the busy extents in the +* list. We plug and chain the bios so that we only need a single completion +* call to clear all the busy extents once the discards are complete. +*/ +static int +xfs_discard_rtdev_extents ( +struct xfs_mount *mp, +struct xfs_trim_rtdev *tr) +{ +struct block_device *bdev = mp->m_rtdev_targp->bt_bdev; +struct xfs_rtx_busy *busyp; +struct bio *bio =NULL ; +struct blk_plug plug; +xfs_rtblock_t start =NULLRTBLOCK , length =0 ; +int error =0 ; + +blk_start_plug (&plug); +list_for_each_entry (busyp, &tr->extent_list, list) { +if (start ==NULLRTBLOCK ) + start = busyp->bno; + length += busyp->length; + +trace_xfs_discard_rtextent (mp, busyp->bno, busyp->length); + + error =__blkdev_issue_discard (bdev, +XFS_FSB_TO_BB (mp, busyp->bno), +XFS_FSB_TO_BB (mp, busyp->length), +GFP_NOFS , &bio); +if (error) +break ; + } +xfs_discard_free_rtdev_extents (tr); + +if (bio) { + error =submit_bio_wait (bio); +if (error == -EOPNOTSUPP ) + error =0 ; +if (error) +xfs_info (mp, +"discard failed for rtextent [0x%llx,%llu], error %d" , + (unsigned long long )start, + (unsigned long long )length, + error); +bio_put (bio); + } +blk_finish_plug (&plug); + +return error; +} + +static int +xfs_trim_gather_rtextent ( +struct xfs_mount *mp, +struct xfs_trans *tp, +const struct xfs_rtalloc_rec *rec, +void *priv) +{ +struct xfs_trim_rtdev *tr = priv; +struct xfs_rtx_busy *busyp; +xfs_rtblock_t rbno, rlen; + +if (rec->ar_startext > tr->stop_rtx) { +/* +* If we've scanned a large number of rtbitmap blocks, update +* the cursor to point at this extent so we restart the next +* batch from this extent. +*/ + tr->restart_rtx = rec->ar_startext; +return -ECANCELED ; + } + + rbno =xfs_rtx_to_rtb (mp, rec->ar_startext); + rlen =xfs_rtx_to_rtb (mp, rec->ar_extcount); + +/* Ignore too small. */ +if (rlen < tr->minlen_fsb) { +trace_xfs_discard_rttoosmall (mp, rbno, rlen); +return 0 ; + } + + busyp =kzalloc (sizeof (struct xfs_rtx_busy ),GFP_KERNEL ); +if (!busyp) +return -ENOMEM ; + + busyp->bno = rbno; + busyp->length = rlen; +INIT_LIST_HEAD (&busyp->list); +list_add_tail (&busyp->list, &tr->extent_list); + *tr->blocks_trimmed += rlen; + + tr->restart_rtx = rec->ar_startext + rec->ar_extcount; +return 0 ; +} + +static int +xfs_trim_rtdev_extents ( +struct xfs_mount *mp, +xfs_daddr_t start, +xfs_daddr_t end, +xfs_daddr_t minlen, +uint64_t *blocks_trimmed) +{ +struct xfs_rtalloc_rec low = { }; +struct xfs_rtalloc_rec high = { }; +struct xfs_trim_rtdev tr = { + .blocks_trimmed = blocks_trimmed, + .minlen_fsb =XFS_BB_TO_FSB (mp, minlen), + }; +struct xfs_trans *tp; +xfs_daddr_t rtdev_daddr; +int error; + +INIT_LIST_HEAD (&tr.extent_list); + +/* Shift the start and end downwards to match the rt device. */ + rtdev_daddr =XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks); +if (start > rtdev_daddr) + start -= rtdev_daddr; +else + start =0 ; + +if (end <= rtdev_daddr) +return 0 ; + end -= rtdev_daddr; + + error =xfs_trans_alloc_empty (mp, &tp); +if (error) +return error; + +if (end >XFS_FSB_TO_BB (mp, mp->m_sb.sb_rblocks) -1 ) + end =XFS_FSB_TO_BB (mp, mp->m_sb.sb_rblocks) -1 ; + +/* Convert the rt blocks to rt extents */ + low.ar_startext =xfs_rtb_to_rtxup (mp,XFS_BB_TO_FSB (mp, start)); + high.ar_startext =xfs_rtb_to_rtx (mp,XFS_BB_TO_FSBT (mp, end)); + +/* +* Walk the free ranges between low and high. The query_range function +* trims the extents returned. +*/ +do { + tr.stop_rtx = low.ar_startext + (mp->m_sb.sb_blocksize *NBBY ); +xfs_rtbitmap_lock_shared (mp,XFS_RBMLOCK_BITMAP ); + error =xfs_rtalloc_query_range (mp, tp, &low, &high, + xfs_trim_gather_rtextent, &tr); + +if (error == -ECANCELED ) + error =0 ; +if (error) { +xfs_rtbitmap_unlock_shared (mp,XFS_RBMLOCK_BITMAP ); +xfs_discard_free_rtdev_extents (&tr); +break ; + } + +if (list_empty (&tr.extent_list)) { +xfs_rtbitmap_unlock_shared (mp,XFS_RBMLOCK_BITMAP ); +break ; + } + + error =xfs_discard_rtdev_extents (mp, &tr); +xfs_rtbitmap_unlock_shared (mp,XFS_RBMLOCK_BITMAP ); +if (error) +break ; + + low.ar_startext = tr.restart_rtx; + }while (!xfs_trim_should_stop () && low.ar_startext <= high.ar_startext); + +xfs_trans_cancel (tp); +return error; +} +#else +# define xfs_trim_rtdev_extents (m,s,e,n,b) (-EOPNOTSUPP) +#endif /* CONFIG_XFS_RT */ +/* * trim a range of the filesystem. *
@@ -391,6 +603,9 @@ xfs_trim_extents(* addressing. FSB addressing is sparse (AGNO|AGBNO), while the incoming format * is a linear address range. Hence we need to use DADDR based conversions and * comparisons for determining the correct offset and regions to trim. +* +* The realtime device is mapped into the FITRIM "address space" immediately +* after the data device. */ int xfs_ioc_trim(
@@ -400,19 +615,28 @@ xfs_ioc_trim(struct xfs_perag *pag;unsigned int granularity =bdev_discard_granularity (mp->m_ddev_targp->bt_bdev); +struct block_device *rt_bdev =NULL ;struct fstrim_range range; -xfs_daddr_t start, end; +xfs_daddr_t start, end, ddev_end;xfs_extlen_t minlen;xfs_agnumber_t start_agno, end_agno;xfs_agblock_t start_agbno, end_agbno; +xfs_rfsblock_t max_blocks;uint64_t blocks_trimmed =0 ;int error, last_error =0 ;if (!capable (CAP_SYS_ADMIN ))return -EPERM ; -if (!bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev)) +if (mp->m_rtdev_targp) + rt_bdev = mp->m_rtdev_targp->bt_bdev; +if (!bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev) && + (!rt_bdev || !bdev_max_discard_sectors (rt_bdev)))return -EOPNOTSUPP ; +if (rt_bdev) + granularity =max (granularity, +bdev_discard_granularity (rt_bdev)); +/* * We haven't recovered the log, so we cannot use our bnobt-guided * storage zapping commands.
@@ -433,19 +657,25 @@ xfs_ioc_trim(* used by the fstrim application. In the end it really doesn't * matter as trimming blocks is an advisory interface. */ -if (range.start >=XFS_FSB_TO_B (mp, mp->m_sb.sb_dblocks) || + max_blocks = mp->m_sb.sb_dblocks + mp->m_sb.sb_rblocks; +if (range.start >=XFS_FSB_TO_B (mp, max_blocks) || range.minlen >XFS_FSB_TO_B (mp, mp->m_ag_max_usable) || range.len < mp->m_sb.sb_blocksize)return -EINVAL ; start =BTOBB (range.start); - end =min_t (xfs_daddr_t, start +BTOBBT (range.len), -XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks)) -1 ; + end = start +BTOBBT (range.len) -1 ; + +if (!bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev)) + goto rt_discard; + + ddev_end =min_t (xfs_daddr_t, end, +XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks) -1 ); start_agno =xfs_daddr_to_agno (mp, start); start_agbno =xfs_daddr_to_agbno (mp, start); - end_agno =xfs_daddr_to_agno (mp, end); - end_agbno =xfs_daddr_to_agbno (mp, end); + end_agno =xfs_daddr_to_agno (mp, ddev_end); + end_agbno =xfs_daddr_to_agbno (mp, ddev_end);for_each_perag_range (mp, start_agno, end_agno, pag) {xfs_agblock_t agend = pag->block_count;
@@ -464,6 +694,14 @@ xfs_ioc_trim( start_agbno =0 ; } +rt_discard: +if (rt_bdev &&bdev_max_discard_sectors (rt_bdev)) { + error =xfs_trim_rtdev_extents (mp, start, end, minlen, + &blocks_trimmed); +if (error) + last_error = error; + } +if (last_error)return last_error;
fs/xfs/xfs_trace.h +29 -0
@@ -2463,6 +2463,35 @@ DEFINE_DISCARD_EVENT(xfs_discard_toosmall);DEFINE_DISCARD_EVENT (xfs_discard_exclude);DEFINE_DISCARD_EVENT (xfs_discard_busy); +DECLARE_EVENT_CLASS (xfs_rtdiscard_class, + TP_PROTO(struct xfs_mount *mp, + xfs_rtblock_t rtbno, xfs_rtblock_t len), +TP_ARGS (mp, rtbno, len), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(xfs_rtblock_t, rtbno) +__field (xfs_rtblock_t, len) + ), +TP_fast_assign ( + __entry->dev = mp->m_rtdev_targp->bt_dev; + __entry->rtbno = rtbno; + __entry->len = len; + ), +TP_printk ("dev %d:%d rtbno 0x%llx rtbcount 0x%llx" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->rtbno, + __entry->len) +) + +#define DEFINE_RTDISCARD_EVENT (name) \ +DEFINE_EVENT(xfs_rtdiscard_class, name, \ + TP_PROTO(struct xfs_mount *mp, \ + xfs_rtblock_t rtbno, xfs_rtblock_t len), \ + TP_ARGS(mp, rtbno, len)) +DEFINE_RTDISCARD_EVENT (xfs_discard_rtextent); +DEFINE_RTDISCARD_EVENT (xfs_discard_rttoosmall); +DEFINE_RTDISCARD_EVENT (xfs_discard_rtrelax); + DECLARE_EVENT_CLASS(xfs_btree_cur_class, TP_PROTO(struct xfs_btree_cur *cur, int level, struct xfs_buf *bp), TP_ARGS(cur, level, bp),
Re: [PATCH 1/1] xfs: enable FITRIM on the realtime device
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (!bdev_max_discard_sectors(mp->m_ddev_targp->bt_bdev)) + goto rt_discard; +
I think this would looks much better if we split the ddev trimming into a separate helper, just like this patch does for the RT device:
fs/xfs/xfs_discard.c +45 -28
@@ -595,6 +595,48 @@ xfs_trim_rtdev_extents(# define xfs_trim_rtdev_extents (m,s,e,n,b) (-EOPNOTSUPP)#endif /* CONFIG_XFS_RT */ +static int +xfs_trim_dddev_extents ( +struct xfs_mount *mp, +xfs_daddr_t start, +xfs_daddr_t end, +xfs_extlen_t minlen, +uint64_t *blocks_trimmed) +{ +xfs_agnumber_t start_agno, end_agno; +xfs_agblock_t start_agbno, end_agbno; +xfs_daddr_t ddev_end; +struct xfs_perag *pag; +int last_error =0 , error; + + ddev_end =min_t (xfs_daddr_t, end, +XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks) -1 ); + + start_agno =xfs_daddr_to_agno (mp, start); + start_agbno =xfs_daddr_to_agbno (mp, start); + end_agno =xfs_daddr_to_agno (mp, ddev_end); + end_agbno =xfs_daddr_to_agbno (mp, ddev_end); + +for_each_perag_range (mp, start_agno, end_agno, pag) { +xfs_agblock_t agend = pag->block_count; + +if (start_agno == end_agno) + agend = end_agbno; + error =xfs_trim_extents (pag, start_agbno, agend, minlen, + blocks_trimmed); +if (error) + last_error = error; + +if (xfs_trim_should_stop ()) { +xfs_perag_rele (pag); +break ; + } + start_agbno =0 ; + } + +return last_error; +} +/* * trim a range of the filesystem. *
@@ -612,15 +654,12 @@ xfs_ioc_trim(struct xfs_mount *mp, struct fstrim_range __user *urange) { - struct xfs_perag *pag; unsigned int granularity =bdev_discard_granularity (mp->m_ddev_targp->bt_bdev);struct block_device *rt_bdev =NULL ;struct fstrim_range range; -xfs_daddr_t start, end, ddev_end; +xfs_daddr_t start, end;xfs_extlen_t minlen; -xfs_agnumber_t start_agno, end_agno; -xfs_agblock_t start_agbno, end_agbno;xfs_rfsblock_t max_blocks;uint64_t blocks_trimmed =0 ;int error, last_error =0 ;
@@ -666,35 +705,13 @@ xfs_ioc_trim( start =BTOBB (range.start); end = start +BTOBBT (range.len) -1 ; -if (!bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev)) - goto rt_discard; - - ddev_end =min_t (xfs_daddr_t, end, -XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks) -1 ); - - start_agno =xfs_daddr_to_agno (mp, start); - start_agbno =xfs_daddr_to_agbno (mp, start); - end_agno =xfs_daddr_to_agno (mp, ddev_end); - end_agbno =xfs_daddr_to_agbno (mp, ddev_end); - -for_each_perag_range (mp, start_agno, end_agno, pag) { -xfs_agblock_t agend = pag->block_count; - -if (start_agno == end_agno) - agend = end_agbno; - error =xfs_trim_extents (pag, start_agbno, agend, minlen, +if (bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev)) { + error =xfs_trim_dddev_extents (mp, start, end, minlen, &blocks_trimmed);if (error) last_error = error; - -if (xfs_trim_should_stop ()) { -xfs_perag_rele (pag); -break ; - } - start_agbno =0 ; } -rt_discard:if (rt_bdev &&bdev_max_discard_sectors (rt_bdev)) { error =xfs_trim_rtdev_extents (mp, start, end, minlen, &blocks_trimmed);
Re: [PATCH 1/1] xfs: enable FITRIM on the realtime device
Quoted 91 lines · Christoph Hellwig
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (!bdev_max_discard_sectors(mp->m_ddev_targp->bt_bdev)) + goto rt_discard; +I think this would looks much better if we split the ddev trimming into a separate helper, just like this patch does for the RT device:
fs/xfs/xfs_discard.c +43
-14@@ -595,6 +595,48 @@ xfs_trim_rtdev_extents(# define xfs_trim_rtdev_extents (m,s,e,n,b) (-EOPNOTSUPP)#endif /* CONFIG_XFS_RT */ +static int +xfs_trim_dddev_extents ( +struct xfs_mount *mp, +xfs_daddr_t start, +xfs_daddr_t end, +xfs_extlen_t minlen, +uint64_t *blocks_trimmed) +{ +xfs_agnumber_t start_agno, end_agno; +xfs_agblock_t start_agbno, end_agbno; +xfs_daddr_t ddev_end; +struct xfs_perag *pag; +int last_error =0 , error; + + ddev_end =min_t (xfs_daddr_t, end, +XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks) -1 ); + + start_agno =xfs_daddr_to_agno (mp, start); + start_agbno =xfs_daddr_to_agbno (mp, start); + end_agno =xfs_daddr_to_agno (mp, ddev_end); + end_agbno =xfs_daddr_to_agbno (mp, ddev_end); + +for_each_perag_range (mp, start_agno, end_agno, pag) { +xfs_agblock_t agend = pag->block_count; + +if (start_agno == end_agno) + agend = end_agbno; + error =xfs_trim_extents (pag, start_agbno, agend, minlen, + blocks_trimmed); +if (error) + last_error = error; + +if (xfs_trim_should_stop ()) { +xfs_perag_rele (pag); +break ; + } + start_agbno =0 ; + } + +return last_error; +} +/* * trim a range of the filesystem. * @@ -612,15 +654,12 @@ xfs_ioc_trim(struct xfs_mount *mp, struct fstrim_range __user *urange) { - struct xfs_perag *pag; unsigned int granularity =bdev_discard_granularity (mp->m_ddev_targp->bt_bdev);struct block_device *rt_bdev =NULL ;struct fstrim_range range; -xfs_daddr_t start, end, ddev_end; +xfs_daddr_t start, end;xfs_extlen_t minlen; -xfs_agnumber_t start_agno, end_agno; -xfs_agblock_t start_agbno, end_agbno;xfs_rfsblock_t max_blocks;uint64_t blocks_trimmed =0 ;int error, last_error =0 ;@@ -666,35 +705,13 @@ xfs_ioc_trim( start =BTOBB (range.start); end = start +BTOBBT (range.len) -1 ; -if (!bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev)) - goto rt_discard; - - ddev_end =min_t (xfs_daddr_t, end, -XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks) -1 ); - - start_agno =xfs_daddr_to_agno (mp, start); - start_agbno =xfs_daddr_to_agbno (mp, start); - end_agno =xfs_daddr_to_agno (mp, ddev_end); - end_agbno =xfs_daddr_to_agbno (mp, ddev_end);
fs/xfs/xfs_discard.c xfs_ioc_trim( · line 710
Quoted 10 lines
fs/xfs/xfs_discard.c +2
-7- -for_each_perag_range (mp, start_agno, end_agno, pag) { -xfs_agblock_t agend = pag->block_count; - -if (start_agno == end_agno) - agend = end_agbno; - error =xfs_trim_extents (pag, start_agbno, agend, minlen, +if (bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev)) { + error =xfs_trim_dddev_extents (mp, start, end, minlen, &blocks_trimmed);
I quite like this cleanup, though I think I'll name the helper xfs_trim_datadev_extents instead.
fs/xfs/xfs_discard.c xfs_ioc_trim( · line 715
Quoted 12 lines
fs/xfs/xfs_discard.c +0
-7if (error) last_error = error; - -if (xfs_trim_should_stop ()) { -xfs_perag_rele (pag); -break ; - } - start_agbno =0 ; } -rt_discard:if (rt_bdev &&bdev_max_discard_sectors (rt_bdev)) {
This needs to check !xfs_trim_should_stop() as well, so that a ^C during the data device discard isn't followed by a rtbitmap query.
Will send a V2.
--D
Quoted 3 lines
fs/xfs/xfs_discard.c +0
-0error =xfs_trim_rtdev_extents (mp, start, end, minlen, &blocks_trimmed);
PATCH v2 1/1 xfs: enable FITRIM on the realtime device
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Implement FITRIM for the realtime device by pretending that it's "space" immediately after the data device. We have to hold the rtbitmap ILOCK while the discard operations are ongoing because there's no busy extent tracking for the rt volume to prevent reallocations.
---
v2: split out the datadev discard code into separate helpers
--- fs/xfs/xfs_discard.c | 303 ++++++++++++++++++++++++++++++++++++++++++++++---- fs/xfs/xfs_trace.h | 29 +++++ 2 files changed, 308 insertions(+), 24 deletions(-)
fs/xfs/xfs_discard.c +279 -24
@@ -20,6 +20,7 @@#include "xfs_log.h" #include "xfs_ag.h" #include "xfs_health.h" +#include "xfs_rtbitmap.h" /* * Notes on an efficient, low latency fstrim algorithm
@@ -322,7 +323,7 @@ xfs_trim_should_stop(void)* we found in the last batch as the key to start the next. */ static int -xfs_trim_extents( +xfs_trim_perag_extents( struct xfs_perag *pag, xfs_agblock_t start, xfs_agblock_t end,
@@ -383,6 +384,259 @@ xfs_trim_extents( } +static int +xfs_trim_datadev_extents ( +struct xfs_mount *mp, +xfs_daddr_t start, +xfs_daddr_t end, +xfs_extlen_t minlen, +uint64_t *blocks_trimmed) +{ +xfs_agnumber_t start_agno, end_agno; +xfs_agblock_t start_agbno, end_agbno; +xfs_daddr_t ddev_end; +struct xfs_perag *pag; +int last_error =0 , error; + + ddev_end =min_t (xfs_daddr_t, end, +XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks) -1 ); + + start_agno =xfs_daddr_to_agno (mp, start); + start_agbno =xfs_daddr_to_agbno (mp, start); + end_agno =xfs_daddr_to_agno (mp, ddev_end); + end_agbno =xfs_daddr_to_agbno (mp, ddev_end); + +for_each_perag_range (mp, start_agno, end_agno, pag) { +xfs_agblock_t agend = pag->block_count; + +if (start_agno == end_agno) + agend = end_agbno; + error =xfs_trim_perag_extents (pag, start_agbno, agend, minlen, + blocks_trimmed); +if (error) + last_error = error; + +if (xfs_trim_should_stop ()) { +xfs_perag_rele (pag); +break ; + } + start_agbno =0 ; + } + +return last_error; +} + +#ifdef CONFIG_XFS_RT +struct xfs_trim_rtdev { +/* list of rt extents to free */ +struct list_head extent_list; + +/* pointer to count of blocks trimmed */ +uint64_t *blocks_trimmed; + +/* minimum length that caller allows us to trim */ +xfs_rtblock_t minlen_fsb; + +/* restart point for the rtbitmap walk */ +xfs_rtxnum_t restart_rtx; + +/* stopping point for the current rtbitmap walk */ +xfs_rtxnum_t stop_rtx; +}; + +struct xfs_rtx_busy { +struct list_head list; +xfs_rtblock_t bno; +xfs_rtblock_t length; +}; + +static void +xfs_discard_free_rtdev_extents ( +struct xfs_trim_rtdev *tr) +{ +struct xfs_rtx_busy *busyp, *n; + +list_for_each_entry_safe (busyp, n, &tr->extent_list, list) { +list_del_init (&busyp->list); +kfree (busyp); + } +} + +/* +* Walk the discard list and issue discards on all the busy extents in the +* list. We plug and chain the bios so that we only need a single completion +* call to clear all the busy extents once the discards are complete. +*/ +static int +xfs_discard_rtdev_extents ( +struct xfs_mount *mp, +struct xfs_trim_rtdev *tr) +{ +struct block_device *bdev = mp->m_rtdev_targp->bt_bdev; +struct xfs_rtx_busy *busyp; +struct bio *bio =NULL ; +struct blk_plug plug; +xfs_rtblock_t start =NULLRTBLOCK , length =0 ; +int error =0 ; + +blk_start_plug (&plug); +list_for_each_entry (busyp, &tr->extent_list, list) { +if (start ==NULLRTBLOCK ) + start = busyp->bno; + length += busyp->length; + +trace_xfs_discard_rtextent (mp, busyp->bno, busyp->length); + + error =__blkdev_issue_discard (bdev, +XFS_FSB_TO_BB (mp, busyp->bno), +XFS_FSB_TO_BB (mp, busyp->length), +GFP_NOFS , &bio); +if (error) +break ; + } +xfs_discard_free_rtdev_extents (tr); + +if (bio) { + error =submit_bio_wait (bio); +if (error == -EOPNOTSUPP ) + error =0 ; +if (error) +xfs_info (mp, +"discard failed for rtextent [0x%llx,%llu], error %d" , + (unsigned long long )start, + (unsigned long long )length, + error); +bio_put (bio); + } +blk_finish_plug (&plug); + +return error; +} + +static int +xfs_trim_gather_rtextent ( +struct xfs_mount *mp, +struct xfs_trans *tp, +const struct xfs_rtalloc_rec *rec, +void *priv) +{ +struct xfs_trim_rtdev *tr = priv; +struct xfs_rtx_busy *busyp; +xfs_rtblock_t rbno, rlen; + +if (rec->ar_startext > tr->stop_rtx) { +/* +* If we've scanned a large number of rtbitmap blocks, update +* the cursor to point at this extent so we restart the next +* batch from this extent. +*/ + tr->restart_rtx = rec->ar_startext; +return -ECANCELED ; + } + + rbno =xfs_rtx_to_rtb (mp, rec->ar_startext); + rlen =xfs_rtx_to_rtb (mp, rec->ar_extcount); + +/* Ignore too small. */ +if (rlen < tr->minlen_fsb) { +trace_xfs_discard_rttoosmall (mp, rbno, rlen); +return 0 ; + } + + busyp =kzalloc (sizeof (struct xfs_rtx_busy ),GFP_KERNEL ); +if (!busyp) +return -ENOMEM ; + + busyp->bno = rbno; + busyp->length = rlen; +INIT_LIST_HEAD (&busyp->list); +list_add_tail (&busyp->list, &tr->extent_list); + *tr->blocks_trimmed += rlen; + + tr->restart_rtx = rec->ar_startext + rec->ar_extcount; +return 0 ; +} + +static int +xfs_trim_rtdev_extents ( +struct xfs_mount *mp, +xfs_daddr_t start, +xfs_daddr_t end, +xfs_daddr_t minlen, +uint64_t *blocks_trimmed) +{ +struct xfs_rtalloc_rec low = { }; +struct xfs_rtalloc_rec high = { }; +struct xfs_trim_rtdev tr = { + .blocks_trimmed = blocks_trimmed, + .minlen_fsb =XFS_BB_TO_FSB (mp, minlen), + }; +struct xfs_trans *tp; +xfs_daddr_t rtdev_daddr; +int error; + +INIT_LIST_HEAD (&tr.extent_list); + +/* Shift the start and end downwards to match the rt device. */ + rtdev_daddr =XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks); +if (start > rtdev_daddr) + start -= rtdev_daddr; +else + start =0 ; + +if (end <= rtdev_daddr) +return 0 ; + end -= rtdev_daddr; + + error =xfs_trans_alloc_empty (mp, &tp); +if (error) +return error; + + end =min_t (xfs_daddr_t, end, +XFS_FSB_TO_BB (mp, mp->m_sb.sb_rblocks) -1 ); + +/* Convert the rt blocks to rt extents */ + low.ar_startext =xfs_rtb_to_rtxup (mp,XFS_BB_TO_FSB (mp, start)); + high.ar_startext =xfs_rtb_to_rtx (mp,XFS_BB_TO_FSBT (mp, end)); + +/* +* Walk the free ranges between low and high. The query_range function +* trims the extents returned. +*/ +do { + tr.stop_rtx = low.ar_startext + (mp->m_sb.sb_blocksize *NBBY ); +xfs_rtbitmap_lock_shared (mp,XFS_RBMLOCK_BITMAP ); + error =xfs_rtalloc_query_range (mp, tp, &low, &high, + xfs_trim_gather_rtextent, &tr); + +if (error == -ECANCELED ) + error =0 ; +if (error) { +xfs_rtbitmap_unlock_shared (mp,XFS_RBMLOCK_BITMAP ); +xfs_discard_free_rtdev_extents (&tr); +break ; + } + +if (list_empty (&tr.extent_list)) { +xfs_rtbitmap_unlock_shared (mp,XFS_RBMLOCK_BITMAP ); +break ; + } + + error =xfs_discard_rtdev_extents (mp, &tr); +xfs_rtbitmap_unlock_shared (mp,XFS_RBMLOCK_BITMAP ); +if (error) +break ; + + low.ar_startext = tr.restart_rtx; + }while (!xfs_trim_should_stop () && low.ar_startext <= high.ar_startext); + +xfs_trans_cancel (tp); +return error; +} +#else +# define xfs_trim_rtdev_extents (m,s,e,n,b) (-EOPNOTSUPP) +#endif /* CONFIG_XFS_RT */ +/* * trim a range of the filesystem. *
@@ -391,28 +645,37 @@ xfs_trim_extents(* addressing. FSB addressing is sparse (AGNO|AGBNO), while the incoming format * is a linear address range. Hence we need to use DADDR based conversions and * comparisons for determining the correct offset and regions to trim. +* +* The realtime device is mapped into the FITRIM "address space" immediately +* after the data device. */ int xfs_ioc_trim (struct xfs_mount *mp,struct fstrim_range __user *urange) { -struct xfs_perag *pag;unsigned int granularity =bdev_discard_granularity (mp->m_ddev_targp->bt_bdev); +struct block_device *rt_bdev =NULL ;struct fstrim_range range;xfs_daddr_t start, end;xfs_extlen_t minlen; -xfs_agnumber_t start_agno, end_agno; -xfs_agblock_t start_agbno, end_agbno; +xfs_rfsblock_t max_blocks;uint64_t blocks_trimmed =0 ;int error, last_error =0 ;if (!capable (CAP_SYS_ADMIN ))return -EPERM ; -if (!bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev)) +if (mp->m_rtdev_targp && +bdev_max_discard_sectors (mp->m_rtdev_targp->bt_bdev)) + rt_bdev = mp->m_rtdev_targp->bt_bdev; +if (!bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev) && !rt_bdev)return -EOPNOTSUPP ; +if (rt_bdev) + granularity =max (granularity, +bdev_discard_granularity (rt_bdev)); +/* * We haven't recovered the log, so we cannot use our bnobt-guided * storage zapping commands.
@@ -433,35 +696,27 @@ xfs_ioc_trim(* used by the fstrim application. In the end it really doesn't * matter as trimming blocks is an advisory interface. */ -if (range.start >=XFS_FSB_TO_B (mp, mp->m_sb.sb_dblocks) || + max_blocks = mp->m_sb.sb_dblocks + mp->m_sb.sb_rblocks; +if (range.start >=XFS_FSB_TO_B (mp, max_blocks) || range.minlen >XFS_FSB_TO_B (mp, mp->m_ag_max_usable) || range.len < mp->m_sb.sb_blocksize)return -EINVAL ; start =BTOBB (range.start); - end =min_t (xfs_daddr_t, start +BTOBBT (range.len), -XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks)) -1 ; + end = start +BTOBBT (range.len) -1 ; - start_agno =xfs_daddr_to_agno (mp, start); - start_agbno =xfs_daddr_to_agbno (mp, start); - end_agno =xfs_daddr_to_agno (mp, end); - end_agbno =xfs_daddr_to_agbno (mp, end); - -for_each_perag_range (mp, start_agno, end_agno, pag) { -xfs_agblock_t agend = pag->block_count; - -if (start_agno == end_agno) - agend = end_agbno; - error =xfs_trim_extents (pag, start_agbno, agend, minlen, +if (bdev_max_discard_sectors (mp->m_ddev_targp->bt_bdev)) { + error =xfs_trim_datadev_extents (mp, start, end, minlen, &blocks_trimmed);if (error) last_error = error; + } -if (xfs_trim_should_stop ()) { -xfs_perag_rele (pag); -break ; - } - start_agbno =0 ; +if (rt_bdev && !xfs_trim_should_stop ()) { + error =xfs_trim_rtdev_extents (mp, start, end, minlen, + &blocks_trimmed); +if (error) + last_error = error; }if (last_error)
fs/xfs/xfs_trace.h +29 -0
@@ -2463,6 +2463,35 @@ DEFINE_DISCARD_EVENT(xfs_discard_toosmall);DEFINE_DISCARD_EVENT (xfs_discard_exclude);DEFINE_DISCARD_EVENT (xfs_discard_busy); +DECLARE_EVENT_CLASS (xfs_rtdiscard_class, + TP_PROTO(struct xfs_mount *mp, + xfs_rtblock_t rtbno, xfs_rtblock_t len), +TP_ARGS (mp, rtbno, len), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(xfs_rtblock_t, rtbno) +__field (xfs_rtblock_t, len) + ), +TP_fast_assign ( + __entry->dev = mp->m_rtdev_targp->bt_dev; + __entry->rtbno = rtbno; + __entry->len = len; + ), +TP_printk ("dev %d:%d rtbno 0x%llx rtbcount 0x%llx" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->rtbno, + __entry->len) +) + +#define DEFINE_RTDISCARD_EVENT (name) \ +DEFINE_EVENT(xfs_rtdiscard_class, name, \ + TP_PROTO(struct xfs_mount *mp, \ + xfs_rtblock_t rtbno, xfs_rtblock_t len), \ + TP_ARGS(mp, rtbno, len)) +DEFINE_RTDISCARD_EVENT (xfs_discard_rtextent); +DEFINE_RTDISCARD_EVENT (xfs_discard_rttoosmall); +DEFINE_RTDISCARD_EVENT (xfs_discard_rtrelax); + DECLARE_EVENT_CLASS(xfs_btree_cur_class, TP_PROTO(struct xfs_btree_cur *cur, int level, struct xfs_buf *bp), TP_ARGS(cur, level, bp),
Re: [PATCH v2 1/1] xfs: enable FITRIM on the realtime device
Looks good:
Re: [PATCH v2 1/1] xfs: enable FITRIM on the realtime device
In reply to Darrick J. WongQuoted 7 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Implement FITRIM for the realtime device by pretending that it's "space" immediately after the data device. We have to hold the rtbitmap ILOCK while the discard operations are ongoing because there's no busy extent tracking for the rt volume to prevent reallocations.
Darrick, This patch causes generic/260 to fail in configuration using a realtime device as shown below,
export TEST_DEV=/dev/loop0
export TEST_DIR=/mnt/test
export TEST_RTDEV=/dev/loop2
export SCRATCH_DEV=/dev/loop1
export SCRATCH_MNT=/mnt/scratch
export SCRATCH_RTDEV=/dev/loop3
export USE_EXTERNAL=yes
MOUNT_OPTIONS='-o usrquota,grpquota,prjquota'
export MKFS_OPTIONS="-i nrext64=1 -m rmapbt=0,reflink=0 -d rtinherit=1"
Here is the test execution log,
# ./check generic/260 RECREATING -- xfs on /dev/loop0 FSTYP -- xfs (debug) PLATFORM -- Linux/x86_64 fstest 6.10.0-rc5-gb62c1dbbb6cb #9 SMP PREEMPT_DYNAMIC Thu Jun 27 11:51:06 IST 2024 MKFS_OPTIONS -- -f -rrtdev=/dev/loop3 -i nrext64=1 -m rmapbt=0,reflink=0 -d rtinherit=1 /dev/loop1 MOUNT_OPTIONS -- -o usrquota,grpquota,prjquota -ortdev=/dev/loop3 /dev/loop1 /mnt/scratch
generic/260 2s ... [failed, exit status 1]- output mismatch (see /root/repos/xfstests-dev/results//generic/260.out.bad)
--- tests/generic/260.out 2022-01-12 11:19:21.869941572 +0530
+++ /root/repos/xfstests-dev/results//generic/260.out.bad 2024-06-27 11:59:47.980946925 +0530
@@ -11,4 +11,5 @@
[+] Default length with start set (should succeed)
[+] Length beyond the end of fs (should succeed)
[+] Length beyond the end of fs with start set (should succeed)
+After the full fs discard 42871967744 bytes were discarded however the file system is 21474836480 bytes long.
Test done
...
(Run 'diff -u /root/repos/xfstests-dev/tests/generic/260.out /root/repos/xfstests-dev/results//generic/260.out.bad' to see the entire diff)
Ran: generic/260
Failures: generic/260
Failed 1 of 1 tests
Signature · 1 line
Chandan
Re: [PATCH v2 1/1] xfs: enable FITRIM on the realtime device
Quoted 2 lines · Chandan Babu R
Darrick, This patch causes generic/260 to fail in configuration using a realtime device as shown below,
It'll need "generic/{251,260}: compute maximum fitrim offset" from Darrick's xfstests stack.
Re: [PATCH v2 1/1] xfs: enable FITRIM on the realtime device
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Chandan Babu R
Darrick, This patch causes generic/260 to fail in configuration using a realtime device as shown below,
It'll need "generic/{251,260}: compute maximum fitrim offset" from Darrick's xfstests stack.
Actually that one is already merged, it needs
common/xfs: FITRIM now supports realtime volumes
on top of that.
Re: [PATCH v2 1/1] xfs: enable FITRIM on the realtime device
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Chandan Babu R
Darrick, This patch causes generic/260 to fail in configuration using a realtime device as shown below,
Quoted 8 lines
Quoted 2 lines
It'll need "generic/{251,260}: compute maximum fitrim offset" from Darrick's xfstests stack.
Actually that one is already merged, it needs
common/xfs: FITRIM now supports realtime volumes
on top of that.
Correct.
--D
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20240723032327.GU1998502@frogsfrogsfrogs
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20240723232805.GX1998502@frogsfrogsfrogs
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20240724235707.GG1646003@frogsfrogsfrogs
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): 20240806163246.GD623936@frogsfrogsfrogs
A message that is not in the archive (sent off-list or not yet received): 20240806230656.GD623922@frogsfrogsfrogs
Re: [PATCH 1/1] xfs: enable FITRIM on the realtime device
Hi Darrick,
We were able to reproduce the bug recently. Below is the script that did it:
#!/bin/sh
fallocate /mnt/file1 -l $((1024*1024*1024*1024*11)) fallocate /mnt/file2 -l $((1024*1024*1024*1024*11))
truncate -s 0 /mnt/file2
rm /mnt/file2
xfs_spaceman -c 'prealloc -s' /mnt
fstrim /mnt -v
The output of fstrim showed that the realtime partition hadn't been trimmed.
I've attached two reports to this mail (short and full). Please take a look.
Thanks,
Konst
Re: [PATCHSET v3.0 5/5] xfs: enable FITRIM for the realtime section
In reply to Darrick J. WongHi Darrick,
Thanks for the patch. Is there a reason why it is not in the mainline yet?
Best regards,
Konst
Quoted 30 lines · Darrick J. Wong
Hi all,
One thing that's been missing for a long time is the ability to tell underlying storage that it can unmap the unused space on the realtime device. This short series exposes this functionality through FITRIM. Callers that want ranged FITRIM should be aware that the realtime space exists in the offset range after the data device. However, it is anticipated that most callers pass in offset=0 len=-1ULL and will not notice or care.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=realtime-discardfstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=realtime-discard
---
Commits in this patchset:
* xfs: enable FITRIM on the realtime device--- fs/xfs/xfs_discard.c | 252 +++++++++++++++++++++++++++++++++++++++++++++++++- fs/xfs/xfs_trace.h | 29 ++++++ 2 files changed, 274 insertions(+), 7 deletions(-)
Re: [PATCHSET v3.0 5/5] xfs: enable FITRIM for the realtime section
Quoted 3 lines · Konst Mayer
Hi Darrick,
Thanks for the patch. Is there a reason why it is not in the mainline yet?
Lack of review bandwidth, I'm sorry to say.
--D
Quoted 37 lines
Best regards,
KonstQuoted 30 lines · Darrick J. Wong
Hi all,
One thing that's been missing for a long time is the ability to tell underlying storage that it can unmap the unused space on the realtime device. This short series exposes this functionality through FITRIM. Callers that want ranged FITRIM should be aware that the realtime space exists in the offset range after the data device. However, it is anticipated that most callers pass in offset=0 len=-1ULL and will not notice or care.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=realtime-discardfstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=realtime-discard
---
Commits in this patchset:
* xfs: enable FITRIM on the realtime device--- fs/xfs/xfs_discard.c | 252 +++++++++++++++++++++++++++++++++++++++++++++++++- fs/xfs/xfs_trace.h | 29 ++++++ 2 files changed, 274 insertions(+), 7 deletions(-)