xfs: modernize the realtime volume
Subsystems (4)
PATCH 3/4 xfs: modernize the realtime volume
Hi all,
This third patchset deluge is for the realtime modernization project. There are five main parts to this effort -- adding a metadata directory tree; sharding the realtime volume into allocation groups to reduce metadata lock contention; adding reverse mapping; adding reflink; and adding the one piece needed to make quotas work on realtime. This brings the robustness of the realtime volume up to par with the data volume.
Originally, the modernization effort was a side project that was intended to match XFS up to the proliferation of persistent memory. The data device would store metadata on cheap(er) flash storage, and the realtime volume would be used to map persistent memory to files and take advantage of the ability to do PMD-aligned allocations. It's now less clear how much of that will actually happen (CXL?), but the code's finished, reasonably well tested, and ready for review.
NOTE: I hacked up metadump to support saving the metadata contents of external logs and realtime devices so that I could run fuzz testing in the least thoughtful way possible. Chandan is working on improving the deployment image story for our customers, and will likely produce something better than my rush job.
As a warning, the patches will likely take several days to trickle in.
--D
cover 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 mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. 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
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_bmap.c | 42 + fs/xfs/libxfs/xfs_bmap.h | 3 fs/xfs/libxfs/xfs_dir2.c | 479 +++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 19 + fs/xfs/libxfs/xfs_ialloc.c | 20 + fs/xfs/libxfs/xfs_inode_util.c | 698 ++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 79 +++ fs/xfs/libxfs/xfs_shared.h | 7 fs/xfs/libxfs/xfs_trans_inode.c | 2 fs/xfs/scrub/tempfile.c | 20 - fs/xfs/xfs_inode.c | 1231 +++++---------------------------------- fs/xfs/xfs_inode.h | 46 + fs/xfs/xfs_ioctl.c | 60 -- fs/xfs/xfs_iops.c | 51 +- fs/xfs/xfs_linux.h | 2 fs/xfs/xfs_qm.c | 8 fs/xfs/xfs_reflink.h | 10 fs/xfs/xfs_symlink.c | 22 - fs/xfs/xfs_trans.h | 1 20 files changed, 1564 insertions(+), 1237 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_inode_util.c create mode 100644 fs/xfs/libxfs/xfs_inode_util.h
PATCH 1/20 xfs: move inode copy-on-write predicates to xfs_inode.[ch]
From: 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 | 7 +++++++ fs/xfs/xfs_inode.h | 7 +++++++ fs/xfs/xfs_reflink.h | 10 ---------- 3 files changed, 14 insertions(+), 10 deletions(-)
fs/xfs/xfs_inode.c +7 -0
@@ -3859,3 +3859,10 @@ xfs_inode_alloc_unitsize(return XFS_FSB_TO_B (ip->i_mount, blocks); } + +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
@@ -276,6 +276,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,
PATCH 2/20 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 | 41 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_bmap.h | 3 +++ fs/xfs/xfs_inode.c | 43 ------------------------------------------- fs/xfs/xfs_inode.h | 3 --- fs/xfs/xfs_iops.c | 1 + 5 files changed, 45 insertions(+), 46 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +41 -0
@@ -6413,3 +6413,44 @@ 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)) +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
@@ -292,4 +292,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 -43
49 lines not on this page · raw message
fs/xfs/xfs_inode.h +0 -3
@@ -532,9 +532,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 user_namespace *mnt_userns, 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
@@ -25,6 +25,7 @@#include "xfs_error.h" #include "xfs_ioctl.h" #include "xfs_xattr.h" +#include "xfs_bmap.h" #include <linux/posix_acl.h> #include <linux/security.h>
PATCH 3/20 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
@@ -39,6 +39,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_rmap.o \
fs/xfs/libxfs/xfs_bmap.c +1 -0
@@ -38,6 +38,7 @@#include "xfs_iomap.h" #include "xfs_health.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
@@ -518,7 +519,6 @@ bool xfs_isilocked(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
PATCH 4/20 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 | 11 +++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 2 ++ fs/xfs/xfs_inode.h | 9 --------- fs/xfs/xfs_linux.h | 2 -- 4 files changed, 13 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +11 -0
@@ -122,3 +122,14 @@ xfs_ip2xflags( flags |=FS_XFLAG_HASATTR ;return flags; } + +#define XFS_PROJID_DEFAULT 0 + +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 ; +}
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
@@ -255,15 +255,6 @@ xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short 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
@@ -134,8 +134,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)
PATCH 5/20 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 | 31 +++++++++++++ fs/xfs/scrub/tempfile.c | 13 +++-- fs/xfs/xfs_inode.c | 99 ++++++++++++++++++++++++++++------------ fs/xfs/xfs_inode.h | 10 ++-- fs/xfs/xfs_qm.c | 8 ++- fs/xfs/xfs_symlink.c | 14 +++--- 6 files changed, 127 insertions(+), 48 deletions(-)
fs/xfs/libxfs/xfs_inode_util.h +31 -0
@@ -13,4 +13,35 @@ uint32_t xfs_ip2xflags(struct xfs_inode *ip);prid_t xfs_get_initial_prid (struct xfs_inode *dp); +/* +* Initial ids, link count, device number, and mode of a new inode. +* +* Due to our only partial reliance on the VFS to propagate uid and gid values +* according to accepted Unix behaviors, callers must initialize mnt_userns to +* the appropriate namespace, uid to fsuid_into_mnt(), and gid to +* fsgid_into_mnt() to get the correct inheritance behaviors when +* XFS_MOUNT_GRPID is set. Use the xfs_ialloc_inherit_args() helper. +* +* To override the default ids, use the FORCE flags defined below. +*/ +struct xfs_icreate_args { +struct user_namespace *mnt_userns; +struct xfs_inode *pip;/* parent inode or null */ + +kuid_t uid; +kgid_t gid; +prid_t prid; + +xfs_nlink_t nlink; +dev_t rdev; + +umode_t mode; + +#define XFS_ICREATE_ARGS_FORCE_UID (1 << 0) +#define XFS_ICREATE_ARGS_FORCE_GID (1 << 1) +#define XFS_ICREATE_ARGS_FORCE_MODE (1 << 2) +#define XFS_ICREATE_ARGS_INIT_XATTRS (1 << 3) +uint16_t flags; +}; +#endif /* __XFS_INODE_UTIL_H__ */
fs/xfs/scrub/tempfile.c +7 -6
@@ -40,6 +40,7 @@ xrep_tempfile_create( struct xfs_scrub *sc, uint16_t mode) { +struct xfs_icreate_args args = { .pip = sc->mp->m_rootip, };struct xfs_mount *mp = sc->mp;struct xfs_trans *tp =NULL ;struct xfs_dquot *udqp =NULL ;
@@ -60,12 +61,15 @@ xrep_tempfile_create(ASSERT (sc->tp ==NULL );ASSERT (sc->tempip ==NULL ); +/* Force everything to have the root ids and mode we want. */ +xfs_icreate_args_rootfile (&args, mode); +/* * Make sure that we have allocated dquot(s) on disk. The temporary * 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 , + error =xfs_qm_vop_dqalloc (dp, args.uid, args.gid, args.prid,XFS_QMOPT_QUOTALL , &udqp, &gdqp, &pdqp);if (error)return error;
@@ -87,14 +91,11 @@ xrep_tempfile_create( error =xfs_dialloc (&tp, dp->i_ino, mode, &ino);if (error) goto out_trans_cancel; - error =xfs_init_new_inode (&init_user_ns, 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 +70 -29
199 lines not on this page · raw message
fs/xfs/xfs_inode.h +6 -4
@@ -523,10 +523,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 user_namespace *mnt_userns,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(
@@ -626,4 +624,8 @@ void xfs_nlink_hook_del(struct xfs_mount *mp, struct xfs_nlink_hook *hook);# define xfs_nlink_dirent_delta (dp, ip, delta, name) ((void)0)#endif /* CONFIG_XFS_LIVE_HOOKS */ +void xfs_icreate_args_inherit (struct xfs_icreate_args *args,struct xfs_inode *dp, +struct user_namespace *mnt_userns,umode_t mode); +void xfs_icreate_args_rootfile (struct xfs_icreate_args *args,umode_t mode); +#endif /* __XFS_INODE_H__ */
fs/xfs/xfs_qm.c +6 -2
@@ -791,12 +791,16 @@ xfs_qm_qino_alloc(return error;if (need_alloc) { +struct xfs_icreate_args args = { + .nlink =1 , + };xfs_ino_t ino; +xfs_icreate_args_rootfile (&args,S_IFREG ); + error =xfs_dialloc (&tp,0 ,S_IFREG , &ino);if (!error) - error =xfs_init_new_inode (&init_user_ns, 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 +7 -7
@@ -88,6 +88,9 @@ xfs_symlink(umode_t mode, struct xfs_inode **ipp) { + struct xfs_icreate_args args = { + .nlink =1 , + };struct xfs_mount *mp = dp->i_mount;struct xfs_trans *tp =NULL ;struct xfs_inode *ip =NULL ;
@@ -95,7 +98,6 @@ 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 ;
@@ -117,13 +119,13 @@ xfs_symlink(return -ENAMETOOLONG ;ASSERT (pathlen >0 ); - prid =xfs_get_initial_prid (dp); +xfs_icreate_args_inherit (&args, dp, mnt_userns, +S_IFLNK | (mode & ~S_IFMT ));/* * Make sure that we have allocated dquot(s) on disk. */ - error =xfs_qm_vop_dqalloc (dp,mapped_fsuid (mnt_userns, &init_user_ns), -mapped_fsgid (mnt_userns, &init_user_ns), prid, + error =xfs_qm_vop_dqalloc (dp, args.uid, args.gid, args.prid,XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , &udqp, &gdqp, &pdqp);if (error)
@@ -160,9 +162,7 @@ xfs_symlink(*/ error =xfs_dialloc (&tp, dp->i_ino,S_IFLNK , &ino);if (!error) - error =xfs_init_new_inode (mnt_userns, tp, dp, ino, -S_IFLNK | (mode & ~S_IFMT ),1 ,0 , prid, - false, &ip); + error =xfs_icreate (tp, ino, &args, &ip);if (error) goto out_trans_cancel;
PATCH 6/20 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
@@ -137,6 +137,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
@@ -69,6 +69,8 @@ xfs_trans_ichgtime( inode->i_mtime = tv;if (flags &XFS_ICHGTIME_CHG ) inode->i_ctime = tv; +if (flags &XFS_ICHGTIME_ACCESS ) + inode->i_atime = tv;if (flags &XFS_ICHGTIME_CREATE ) ip->i_crtime = tv; }
PATCH 7/20 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 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
fs/xfs/xfs_inode.c +7 -9
@@ -689,10 +689,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
@@ -755,20 +756,17 @@ xfs_icreate( ip->i_df.if_nextents =0 ;ASSERT (ip->i_nblocks ==0 ); - tv =current_time (inode); - inode->i_mtime = tv; - inode->i_atime = tv; - inode->i_ctime = 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 :
PATCH 8/20 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 | 20 ++++++++++++- fs/xfs/xfs_inode.c | 66 ++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 38 deletions(-)
fs/xfs/libxfs/xfs_ialloc.c +18 -2
@@ -1870,9 +1870,25 @@ xfs_dialloc( }xfs_perag_put (pag); } +if (error) + goto out; -if (!error) - *new_ino = ino; +/* +* 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_ag_mark_sick (pag,XFS_SICK_AG_INOBT ); + error = -EFSCORRUPTED ; + goto out; + } + + *new_ino = ino; +out:xfs_perag_put (pag);return error; }
fs/xfs/xfs_inode.c +30 -36
89 lines not on this page · raw message
PATCH 9/20 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 | 201 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 21 ++++ fs/xfs/libxfs/xfs_shared.h | 8 -- fs/xfs/xfs_inode.c | 198 +-------------------------------------- fs/xfs/xfs_inode.h | 1 fs/xfs/xfs_trans.h | 1 6 files changed, 228 insertions(+), 202 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +201 -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(
@@ -133,3 +138,199 @@ xfs_get_initial_prid(struct xfs_inode *dp)return XFS_PROJID_DEFAULT ; } + +/* 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 ; + +set_nlink (inode, args->nlink); + inode->i_rdev = args->rdev; + ip->i_projid = args->prid; + +if (dir && !(dir->i_mode &S_ISGID ) &&xfs_has_grpid (mp)) { +inode_fsuid_set (inode, args->mnt_userns); + inode->i_gid = dir->i_gid; + inode->i_mode = args->mode; + }else { +inode_init_owner (args->mnt_userns, inode, dir, args->mode); + } +xfs_inode_sgid_inherit (args, ip); + +/* struct copies */ +if (args->flags &XFS_ICREATE_ARGS_FORCE_UID ) + inode->i_uid = args->uid; +else +ASSERT (uid_eq (inode->i_uid, args->uid)); +if (args->flags &XFS_ICREATE_ARGS_FORCE_GID ) + inode->i_gid = args->gid; +else if (!pip || !XFS_INHERIT_GID (pip)) +ASSERT (gid_eq (inode->i_gid, args->gid)); +if (args->flags &XFS_ICREATE_ARGS_FORCE_MODE ) + inode->i_mode = args->mode; + + 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_u1.if_root =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_ARGS_INIT_XATTRS ) && +xfs_has_attr (mp)) { + ip->i_forkoff =xfs_default_attroffset (ip) >>3 ; +xfs_ifork_init_attr (ip,XFS_DINODE_FMT_EXTENTS ,0 ); + } + +/* +* Log the new values stuffed into the inode. +*/ +xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL ); +xfs_trans_log_inode (tp, ip, flags); + +/* now that we have an i_mode we can setup the inode structure */ +xfs_setup_inode (ip); +}
fs/xfs/libxfs/xfs_inode_util.h +21 -0
@@ -44,4 +44,25 @@ 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); + +/* The libxfs client must provide this group of helper functions. */ + +/* Handle legacy Irix sgid inheritance quirks. */ +void xfs_inode_sgid_inherit (const struct xfs_icreate_args *args, +struct xfs_inode *ip); + +/* Initialize the incore inode. */ +void xfs_setup_inode (struct xfs_inode *ip); +#endif /* __XFS_INODE_UTIL_H__ */
fs/xfs/libxfs/xfs_shared.h +0 -8
@@ -131,14 +131,6 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,#define XFS_RCBAG_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 +6 -192
217 lines not on this page · raw message
fs/xfs/xfs_inode.h +0 -1
@@ -542,7 +542,6 @@ int xfs_break_layouts(struct inode *inode, uint *iolock, enum layout_break_reason reason);/* from xfs_iops.c */ -extern void xfs_setup_inode (struct xfs_inode *ip);extern void xfs_setup_iops (struct xfs_inode *ip);extern void xfs_diflags_to_iflags (struct xfs_inode *ip,bool init);
fs/xfs/xfs_trans.h +0 -1
@@ -228,7 +228,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 );
PATCH 10/20 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 | 59 +++++++++++++++++++++++----------------------------- fs/xfs/xfs_inode.h | 9 ++++---- fs/xfs/xfs_iops.c | 50 +++++++++++++++++++++++++++----------------- 3 files changed, 61 insertions(+), 57 deletions(-)
fs/xfs/xfs_inode.c +26 -33
@@ -808,44 +808,34 @@ xfs_nlink_hook_del(int xfs_create ( -struct user_namespace *mnt_userns, -xfs_inode_t *dp, +struct xfs_inode *dp,struct xfs_name *name, -umode_t mode, -dev_t rdev, -bool init_xattrs, -xfs_inode_t **ipp) +const struct xfs_icreate_args *args, +struct xfs_inode **ipp) { -struct xfs_icreate_args args = { - .rdev = rdev, - .nlink =S_ISDIR (mode) ?2 :1 , - }; -int is_dir =S_ISDIR (mode);struct xfs_mount *mp = dp->i_mount;struct xfs_inode *ip =NULL ;struct xfs_trans *tp =NULL ; -int error; -bool unlock_dp_on_error = false;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; +bool unlock_dp_on_error = false; +bool is_dir =S_ISDIR (args->mode); +uint resblks; +int error; +ASSERT (args->pip == dp);trace_xfs_create (dp, name);if (xfs_is_shutdown (mp))return -EIO ; -xfs_icreate_args_inherit (&args, dp, mnt_userns, mode); -if (init_xattrs) - args.flags |=XFS_ICREATE_ARGS_INIT_XATTRS ; -/* * Make sure that we have allocated dquot(s) on disk. */ - error =xfs_qm_vop_dqalloc (dp, args.uid, args.gid, args.prid, + error =xfs_qm_vop_dqalloc (dp, args->uid, args->gid, args->prid,XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , &udqp, &gdqp, &pdqp);if (error)
@@ -884,9 +874,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;
@@ -977,32 +967,31 @@ xfs_create(int xfs_create_tmpfile ( -struct user_namespace *mnt_userns,struct xfs_inode *dp, -umode_t mode, +const struct xfs_icreate_args *args,struct xfs_inode **ipp) { -struct xfs_icreate_args args = {NULL };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; -uint resblks;xfs_ino_t ino; +uint resblks; +int error; + +ASSERT (args->nlink ==0 ); +ASSERT (args->pip == dp);if (xfs_is_shutdown (mp))return -EIO ; -xfs_icreate_args_inherit (&args, dp, mnt_userns, mode); -/* * Make sure that we have allocated dquot(s) on disk. */ - error =xfs_qm_vop_dqalloc (dp, args.uid, args.gid, args.prid, + error =xfs_qm_vop_dqalloc (dp, args->uid, args->gid, args->prid,XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , &udqp, &gdqp, &pdqp);if (error)
@@ -1016,9 +1005,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;
@@ -2750,12 +2739,16 @@ xfs_rename_alloc_whiteout(struct xfs_inode *dp, struct xfs_inode **wip) { + struct xfs_icreate_args args = { + .nlink =0 , + };struct xfs_inode *tmpfile;struct qstr name;int error; - error =xfs_create_tmpfile (mnt_userns, dp,S_IFCHR |WHITEOUT_MODE , - &tmpfile); +xfs_icreate_args_inherit (&args, dp, mnt_userns,S_IFCHR |WHITEOUT_MODE ); + + error =xfs_create_tmpfile (dp, &args, &tmpfile);if (error)return error;
fs/xfs/xfs_inode.h +4 -5
@@ -485,12 +485,11 @@ int xfs_release(struct xfs_inode *ip);void 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 user_namespace *mnt_userns, -struct xfs_inode *dp,struct xfs_name *name, -umode_t mode,dev_t rdev,bool need_xattr, +int xfs_create (struct xfs_inode *dp,struct xfs_name *name, +const struct xfs_icreate_args *iargs,struct xfs_inode **ipp); -int xfs_create_tmpfile (struct user_namespace *mnt_userns, -struct xfs_inode *dp,umode_t mode, +int xfs_create_tmpfile (struct xfs_inode *dp, +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 +31 -19
75 lines not on this page · raw message
PATCH 11/20 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 | 38 ++++++++++++++++++++++++++------------ fs/xfs/xfs_inode.h | 3 +++ fs/xfs/xfs_symlink.c | 10 ++++------ 4 files changed, 37 insertions(+), 23 deletions(-)
fs/xfs/scrub/tempfile.c +4 -5
@@ -43,9 +43,9 @@ xrep_tempfile_create(struct xfs_icreate_args args = { .pip = sc->mp->m_rootip, };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;
@@ -69,8 +69,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, args.uid, args.gid, args.prid, -XFS_QMOPT_QUOTALL , &udqp, &gdqp, &pdqp); + error =xfs_icreate_dqalloc (&args, &udqp, &gdqp, &pdqp);if (error)return error;
fs/xfs/xfs_inode.c +26 -12
@@ -806,6 +806,24 @@ xfs_nlink_hook_del(# define xfs_nlink_backref_delta (dp, ip, delta) ((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) +{ +unsigned int flags =XFS_QMOPT_QUOTALL ; + + *udqpp = *gdqpp = *pdqpp =NULL ; + +if (!(args->flags &XFS_ICREATE_ARGS_FORCE_GID )) + flags |=XFS_QMOPT_INHERIT ; + +return xfs_qm_vop_dqalloc (args->pip, args->uid, args->gid, args->prid, + flags, udqpp, gdqpp, pdqpp); +} + int xfs_create( struct xfs_inode *dp,
@@ -816,9 +834,9 @@ xfs_create(struct xfs_mount *mp = dp->i_mount;struct xfs_inode *ip =NULL ;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;xfs_ino_t ino;bool unlock_dp_on_error = false;
@@ -835,9 +853,7 @@ xfs_create(/* * Make sure that we have allocated dquot(s) on disk. */ - error =xfs_qm_vop_dqalloc (dp, args->uid, args->gid, args->prid, -XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , - &udqp, &gdqp, &pdqp); + error =xfs_icreate_dqalloc (args, &udqp, &gdqp, &pdqp);if (error)return error;
@@ -974,9 +990,9 @@ xfs_create_tmpfile(struct xfs_mount *mp = dp->i_mount;struct xfs_inode *ip =NULL ;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;xfs_ino_t ino;uint resblks;
@@ -991,9 +1007,7 @@ xfs_create_tmpfile(/* * Make sure that we have allocated dquot(s) on disk. */ - error =xfs_qm_vop_dqalloc (dp, args->uid, args->gid, args->prid, -XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , - &udqp, &gdqp, &pdqp); + error =xfs_icreate_dqalloc (args, &udqp, &gdqp, &pdqp);if (error)return error;
fs/xfs/xfs_inode.h +3 -0
@@ -625,5 +625,8 @@ void xfs_nlink_hook_del(struct xfs_mount *mp, struct xfs_nlink_hook *hook);void xfs_icreate_args_inherit (struct xfs_icreate_args *args,struct xfs_inode *dp,struct user_namespace *mnt_userns,umode_t mode);void xfs_icreate_args_rootfile (struct xfs_icreate_args *args,umode_t mode); +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 +4 -6
@@ -98,9 +98,9 @@ xfs_symlink(int pathlen;bool unlock_dp_on_error = false;xfs_filblks_t fs_blocks; -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;
@@ -125,9 +125,7 @@ xfs_symlink(/* * Make sure that we have allocated dquot(s) on disk. */ - error =xfs_qm_vop_dqalloc (dp, args.uid, args.gid, args.prid, -XFS_QMOPT_QUOTALL |XFS_QMOPT_INHERIT , - &udqp, &gdqp, &pdqp); + error =xfs_icreate_dqalloc (&args, &udqp, &gdqp, &pdqp);if (error)return error;
PATCH 12/20 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 | 276 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 4 + fs/xfs/xfs_inode.c | 275 ---------------------------------------- fs/xfs/xfs_inode.h | 1 4 files changed, 280 insertions(+), 276 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +276 -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(
@@ -334,3 +338,275 @@ xfs_inode_init(/* now that we have an i_mode we can setup the inode structure */ xfs_setup_inode (ip); } + +/* +* 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. */ +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) { +xfs_ag_mark_sick (pag,XFS_SICK_AG_AGI ); +return -EFSCORRUPTED ; + } + + 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) +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, &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) +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, &agibp); +if (error) +return error; + +return xfs_iunlink_remove_inode (tp, pag, agibp, ip); +}
fs/xfs/libxfs/xfs_inode_util.h +4 -0
@@ -56,6 +56,10 @@ 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); +/* The libxfs client must provide this group of helper functions. */ /* Handle legacy Irix sgid inheritance quirks. */
fs/xfs/xfs_inode.c +0 -275
293 lines not on this page · raw message
fs/xfs/xfs_inode.h +0 -1
@@ -574,7 +574,6 @@ 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);struct xfs_inode *xfs_iunlink_lookup (struct xfs_perag *pag,xfs_agino_t agino);void xfs_end_io (struct work_struct *work);
PATCH 13/20 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 | 35 +++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 2 ++ fs/xfs/xfs_inode.c | 35 ----------------------------------- fs/xfs/xfs_inode.h | 1 - 4 files changed, 37 insertions(+), 36 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +35 -0
@@ -610,3 +610,38 @@ 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) +{ +xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG ); + +drop_nlink (VFS_I (ip)); +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); + +if (VFS_I (ip)->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) +{ +xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG ); + +inc_nlink (VFS_I (ip)); +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); +}
fs/xfs/libxfs/xfs_inode_util.h +2 -0
@@ -59,6 +59,8 @@ 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);/* The libxfs client must provide this group of helper functions. */
fs/xfs/xfs_inode.c +0 -35
@@ -657,41 +657,6 @@ xfs_icreate_args_rootfile(XFS_ICREATE_ARGS_FORCE_MODE ; } -/* -* 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(). -*/ -static int /* error */ -xfs_droplink ( -xfs_trans_t *tp, -xfs_inode_t *ip) -{ -xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG ); - -drop_nlink (VFS_I (ip)); -xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); - -if (VFS_I (ip)->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) -{ -xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG ); - -inc_nlink (VFS_I (ip)); -xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); -} -#ifdef CONFIG_XFS_LIVE_HOOKS /* * Use a static key here to reduce the overhead of link count live updates. If
fs/xfs/xfs_inode.h +0 -1
@@ -580,7 +580,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_bumplink (struct xfs_trans *tp,struct xfs_inode *ip);void xfs_inode_count_blocks (struct xfs_trans *tp,struct xfs_inode *ip,xfs_filblks_t *dblocks,xfs_filblks_t *rblocks);
PATCH 14/20 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 | 44 ++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 4 ++++ fs/xfs/xfs_inode.c | 17 ++--------------- 3 files changed, 50 insertions(+), 15 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +44 -0
@@ -19,6 +19,8 @@#include "xfs_error.h" #include "xfs_trace.h" #include "xfs_health.h" +#include "xfs_bmap_btree.h" +#include "xfs_trans_space.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)".." ,
@@ -781,3 +783,45 @@ 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_new_child ( +struct xfs_trans *tp, +uint resblks, +struct xfs_inode *dp, +struct xfs_name *name, +struct xfs_inode *ip) +{ +struct xfs_mount *mp = tp->t_mountp; +int error; + +ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +ASSERT (xfs_isilocked (dp,XFS_ILOCK_EXCL )); +ASSERT (resblks ==0 || resblks >XFS_IALLOC_SPACE_RES (mp)); + + error =xfs_dir_createname (tp, dp, name, ip->i_ino, + resblks -XFS_IALLOC_SPACE_RES (mp)); +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)) +return 0 ; + + error =xfs_dir_init (tp, ip, dp); +if (error) +return error; + +xfs_bumplink (tp, dp); +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +4 -0
@@ -253,4 +253,8 @@ unsigned int xfs_dir3_data_end_offset(struct xfs_da_geometry *geo, struct xfs_dir2_data_hdr *hdr);bool xfs_dir2_namecheck (const void *name,size_t length); +int xfs_dir_create_new_child (struct xfs_trans *tp,uint resblks, +struct xfs_inode *dp,struct xfs_name *name, +struct xfs_inode *ip); +#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +2 -15
@@ -868,22 +868,9 @@ xfs_create(xfs_trans_ijoin (tp, dp,XFS_ILOCK_EXCL ); unlock_dp_on_error = false; - error =xfs_dir_createname (tp, dp, name, ip->i_ino, - resblks -XFS_IALLOC_SPACE_RES (mp)); -if (error) { -ASSERT (error != -ENOSPC ); + error =xfs_dir_create_new_child (tp, resblks, dp, name, ip); +if (error) goto out_trans_cancel; - } -xfs_trans_ichgtime (tp, dp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); -xfs_trans_log_inode (tp, dp,XFS_ILOG_CORE ); - -if (is_dir) { - error =xfs_dir_init (tp, ip, dp); -if (error) - goto out_trans_cancel; - -xfs_bumplink (tp, dp); - }/* * Create ip with a reference from dp, and add '.' and '..' references
PATCH 15/20 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 | 51 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 3 +++ fs/xfs/xfs_inode.c | 26 +---------------------- 3 files changed, 55 insertions(+), 25 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +51 -0
@@ -21,6 +21,7 @@#include "xfs_health.h" #include "xfs_bmap_btree.h" #include "xfs_trans_space.h" +#include "xfs_ag.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)".." ,
@@ -825,3 +826,53 @@ xfs_dir_create_new_child(xfs_bumplink (tp, dp);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_link_existing_child ( +struct xfs_trans *tp, +uint resblks, +struct xfs_inode *dp, +struct xfs_name *name, +struct xfs_inode *ip) +{ +struct xfs_mount *mp = tp->t_mountp; +int error; + +ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +ASSERT (xfs_isilocked (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); +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +3 -0
@@ -256,5 +256,8 @@ bool xfs_dir2_namecheck(const void *name, size_t length);int xfs_dir_create_new_child (struct xfs_trans *tp,uint resblks,struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode *ip); +int xfs_dir_link_existing_child (struct xfs_trans *tp,uint resblks, +struct xfs_inode *dp,struct xfs_name *name, +struct xfs_inode *ip);#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +1 -25
@@ -1062,33 +1062,9 @@ xfs_link( goto error_return; } -if (!resblks) { - error =xfs_dir_canenter (tp, tdp, target_name); -if (error) - goto error_return; - } - -/* -* Handle initial link state of O_TMPFILE inode -*/ -if (VFS_I (sip)->i_nlink ==0 ) { -struct xfs_perag *pag; - - pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, sip->i_ino)); - error =xfs_iunlink_remove (tp, pag, sip); -xfs_perag_put (pag); -if (error) - goto error_return; - } - - error =xfs_dir_createname (tp, tdp, target_name, sip->i_ino, - resblks); + error =xfs_dir_link_existing_child (tp, resblks, tdp, target_name, sip);if (error) goto error_return; -xfs_trans_ichgtime (tp, tdp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG ); -xfs_trans_log_inode (tp, tdp,XFS_ILOG_CORE ); - -xfs_bumplink (tp, sip);xfs_nlink_dirent_delta (tdp, sip,1 , target_name);/*
PATCH 16/20 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 | 51 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_util.h | 5 ++++ fs/xfs/xfs_inode.c | 35 +-------------------------- 3 files changed, 57 insertions(+), 34 deletions(-)
fs/xfs/libxfs/xfs_inode_util.c +51 -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(
@@ -645,3 +646,53 @@ xfs_bumplink(inc_nlink (VFS_I (ip));xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); } + +/* Mark an inode free on disk. */ +int +xfs_dir_ifree ( +struct xfs_trans *tp, +struct xfs_perag *pag, +struct xfs_inode *ip, +struct xfs_icluster *xic) +{ +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 ) { +kmem_free (ip->i_df.if_u1.if_data); + ip->i_df.if_u1.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 = ip->i_mount->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);
@@ -56,6 +58,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_dir_ifree (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
@@ -1886,36 +1886,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_dir_ifree (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 ) { -kmem_free (ip->i_df.if_u1.if_data); - ip->i_df.if_u1.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 );
@@ -1924,13 +1898,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:
PATCH 17/20 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 | 73 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 3 ++ fs/xfs/xfs_inode.c | 55 +---------------------------------- 3 files changed, 77 insertions(+), 54 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +73 -0
@@ -876,3 +876,76 @@ xfs_dir_link_existing_child(xfs_bumplink (tp, ip);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, +uint resblks, +struct xfs_inode *dp, +struct xfs_name *name, +struct xfs_inode *ip) +{ +int error; + +ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +ASSERT (xfs_isilocked (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; + } + +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +3 -0
@@ -259,5 +259,8 @@ int xfs_dir_create_new_child(struct xfs_trans *tp, uint resblks,int xfs_dir_link_existing_child (struct xfs_trans *tp,uint resblks,struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode *ip); +int xfs_dir_remove_child (struct xfs_trans *tp,uint resblks, +struct xfs_inode *dp,struct xfs_name *name, +struct xfs_inode *ip);#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +1 -54
64 lines not on this page · raw message
PATCH 18/20 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 | 108 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 4 ++ fs/xfs/xfs_inode.c | 86 +------------------------------------ 3 files changed, 115 insertions(+), 83 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +108 -0
@@ -949,3 +949,111 @@ 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 ( +struct xfs_trans *tp, +struct xfs_inode *dp1, +struct xfs_name *name1, +struct xfs_inode *ip1, +struct xfs_inode *dp2, +struct xfs_name *name2, +struct xfs_inode *ip2, +unsigned int spaceres) +{ +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 ); + +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +4 -0
@@ -262,5 +262,9 @@ int xfs_dir_link_existing_child(struct xfs_trans *tp, uint resblks,int xfs_dir_remove_child (struct xfs_trans *tp,uint resblks,struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode *ip); +int xfs_dir_exchange (struct xfs_trans *tp,struct xfs_inode *dp1, +struct xfs_name *name1,struct xfs_inode *ip1, +struct xfs_inode *dp2,struct xfs_name *name2, +struct xfs_inode *ip2,unsigned int spaceres);#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +3 -83
96 lines not on this page · raw message
PATCH 19/20 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 | 203 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2.h | 5 + fs/xfs/xfs_inode.c | 177 ++-------------------------------------- 3 files changed, 218 insertions(+), 167 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +203 -0
@@ -22,6 +22,7 @@#include "xfs_bmap_btree.h" #include "xfs_trans_space.h" #include "xfs_ag.h" +#include "xfs_ialloc.h" const struct xfs_name xfs_name_dotdot = { .name = (const unsigned char *)".." ,
@@ -1057,3 +1058,205 @@ xfs_dir_exchange(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 ( +struct xfs_trans *tp, +struct xfs_inode *src_dp, +struct xfs_name *src_name, +struct xfs_inode *src_ip, +struct xfs_inode *target_dp, +struct xfs_name *target_name, +struct xfs_inode *target_ip, +unsigned int spaceres, +struct xfs_inode *wip) +{ +struct xfs_mount *mp = tp->t_mountp; +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 (wip) { +struct xfs_perag *pag; + +ASSERT (VFS_I (wip)->i_nlink ==0 ); + + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, wip->i_ino)); + error =xfs_iunlink_remove (tp, pag, wip); +xfs_perag_put (pag); +if (error) +return error; + +xfs_bumplink (tp, wip); + } + +/* +* 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 (wip) + error =xfs_dir_replace (tp, src_dp, src_name, wip->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 ); + +return 0 ; +}
fs/xfs/libxfs/xfs_dir2.h +5 -0
@@ -266,5 +266,10 @@ int xfs_dir_exchange(struct xfs_trans *tp, struct xfs_inode *dp1, struct xfs_name *name1, struct xfs_inode *ip1, struct xfs_inode *dp2, struct xfs_name *name2, struct xfs_inode *ip2, unsigned int spaceres); +int xfs_dir_rename (struct xfs_trans *tp,struct xfs_inode *src_dp, +struct xfs_name *src_name,struct xfs_inode *src_ip, +struct xfs_inode *target_dp,struct xfs_name *target_name, +struct xfs_inode *target_ip,unsigned int spaceres, +struct xfs_inode *wip);#endif /* __XFS_DIR2_H__ */
fs/xfs/xfs_inode.c +10 -167
193 lines not on this page · raw message
PATCH 20/20 xfs: get rid of cross_rename
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Get rid of the largely pointless xfs_cross_rename now that we've refactored its parent.
--- fs/xfs/xfs_inode.c | 72 +++++++++++----------------------------------------- 1 file changed, 15 insertions(+), 57 deletions(-)
fs/xfs/xfs_inode.c +15 -57
@@ -2177,54 +2177,6 @@ xfs_rename_call_nlink_hooks( ((void)0)#endif /* CONFIG_XFS_LIVE_HOOKS */ -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_inode *dp2, -struct xfs_name *name2, -struct xfs_inode *ip2, -int spaceres) -{ -int error; - - error =xfs_dir_exchange (tp, dp1, name1, ip1, dp2, name2, ip2, - spaceres); -if (error) - goto out_trans_abort; - -if (xfs_hooks_switched_on (&xfs_nlinks_hooks_switch)) -xfs_rename_call_nlink_hooks (dp1, name1, ip1, dp2, name2, ip2, -NULL ,RENAME_EXCHANGE ); - -return xfs_finish_rename (tp); - -out_trans_abort: -xfs_trans_cancel (tp); -return error; -} -/* * xfs_rename_alloc_whiteout() *
@@ -2377,12 +2329,6 @@ xfs_rename( goto out_trans_cancel; } -/* RENAME_EXCHANGE is unique from here on. */ -if (flags &RENAME_EXCHANGE ) -return xfs_cross_rename (tp, src_dp, src_name, src_ip, - target_dp, target_name, target_ip, - spaceres); -/* * Try to reserve quota to handle an expansion of the target directory. * We'll allow the rename to continue in reservationless mode if we hit
@@ -2434,8 +2380,13 @@ xfs_rename( } } - error =xfs_dir_rename (tp, src_dp, src_name, src_ip, target_dp, - target_name, target_ip, spaceres, wip); +if (flags &RENAME_EXCHANGE ) + error =xfs_dir_exchange (tp, src_dp, src_name, src_ip, + target_dp, target_name, target_ip, spaceres); +else + error =xfs_dir_rename (tp, src_dp, src_name, src_ip, + target_dp, target_name, target_ip, spaceres, + wip);if (error) goto out_trans_cancel;
@@ -2452,7 +2403,14 @@ xfs_rename(xfs_rename_call_nlink_hooks (src_dp, src_name, src_ip, target_dp, target_name, target_ip, wip, flags); - error =xfs_finish_rename (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); + + error =xfs_trans_commit (tp);if (wip)xfs_irele (wip);return error;
cover xfs: metadata inode directories
In reply to Darrick J. WongHi all,
This series delivers a new feature -- metadata inode directories. This is a separate directory tree (rooted in the superblock) that contains only inodes that contain filesystem metadata. Different metadata objects can be looked up with regular paths.
We start by creating xfs_imeta_* functions to mediate access to metadata inode pointers. This enables the imeta code to abstract inode pointers, whether they're the classic five in the superblock, or the much more complex directory tree. All current users of metadata inodes (rt+quota) are converted to use the boilerplate code.
Next, we define the metadir on-disk format, which consists of marking inodes with a new iflag that says they're metadata. This we use to prevent bulkstat and friends from ever getting their hands on fs metadata.
Finally, we implement metadir operations so that clients can create, delete, zap, and look up metadata inodes by path. Beware that much of this code is only lightly used, because the five current users of metadata inodes don't tend to change them very often. This is likely to change if and when the subvolume and multiple-rt-volume features get written/merged/etc.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. 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=metadir
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=metadir
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=metadir
xfsdocs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-documentation.git/log/?h=metadir
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_format.h | 60 ++ fs/xfs/libxfs/xfs_fs.h | 12 fs/xfs/libxfs/xfs_health.h | 4 fs/xfs/libxfs/xfs_ialloc.c | 16 - fs/xfs/libxfs/xfs_ialloc.h | 2 fs/xfs/libxfs/xfs_imeta.c | 1210 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_imeta.h | 94 +++ fs/xfs/libxfs/xfs_inode_buf.c | 73 ++ fs/xfs/libxfs/xfs_inode_buf.h | 3 fs/xfs/libxfs/xfs_inode_util.c | 4 fs/xfs/libxfs/xfs_log_rlimit.c | 9 fs/xfs/libxfs/xfs_sb.c | 35 + fs/xfs/libxfs/xfs_trans_resv.c | 74 ++ fs/xfs/libxfs/xfs_trans_resv.h | 2 fs/xfs/libxfs/xfs_types.c | 7 fs/xfs/scrub/agheader.c | 29 + fs/xfs/scrub/common.c | 7 fs/xfs/scrub/dir.c | 9 fs/xfs/scrub/dir_repair.c | 6 fs/xfs/scrub/inode_repair.c | 10 fs/xfs/scrub/nlinks.c | 12 fs/xfs/scrub/nlinks_repair.c | 2 fs/xfs/scrub/parent.c | 18 + fs/xfs/scrub/parent_repair.c | 37 + fs/xfs/scrub/tempfile.c | 10 fs/xfs/xfs_health.c | 1 fs/xfs/xfs_icache.c | 39 + fs/xfs/xfs_inode.c | 131 ++++ fs/xfs/xfs_inode.h | 11 fs/xfs/xfs_ioctl.c | 7 fs/xfs/xfs_iops.c | 34 + fs/xfs/xfs_itable.c | 32 + fs/xfs/xfs_itable.h | 3 fs/xfs/xfs_mount.c | 39 + fs/xfs/xfs_mount.h | 3 fs/xfs/xfs_ondisk.h | 1 fs/xfs/xfs_qm.c | 212 +++++-- fs/xfs/xfs_qm_syscalls.c | 4 fs/xfs/xfs_rtalloc.c | 16 - fs/xfs/xfs_super.c | 4 fs/xfs/xfs_symlink.c | 2 fs/xfs/xfs_trace.h | 78 +++ 43 files changed, 2223 insertions(+), 140 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_imeta.c create mode 100644 fs/xfs/libxfs/xfs_imeta.h
PATCH 1/23 xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb
From: 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/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/xfs_ondisk.h +1 -0
@@ -81,6 +81,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 );
PATCH 2/23 xfs: create imeta abstractions to get and set metadata inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create some helper routines to get and set metadata inode numbers instead of open-coding them throughout xfs.
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_imeta.c | 438 +++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_imeta.h | 48 +++++ fs/xfs/libxfs/xfs_types.c | 5 - fs/xfs/xfs_mount.c | 21 ++ fs/xfs/xfs_trace.h | 37 ++++ 6 files changed, 546 insertions(+), 4 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_imeta.c create mode 100644 fs/xfs/libxfs/xfs_imeta.h
fs/xfs/Makefile +1 -0
@@ -37,6 +37,7 @@ xfs-y += $(addprefix libxfs/, \ xfs_ialloc.o \ xfs_ialloc_btree.o \ xfs_iext_tree.o \ + xfs_imeta.o \ xfs_inode_fork.o \ xfs_inode_buf.o \ xfs_inode_util.o \
fs/xfs/libxfs/xfs_imeta.c new file +438 -0
438 lines not on this page · raw message
fs/xfs/libxfs/xfs_imeta.h new file +48 -0
48 lines not on this page · raw message
fs/xfs/libxfs/xfs_types.c +2 -3
@@ -12,6 +12,7 @@#include "xfs_bit.h" #include "xfs_mount.h" #include "xfs_ag.h" +#include "xfs_imeta.h" /*
@@ -115,9 +116,7 @@ xfs_internal_inum( struct xfs_mount *mp, xfs_ino_t ino) { -return ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino || - (xfs_has_quota (mp) && -xfs_is_quota_inode (&mp->m_sb, ino)); +return xfs_is_static_meta_ino (mp, ino); }/*
fs/xfs/xfs_mount.c +21 -0
@@ -34,6 +34,7 @@#include "xfs_health.h" #include "xfs_trace.h" #include "xfs_ag.h" +#include "xfs_imeta.h" static DEFINE_MUTEX (xfs_uuid_table_mutex);static int xfs_uuid_table_size;
@@ -609,6 +610,22 @@ xfs_mount_setup_inode_geom(xfs_ialloc_setup_geometry (mp); } +STATIC int +xfs_mount_setup_metadir ( +struct xfs_mount *mp) +{ +int error; + + error =xfs_imeta_mount (mp); +if (error) { +xfs_warn (mp,"Failed to load metadata inode info, error %d" , + error); +return error; + } + +return 0 ; +} +/* Compute maximum possible height for per-AG btree types for this fs. */ static inline void xfs_agbtree_compute_maxlevels(
@@ -843,6 +860,10 @@ xfs_mountfs( mp->m_features |=XFS_FEAT_ATTR2 ; } + error =xfs_mount_setup_metadir (mp); +if (error) + goto out_log_dealloc; +/* * Get and sanity-check the root inode. * Save the pointer to it in the mount structure.
fs/xfs/xfs_trace.h +36 -1
@@ -148,7 +148,7 @@ DEFINE_ATTR_LIST_EVENT(xfs_attr_list_notfound);DEFINE_ATTR_LIST_EVENT (xfs_attr_leaf_list);DEFINE_ATTR_LIST_EVENT (xfs_attr_node_list); -TRACE_EVENT(xlog_intent_recovery_failed, +DECLARE_EVENT_CLASS(xfs_fs_error_class, TP_PROTO(struct xfs_mount *mp, int error, void *function), TP_ARGS(mp, error, function), TP_STRUCT__entry(
@@ -165,6 +165,11 @@ TRACE_EVENT(xlog_intent_recovery_failed,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->error, __entry->function) ); +#define DEFINE_FS_ERROR_EVENT (name) \ +DEFINE_EVENT(xfs_fs_error_class, name, \ + TP_PROTO(struct xfs_mount *mp, int error, void *function), \ + TP_ARGS(mp, error, function)) +DEFINE_FS_ERROR_EVENT (xlog_intent_recovery_failed); DECLARE_EVENT_CLASS(xfs_perag_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, int refcount,
@@ -4917,6 +4922,36 @@ TRACE_EVENT(xfs_swapext_delta_nextents, __entry->d_nexts1, __entry->d_nexts2) ); +DECLARE_EVENT_CLASS (xfs_imeta_sb_class, + TP_PROTO(struct xfs_mount *mp, xfs_ino_t *sb_inop), +TP_ARGS (mp, sb_inop), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(unsigned int, sb_offset) +__field (xfs_ino_t, ino) + ), +TP_fast_assign ( + __entry->dev = mp->m_super->s_dev; + __entry->sb_offset = (char *)sb_inop - (char *)&mp->m_sb; + __entry->ino = *sb_inop; + ), +TP_printk ("dev %d:%d sb_offset 0x%x ino 0x%llx" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->sb_offset, + __entry->ino) +) + +#define DEFINE_IMETA_SB_EVENT (name) \ +DEFINE_EVENT(xfs_imeta_sb_class, name, \ + TP_PROTO(struct xfs_mount *mp, xfs_ino_t *sb_inop), \ + TP_ARGS(mp, sb_inop)) +DEFINE_IMETA_SB_EVENT (xfs_imeta_sb_lookup); +DEFINE_IMETA_SB_EVENT (xfs_imeta_sb_create); +DEFINE_IMETA_SB_EVENT (xfs_imeta_sb_unlink); +DEFINE_IMETA_SB_EVENT (xfs_imeta_sb_link); +DEFINE_FS_ERROR_EVENT (xfs_imeta_start_update); +DEFINE_FS_ERROR_EVENT (xfs_imeta_end_update); +#endif /* _TRACE_XFS_H */ #undef TRACE_INCLUDE_PATH
PATCH 3/23 xfs: create transaction reservations for metadata inode operations
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create transaction reservation types and block reservation helpers to help us calculate transaction requirements. Right now the reservations are the same as always; we're just separating the symbols for a future patch.
--- fs/xfs/libxfs/xfs_imeta.c | 20 ++++++++++++++++++++ fs/xfs/libxfs/xfs_imeta.h | 3 +++ fs/xfs/libxfs/xfs_trans_resv.c | 4 ++++ fs/xfs/libxfs/xfs_trans_resv.h | 2 ++ 4 files changed, 29 insertions(+)
fs/xfs/libxfs/xfs_imeta.c +20 -0
@@ -19,6 +19,10 @@#include "xfs_inode.h" #include "xfs_quota.h" #include "xfs_ialloc.h" +#include "xfs_bmap_btree.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" +#include "xfs_trans_space.h" /* * Metadata Inode Number Management
@@ -436,3 +440,19 @@ xfs_imeta_mount( {return 0 ; } + +/* Calculate the log block reservation to create a metadata inode. */ +unsigned int +xfs_imeta_create_space_res ( +struct xfs_mount *mp) +{ +return XFS_IALLOC_SPACE_RES (mp); +} + +/* Calculate the log block reservation to unlink a metadata inode. */ +unsigned int +xfs_imeta_unlink_space_res ( +struct xfs_mount *mp) +{ +return XFS_REMOVE_SPACE_RES (mp); +}
fs/xfs/libxfs/xfs_imeta.h +3 -0
@@ -45,4 +45,7 @@ int xfs_imeta_start_update(struct xfs_mount *mp,bool xfs_is_static_meta_ino (struct xfs_mount *mp,xfs_ino_t ino);int xfs_imeta_mount (struct xfs_mount *mp); +unsigned int xfs_imeta_create_space_res (struct xfs_mount *mp); +unsigned int xfs_imeta_unlink_space_res (struct xfs_mount *mp); +#endif /* __XFS_IMETA_H__ */
fs/xfs/libxfs/xfs_trans_resv.c +4 -0
@@ -1025,4 +1025,8 @@ xfs_trans_resv_calc( resp->tr_itruncate.tr_logcount += logcount_adj; resp->tr_write.tr_logcount += logcount_adj; resp->tr_qm_dqalloc.tr_logcount += logcount_adj; + +/* metadata inode creation and unlink */ + resp->tr_imeta_create = resp->tr_create; + resp->tr_imeta_unlink = resp->tr_remove; }
fs/xfs/libxfs/xfs_trans_resv.h +2 -0
@@ -48,6 +48,8 @@ struct xfs_trans_resv {struct xfs_trans_res tr_qm_dqalloc;/* allocate quota on disk */ struct xfs_trans_res tr_sb;/* modify superblock */ struct xfs_trans_res tr_fsyncts;/* update timestamps on fsync */ +struct xfs_trans_res tr_imeta_create;/* create metadata inode */ +struct xfs_trans_res tr_imeta_unlink;/* unlink metadata inode */ };/* shorthand way of accessing reservation structure */
PATCH 4/23 xfs: refactor the v4 group/project inode pointer switch
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Refactor the group and project quota inode pointer switcheroo that happens only on v4 filesystems into a separate function prior to enhancing the xfs_qm_qino_alloc function.
--- fs/xfs/xfs_qm.c | 90 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 36 deletions(-)
fs/xfs/xfs_qm.c +54 -36
@@ -731,6 +731,57 @@ xfs_qm_destroy_quotainfo( mp->m_quotainfo =NULL ; } +/* +* Switch the group and project quota in-core inode pointers if needed. +* +* On v4 superblocks that don't have separate pquotino, we share an inode +* between gquota and pquota. If the on-disk superblock has GQUOTA and the +* filesystem is now mounted with PQUOTA, just use sb_gquotino for sb_pquotino +* and vice-versa. +*/ +STATIC int +xfs_qm_qino_switch ( +struct xfs_mount *mp, +struct xfs_inode **ipp, +unsigned int flags, +bool *need_alloc) +{ +xfs_ino_t ino =NULLFSINO ; +int error; + +if (xfs_has_pquotino (mp) || + !(flags & (XFS_QMOPT_PQUOTA |XFS_QMOPT_GQUOTA ))) +return 0 ; + +if ((flags &XFS_QMOPT_PQUOTA ) && + (mp->m_sb.sb_gquotino !=NULLFSINO )) { + ino = mp->m_sb.sb_gquotino; +if (XFS_IS_CORRUPT (mp, mp->m_sb.sb_pquotino !=NULLFSINO )) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_PQUOTA ); +return -EFSCORRUPTED ; + } + }else if ((flags &XFS_QMOPT_GQUOTA ) && + (mp->m_sb.sb_pquotino !=NULLFSINO )) { + ino = mp->m_sb.sb_pquotino; +if (XFS_IS_CORRUPT (mp, mp->m_sb.sb_gquotino !=NULLFSINO )) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_GQUOTA ); +return -EFSCORRUPTED ; + } + } + +if (ino ==NULLFSINO ) +return 0 ; + + error =xfs_iget (mp,NULL , ino,0 ,0 , ipp); +if (error) +return error; + + mp->m_sb.sb_gquotino =NULLFSINO ; + mp->m_sb.sb_pquotino =NULLFSINO ; + *need_alloc = false; +return 0 ; +} +/* * Create an inode and return with a reference already taken, but unlocked * This is how we create quota inodes
@@ -746,43 +797,10 @@ xfs_qm_qino_alloc(bool need_alloc = true; *ipp =NULL ; -/* -* With superblock that doesn't have separate pquotino, we -* share an inode between gquota and pquota. If the on-disk -* superblock has GQUOTA and the filesystem is now mounted -* with PQUOTA, just use sb_gquotino for sb_pquotino and -* vice-versa. -*/ -if (!xfs_has_pquotino (mp) && - (flags & (XFS_QMOPT_PQUOTA |XFS_QMOPT_GQUOTA ))) { -xfs_ino_t ino =NULLFSINO ; -if ((flags &XFS_QMOPT_PQUOTA ) && - (mp->m_sb.sb_gquotino !=NULLFSINO )) { - ino = mp->m_sb.sb_gquotino; -if (XFS_IS_CORRUPT (mp, - mp->m_sb.sb_pquotino !=NULLFSINO )) { -xfs_fs_mark_sick (mp,XFS_SICK_FS_PQUOTA ); -return -EFSCORRUPTED ; - } - }else if ((flags &XFS_QMOPT_GQUOTA ) && - (mp->m_sb.sb_pquotino !=NULLFSINO )) { - ino = mp->m_sb.sb_pquotino; -if (XFS_IS_CORRUPT (mp, - mp->m_sb.sb_gquotino !=NULLFSINO )) { -xfs_fs_mark_sick (mp,XFS_SICK_FS_GQUOTA ); -return -EFSCORRUPTED ; - } - } -if (ino !=NULLFSINO ) { - error =xfs_iget (mp,NULL , ino,0 ,0 , ipp); -if (error) -return error; - mp->m_sb.sb_gquotino =NULLFSINO ; - mp->m_sb.sb_pquotino =NULLFSINO ; - need_alloc = false; - } - } + error =xfs_qm_qino_switch (mp, ipp, flags, &need_alloc); +if (error) +return error; error = xfs_trans_alloc(mp, &M_RES(mp)->tr_create, need_alloc ? XFS_QM_QINOCREATE_SPACE_RES(mp) : 0,
PATCH 5/23 xfs: convert all users to xfs_imeta_log
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Convert all open-coded sb metadata inode pointer logging to use xfs_imeta_log.
--- fs/xfs/xfs_qm.c | 85 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 28 deletions(-)
fs/xfs/xfs_qm.c +57 -28
@@ -27,6 +27,7 @@#include "xfs_ialloc.h" #include "xfs_log_priv.h" #include "xfs_health.h" +#include "xfs_imeta.h" /* * The global quota manager. There is only one of these for the entire
@@ -731,6 +732,18 @@ xfs_qm_destroy_quotainfo( mp->m_quotainfo =NULL ; } +static inline const struct xfs_imeta_path * +xfs_qflags_to_imeta ( +unsigned int qflags) +{ +if (qflags &XFS_QMOPT_UQUOTA ) +return &XFS_IMETA_USRQUOTA ; +else if (qflags &XFS_QMOPT_GQUOTA ) +return &XFS_IMETA_GRPQUOTA ; +else +return &XFS_IMETA_PRJQUOTA ; +} +/* * Switch the group and project quota in-core inode pointers if needed. *
@@ -738,6 +751,12 @@ xfs_qm_destroy_quotainfo(* between gquota and pquota. If the on-disk superblock has GQUOTA and the * filesystem is now mounted with PQUOTA, just use sb_gquotino for sb_pquotino * and vice-versa. +* +* We tolerate the direct manipulation of the in-core sb quota inode pointers +* here because calling xfs_imeta_log is only really required for filesystems +* with the metadata directory feature. That feature requires a v5 superblock, +* which always supports simultaneous group and project quotas, so we'll never +* get here. */ STATIC int xfs_qm_qino_switch(
@@ -776,8 +795,13 @@ xfs_qm_qino_switch(if (error)return error; - mp->m_sb.sb_gquotino =NULLFSINO ; - mp->m_sb.sb_pquotino =NULLFSINO ; +if (flags &XFS_QMOPT_PQUOTA ) { + mp->m_sb.sb_gquotino =NULLFSINO ; + mp->m_sb.sb_pquotino = ino; + }else if (flags &XFS_QMOPT_GQUOTA ) { + mp->m_sb.sb_gquotino = ino; + mp->m_sb.sb_pquotino =NULLFSINO ; + } *need_alloc = false;return 0 ; }
@@ -792,7 +816,9 @@ xfs_qm_qino_alloc( struct xfs_inode **ipp, unsigned int flags) { +struct xfs_imeta_update upd;struct xfs_trans *tp; +const struct xfs_imeta_path *path =xfs_qflags_to_imeta (flags);int error;bool need_alloc = true;
@@ -802,28 +828,15 @@ xfs_qm_qino_alloc(if (error)return error; - error =xfs_trans_alloc (mp, &M_RES (mp)->tr_create, - need_alloc ?XFS_QM_QINOCREATE_SPACE_RES (mp) :0 , + error =xfs_imeta_start_update (mp, path, &upd); +if (error) +return error; + + error =xfs_trans_alloc (mp, &M_RES (mp)->tr_imeta_create, + need_alloc ?xfs_imeta_create_space_res (mp) :0 ,0 ,0 , &tp);if (error) -return error; - -if (need_alloc) { -struct xfs_icreate_args args = { - .nlink =1 , - }; -xfs_ino_t ino; - -xfs_icreate_args_rootfile (&args,S_IFREG ); - - error =xfs_dialloc (&tp,0 ,S_IFREG , &ino); -if (!error) - error =xfs_icreate (tp, ino, &args, ipp); -if (error) { -xfs_trans_cancel (tp); -return error; - } - } + goto out_end;/* * Make the changes in the superblock, and log those too.
@@ -842,22 +855,38 @@ xfs_qm_qino_alloc(/* qflags will get updated fully _after_ quotacheck */ mp->m_sb.sb_qflags = mp->m_qflags &XFS_ALL_QUOTA_ACCT ; } -if (flags &XFS_QMOPT_UQUOTA ) - mp->m_sb.sb_uquotino = (*ipp)->i_ino; -else if (flags &XFS_QMOPT_GQUOTA ) - mp->m_sb.sb_gquotino = (*ipp)->i_ino; -else - mp->m_sb.sb_pquotino = (*ipp)->i_ino;spin_unlock (&mp->m_sb_lock);xfs_log_sb (tp); +if (need_alloc) { + error =xfs_imeta_create (&tp, path,S_IFREG , +XFS_IMETA_CREATE_NOQUOTA , ipp, &upd); +if (error) + goto out_cancel; + } + error =xfs_trans_commit (tp);if (error) {ASSERT (xfs_is_shutdown (mp));xfs_alert (mp,"%s failed (error %d)!" , __func__, error); + goto out_end; } + +xfs_imeta_end_update (mp, &upd, error);if (need_alloc)xfs_finish_inode_setup (*ipp); +return 0 ; + +out_cancel: +xfs_trans_cancel (tp); +out_end: +/* Have to finish setting up the inode to ensure it's deleted. */ +if (*ipp) { +xfs_finish_inode_setup (*ipp); +xfs_irele (*ipp); + *ipp =NULL ; + } +xfs_imeta_end_update (mp, &upd, error);return error; }
PATCH 6/23 xfs: iget for metadata inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a xfs_iget_meta function for metadata inodes to ensure that we always check that the inobt thinks a metadata inode is in use.
--- fs/xfs/libxfs/xfs_imeta.h | 5 +++++ fs/xfs/xfs_icache.c | 36 ++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_inode.c | 8 ++++++++ fs/xfs/xfs_qm.c | 33 +++++++++++++++++---------------- fs/xfs/xfs_qm_syscalls.c | 4 +++- fs/xfs/xfs_rtalloc.c | 16 ++++++++++------ 6 files changed, 79 insertions(+), 23 deletions(-)
fs/xfs/libxfs/xfs_imeta.h +5 -0
@@ -48,4 +48,9 @@ int xfs_imeta_mount(struct xfs_mount *mp);unsigned int xfs_imeta_create_space_res (struct xfs_mount *mp);unsigned int xfs_imeta_unlink_space_res (struct xfs_mount *mp); +/* Must be implemented by the libxfs client */ +int xfs_imeta_iget (struct xfs_mount *mp,xfs_ino_t ino,unsigned char ftype, +struct xfs_inode **ipp); +void xfs_imeta_irele (struct xfs_inode *ip); +#endif /* __XFS_IMETA_H__ */
fs/xfs/xfs_icache.c +36 -0
@@ -25,6 +25,9 @@#include "xfs_ag.h" #include "xfs_log_priv.h" #include "xfs_health.h" +#include "xfs_da_format.h" +#include "xfs_dir2.h" +#include "xfs_imeta.h" #include <linux/iversion.h>
@@ -905,6 +908,39 @@ xfs_icache_inode_is_allocated(return error; } +/* Get a metadata inode. The ftype must match exactly. */ +int +xfs_imeta_iget ( +struct xfs_mount *mp, +xfs_ino_t ino, +unsigned char ftype, +struct xfs_inode **ipp) +{ +struct xfs_inode *ip; +int error; + +ASSERT (ftype !=XFS_DIR3_FT_UNKNOWN ); + + error =xfs_iget (mp,NULL , ino,XFS_IGET_UNTRUSTED ,0 , &ip); +if (error == -EFSCORRUPTED ) + goto whine; +if (error) +return error; + +if (VFS_I (ip)->i_nlink ==0 ) + goto bad_rele; +if (xfs_mode_to_ftype (VFS_I (ip)->i_mode) != ftype) + goto bad_rele; + + *ipp = ip; +return 0 ; +bad_rele: +xfs_irele (ip); +whine: +xfs_err (mp,"metadata inode 0x%llx is corrupt" , ino); +return -EFSCORRUPTED ; +} +/* * Grab the inode for reclaim exclusively. *
fs/xfs/xfs_inode.c +8 -0
@@ -40,6 +40,7 @@#include "xfs_log_priv.h" #include "xfs_health.h" #include "xfs_inode_util.h" +#include "xfs_imeta.h" struct kmem_cache *xfs_inode_cache;
@@ -2709,6 +2710,13 @@ xfs_irele(iput (VFS_I (ip)); } +void +xfs_imeta_irele ( +struct xfs_inode *ip) +{ +xfs_irele (ip); +} +/* * Ensure all commited transactions touching the inode are written to the log. */
fs/xfs/xfs_qm.c +17 -16
@@ -28,6 +28,7 @@#include "xfs_log_priv.h" #include "xfs_health.h" #include "xfs_imeta.h" +#include "xfs_da_format.h" /* * The global quota manager. There is only one of these for the entire
@@ -232,15 +233,15 @@ xfs_qm_unmount_quotas(*/ if (mp->m_quotainfo) {if (mp->m_quotainfo->qi_uquotaip) { -xfs_irele (mp->m_quotainfo->qi_uquotaip); +xfs_imeta_irele (mp->m_quotainfo->qi_uquotaip); mp->m_quotainfo->qi_uquotaip =NULL ; }if (mp->m_quotainfo->qi_gquotaip) { -xfs_irele (mp->m_quotainfo->qi_gquotaip); +xfs_imeta_irele (mp->m_quotainfo->qi_gquotaip); mp->m_quotainfo->qi_gquotaip =NULL ; }if (mp->m_quotainfo->qi_pquotaip) { -xfs_irele (mp->m_quotainfo->qi_pquotaip); +xfs_imeta_irele (mp->m_quotainfo->qi_pquotaip); mp->m_quotainfo->qi_pquotaip =NULL ; } }
@@ -791,7 +792,7 @@ xfs_qm_qino_switch(if (ino ==NULLFSINO )return 0 ; - error =xfs_iget (mp,NULL , ino,0 ,0 , ipp); + error =xfs_imeta_iget (mp, ino,XFS_DIR3_FT_REG_FILE , ipp);if (error)return error;
@@ -1576,24 +1577,24 @@ xfs_qm_init_quotainos(if (XFS_IS_UQUOTA_ON (mp) && mp->m_sb.sb_uquotino !=NULLFSINO ) {ASSERT (mp->m_sb.sb_uquotino >0 ); - error =xfs_iget (mp,NULL , mp->m_sb.sb_uquotino, -0 ,0 , &uip); + error =xfs_imeta_iget (mp, mp->m_sb.sb_uquotino, +XFS_DIR3_FT_REG_FILE , &uip);if (error)return error; }if (XFS_IS_GQUOTA_ON (mp) && mp->m_sb.sb_gquotino !=NULLFSINO ) {ASSERT (mp->m_sb.sb_gquotino >0 ); - error =xfs_iget (mp,NULL , mp->m_sb.sb_gquotino, -0 ,0 , &gip); + error =xfs_imeta_iget (mp, mp->m_sb.sb_gquotino, +XFS_DIR3_FT_REG_FILE , &gip);if (error) goto error_rele; }if (XFS_IS_PQUOTA_ON (mp) && mp->m_sb.sb_pquotino !=NULLFSINO ) {ASSERT (mp->m_sb.sb_pquotino >0 ); - error =xfs_iget (mp,NULL , mp->m_sb.sb_pquotino, -0 ,0 , &pip); + error =xfs_imeta_iget (mp, mp->m_sb.sb_pquotino, +XFS_DIR3_FT_REG_FILE , &pip);if (error) goto error_rele; }
@@ -1638,11 +1639,11 @@ xfs_qm_init_quotainos( error_rele:if (uip) -xfs_irele (uip); +xfs_imeta_irele (uip);if (gip) -xfs_irele (gip); +xfs_imeta_irele (gip);if (pip) -xfs_irele (pip); +xfs_imeta_irele (pip);return error; }
@@ -1651,15 +1652,15 @@ xfs_qm_destroy_quotainos( struct xfs_quotainfo *qi) {if (qi->qi_uquotaip) { -xfs_irele (qi->qi_uquotaip); +xfs_imeta_irele (qi->qi_uquotaip); qi->qi_uquotaip =NULL ;/* paranoia */ }if (qi->qi_gquotaip) { -xfs_irele (qi->qi_gquotaip); +xfs_imeta_irele (qi->qi_gquotaip); qi->qi_gquotaip =NULL ; }if (qi->qi_pquotaip) { -xfs_irele (qi->qi_pquotaip); +xfs_imeta_irele (qi->qi_pquotaip); qi->qi_pquotaip =NULL ; } }
fs/xfs/xfs_qm_syscalls.c +3 -1
@@ -18,6 +18,8 @@#include "xfs_quota.h" #include "xfs_qm.h" #include "xfs_icache.h" +#include "xfs_imeta.h" +#include "xfs_da_format.h" int xfs_qm_scall_quotaoff(
@@ -62,7 +64,7 @@ xfs_qm_scall_trunc_qfile(if (ino ==NULLFSINO )return 0 ; - error =xfs_iget (mp,NULL , ino,0 ,0 , &ip); + error =xfs_imeta_iget (mp, ino,XFS_DIR3_FT_REG_FILE , &ip);if (error)return error;
fs/xfs/xfs_rtalloc.c +10 -6
@@ -22,6 +22,8 @@#include "xfs_log_priv.h" #include "xfs_health.h" #include "xfs_trace.h" +#include "xfs_da_format.h" +#include "xfs_imeta.h" /* * Read and return the summary information for a given extent size,
@@ -1375,7 +1377,8 @@ xfs_rtmount_inodes(xfs_sb_t *sbp; sbp = &mp->m_sb; - error =xfs_iget (mp,NULL , sbp->sb_rbmino,0 ,0 , &mp->m_rbmip); + error =xfs_imeta_iget (mp, mp->m_sb.sb_rbmino,XFS_DIR3_FT_REG_FILE , + &mp->m_rbmip);if (xfs_metadata_is_sick (error))xfs_rt_mark_sick (mp,XFS_SICK_RT_BITMAP );if (error)
@@ -1386,7 +1389,8 @@ xfs_rtmount_inodes(if (error) goto out_rele_bitmap; - error =xfs_iget (mp,NULL , sbp->sb_rsumino,0 ,0 , &mp->m_rsumip); + error =xfs_imeta_iget (mp, mp->m_sb.sb_rsumino,XFS_DIR3_FT_REG_FILE , + &mp->m_rsumip);if (xfs_metadata_is_sick (error))xfs_rt_mark_sick (mp,XFS_SICK_RT_SUMMARY );if (error)
@@ -1401,9 +1405,9 @@ xfs_rtmount_inodes(return 0 ; out_rele_summary: -xfs_irele (mp->m_rsumip); +xfs_imeta_irele (mp->m_rsumip); out_rele_bitmap: -xfs_irele (mp->m_rbmip); +xfs_imeta_irele (mp->m_rbmip);return error; }
@@ -1413,9 +1417,9 @@ xfs_rtunmount_inodes( {kmem_free (mp->m_rsum_cache);if (mp->m_rbmip) -xfs_irele (mp->m_rbmip); +xfs_imeta_irele (mp->m_rbmip);if (mp->m_rsumip) -xfs_irele (mp->m_rsumip); +xfs_imeta_irele (mp->m_rsumip); }/*
PATCH 7/23 xfs: define the on-disk format for the metadir feature
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Define the on-disk layout and feature flags for the metadata inode directory feature.
--- fs/xfs/libxfs/xfs_format.h | 48 ++++++++++++++++++++++++++++++++++++++-- fs/xfs/libxfs/xfs_inode_util.c | 2 ++ fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/xfs_inode.h | 7 ++++++ fs/xfs/xfs_mount.h | 2 ++ fs/xfs/xfs_super.c | 4 +++ 6 files changed, 63 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_format.h +46 -2
@@ -174,6 +174,16 @@ typedef struct xfs_sb {xfs_lsn_t sb_lsn;/* last write sequence */ uuid_t sb_meta_uuid;/* metadata file system unique id */ +/* Fields beyond here do not match xfs_dsb. Be very careful! */ + +/* +* Metadata Directory Inode. On disk this lives in the sb_rbmino slot, +* but we continue to use the in-core superblock to cache the classic +* inodes (rt bitmap; rt summary; user, group, and project quotas) so +* we cache the metadir inode value here too. +*/ +xfs_ino_t sb_metadirino; +/* must be padded to 64 bit alignment */ } xfs_sb_t;
@@ -190,7 +200,14 @@ struct xfs_dsb {uuid_t sb_uuid;/* user-visible file system unique id */ __be64 sb_logstart;/* starting block of log if internal */ __be64 sb_rootino;/* root inode number */ -__be64 sb_rbmino;/* bitmap inode for realtime extents */ +/* +* bitmap inode for realtime extents. +* +* The metadata directory feature uses the sb_rbmino field to point to +* the root of the metadata directory tree. All other sb inode +* pointers are no longer used. +*/ +__be64 sb_rbmino;__be64 sb_rsumino;/* summary inode for rt bitmap */ __be32 sb_rextsize;/* realtime extent size, blocks */ __be32 sb_agblocks;/* size of an allocation group */
@@ -372,6 +389,7 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3)/* large timestamps */ #define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4)/* needs xfs_repair */ #define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5)/* large extent counters */ +#define XFS_SB_FEAT_INCOMPAT_METADIR (1U << 31)/* metadata dir tree */ #define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ XFS_SB_FEAT_INCOMPAT_SPINODES| \
@@ -1078,6 +1096,7 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)#define XFS_DIFLAG2_COWEXTSIZE_BIT 2/* copy on write extent size hint */ #define XFS_DIFLAG2_BIGTIME_BIT 3/* big timestamps */ #define XFS_DIFLAG2_NREXT64_BIT 4/* large extent counters */ +#define XFS_DIFLAG2_METADATA_BIT 63/* filesystem metadata */ #define XFS_DIFLAG2_DAX (1 << XFS_DIFLAG2_DAX_BIT)#define XFS_DIFLAG2_REFLINK (1 << XFS_DIFLAG2_REFLINK_BIT)
@@ -1085,9 +1104,34 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)#define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT)#define XFS_DIFLAG2_NREXT64 (1 << XFS_DIFLAG2_NREXT64_BIT) +/* +* The inode contains filesystem metadata and can be found through the metadata +* directory tree. Metadata inodes must satisfy the following constraints: +* +* - V5 filesystem (and ftype) are enabled; +* - The only valid modes are regular files and directories; +* - The access bits must be zero; +* - DMAPI event and state masks are zero; +* - The user, group, and project IDs must be zero; +* - The immutable, sync, noatime, nodump, nodefrag flags must be set. +* - The dax flag must not be set. +* - Directories must have nosymlinks set. +* +* These requirements are chosen defensively to minimize the ability of +* userspace to read or modify the contents, should a metadata file ever +* escape to userspace. +* +* There are further constraints on the directory tree itself: +* +* - Metadata inodes must never be resolvable through the root directory; +* - They must never be accessed by userspace; +* - Metadata directory entries must have correct ftype. +*/ +#define XFS_DIFLAG2_METADATA (1ULL << XFS_DIFLAG2_METADATA_BIT) +#define XFS_DIFLAG2_ANY \ (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \ - XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64) + XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_METADATA)static inline bool xfs_dinode_has_bigtime (const struct xfs_dinode *dip) {
fs/xfs/libxfs/xfs_inode_util.c +2 -0
@@ -225,6 +225,8 @@ xfs_inode_inherit_flags2( }if (pip->i_diflags2 &XFS_DIFLAG2_DAX ) ip->i_diflags2 |=XFS_DIFLAG2_DAX ; +if (pip->i_diflags2 &XFS_DIFLAG2_METADATA ) + ip->i_diflags2 |=XFS_DIFLAG2_METADATA ;/* Don't let invalid cowextsize hints propagate. */ failaddr = xfs_inode_validate_cowextsize(ip->i_mount, ip->i_cowextsize,
fs/xfs/libxfs/xfs_sb.c +2 -0
@@ -174,6 +174,8 @@ xfs_sb_version_to_features( features |=XFS_FEAT_NEEDSREPAIR ;if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_NREXT64 ) features |=XFS_FEAT_NREXT64 ; +if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_METADIR ) + features |=XFS_FEAT_METADIR ;return features; }
fs/xfs/xfs_inode.h +7 -0
@@ -264,6 +264,13 @@ static inline bool xfs_is_metadata_inode(struct xfs_inode *ip) {struct xfs_mount *mp = ip->i_mount; +if (xfs_has_metadir (mp)) +return ip->i_diflags2 &XFS_DIFLAG2_METADATA ; + +/* +* Before metadata directories, the only metadata inodes were the +* three quota files, the realtime bitmap, and the realtime summary. +*/ return ip == mp->m_rbmip || ip == mp->m_rsumip ||xfs_is_quota_inode (&mp->m_sb, ip->i_ino); }
fs/xfs/xfs_mount.h +2 -0
@@ -281,6 +281,7 @@ typedef struct xfs_mount {#define XFS_FEAT_BIGTIME (1ULL << 24)/* large timestamps */ #define XFS_FEAT_NEEDSREPAIR (1ULL << 25)/* needs xfs_repair */ #define XFS_FEAT_NREXT64 (1ULL << 26)/* large extent counters */ +#define XFS_FEAT_METADIR (1ULL << 27)/* metadata directory tree */ /* Mount features */ #define XFS_FEAT_NOATTR2 (1ULL << 48)/* disable attr2 creation */
@@ -344,6 +345,7 @@ __XFS_HAS_FEAT(inobtcounts, INOBTCNT) __XFS_HAS_FEAT(bigtime, BIGTIME) __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR) __XFS_HAS_FEAT(large_extent_counts, NREXT64) +__XFS_HAS_FEAT (metadir,METADIR )/* * Mount features
fs/xfs/xfs_super.c +4 -0
@@ -1640,6 +1640,10 @@ xfs_fs_fill_super( mp->m_features &= ~XFS_FEAT_DISCARD ; } +if (xfs_has_metadir (mp)) +xfs_warn (mp, +"EXPERIMENTAL metadata directory feature in use. Use at your own risk!" ); +if (xfs_has_reflink (mp)) {if (mp->m_sb.sb_rblocks) { xfs_alert(mp,
PATCH 8/23 xfs: update imeta transaction reservations for metadir
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Update the new metadata inode transaction reservations to handle metadata directories if that feature is enabled.
--- fs/xfs/libxfs/xfs_log_rlimit.c | 9 +++++ fs/xfs/libxfs/xfs_trans_resv.c | 68 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_log_rlimit.c +9 -0
@@ -48,6 +48,15 @@ xfs_log_calc_trans_resv_for_minlogblocks( {unsigned int rmap_maxlevels = mp->m_rmap_maxlevels; +/* +* The metadata directory tree feature drops the oversized minimum log +* size computations introduced by the original reflink code. +*/ +if (xfs_has_metadir (mp)) { +xfs_trans_resv_calc (mp, resv); +return ; + } +/* * In the early days of rmap+reflink, we always set the rmap maxlevels * to 9 even if the AG was small enough that it would never grow to
fs/xfs/libxfs/xfs_trans_resv.c +66 -2
78 lines not on this page · raw message
PATCH 9/23 xfs: load metadata directory root at mount time
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Load the metadata directory root inode into memory at mount time and release it at unmount time. We also make sure that the obsolete inode pointers in the superblock are not logged or read from the superblock.
--- fs/xfs/libxfs/xfs_sb.c | 31 +++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_types.c | 2 +- fs/xfs/xfs_mount.c | 20 +++++++++++++++++--- fs/xfs/xfs_mount.h | 1 + 4 files changed, 50 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_sb.c +31 -0
@@ -622,6 +622,25 @@ __xfs_sb_from_disk(/* Convert on-disk flags to in-memory flags? */ if (convert_xquota)xfs_sb_quota_from_disk (to); + +if (to->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_METADIR ) { +/* +* Set metadirino here and null out the in-core fields for +* the other inodes because metadir initialization will load +* them later. +*/ + to->sb_metadirino =be64_to_cpu (from->sb_rbmino); + to->sb_rbmino =NULLFSINO ; + to->sb_rsumino =NULLFSINO ; + +/* +* We don't have to worry about quota inode conversion here +* because metadir requires a v5 filesystem. +*/ + to->sb_uquotino =NULLFSINO ; + to->sb_gquotino =NULLFSINO ; + to->sb_pquotino =NULLFSINO ; + } }void
@@ -769,6 +788,18 @@ xfs_sb_to_disk( to->sb_lsn =cpu_to_be64 (from->sb_lsn);if (from->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID )uuid_copy (&to->sb_meta_uuid, &from->sb_meta_uuid); + +if (from->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_METADIR ) { +/* +* Save metadirino here and null out the on-disk fields for +* the other inodes, at least until we reuse the fields. +*/ + to->sb_rbmino =cpu_to_be64 (from->sb_metadirino); + to->sb_rsumino =cpu_to_be64 (NULLFSINO ); + to->sb_uquotino =cpu_to_be64 (NULLFSINO ); + to->sb_gquotino =cpu_to_be64 (NULLFSINO ); + to->sb_pquotino =cpu_to_be64 (NULLFSINO ); + } }/*
fs/xfs/libxfs/xfs_types.c +1 -1
@@ -128,7 +128,7 @@ xfs_verify_dir_ino( struct xfs_mount *mp, xfs_ino_t ino) { - if (xfs_internal_inum(mp, ino)) +if (!xfs_has_metadir (mp) &&xfs_internal_inum (mp, ino))return false;return xfs_verify_ino (mp, ino); }
fs/xfs/xfs_mount.c +17 -3
@@ -616,6 +616,16 @@ xfs_mount_setup_metadir( {int error; +/* Load the metadata directory inode into memory. */ +if (xfs_has_metadir (mp)) { + error =xfs_imeta_iget (mp, mp->m_sb.sb_metadirino, +XFS_DIR3_FT_DIR , &mp->m_metadirip); +if (error) { +xfs_warn (mp,"Failed metadir inode init: %d" , error); +return error; + } + } + error =xfs_imeta_mount (mp);if (error) { xfs_warn(mp, "Failed to load metadata inode info, error %d",
@@ -862,7 +872,7 @@ xfs_mountfs( error =xfs_mount_setup_metadir (mp);if (error) - goto out_log_dealloc; + goto out_free_metadir;/* * Get and sanity-check the root inode.
@@ -874,7 +884,7 @@ xfs_mountfs(xfs_warn (mp,"Failed to read root inode 0x%llx, error %d" , sbp->sb_rootino, -error); - goto out_log_dealloc; + goto out_free_metadir; }ASSERT (rip !=NULL );
@@ -1017,6 +1027,9 @@ xfs_mountfs(xfs_irele (rip);/* Clean out dquots that might be in memory after quotacheck. */ xfs_qm_unmount (mp); + out_free_metadir: +if (mp->m_metadirip) +xfs_imeta_irele (mp->m_metadirip);/* * Inactivate all inodes that might still be in memory after a log
@@ -1038,7 +1051,6 @@ xfs_mountfs(* quota inodes. */ xfs_unmount_flush_inodes (mp); - out_log_dealloc:xfs_log_mount_cancel (mp); out_inodegc_shrinker:unregister_shrinker (&mp->m_inodegc_shrinker);
@@ -1090,6 +1102,8 @@ xfs_unmountfs(xfs_qm_unmount_quotas (mp);xfs_rtunmount_inodes (mp);xfs_irele (mp->m_rootip); +if (mp->m_metadirip) +xfs_imeta_irele (mp->m_metadirip);xfs_unmount_flush_inodes (mp);
fs/xfs/xfs_mount.h +1 -0
@@ -90,6 +90,7 @@ typedef struct xfs_mount {struct xfs_inode *m_rbmip;/* pointer to bitmap inode */ struct xfs_inode *m_rsumip;/* pointer to summary inode */ struct xfs_inode *m_rootip;/* pointer to root directory */ +struct xfs_inode *m_metadirip;/* ptr to metadata directory */ struct xfs_quotainfo *m_quotainfo;/* disk quota information */ xfs_buftarg_t *m_ddev_targp;/* saves taking the address */ xfs_buftarg_t *m_logdev_targp;/* ptr to log device */
PATCH 10/23 xfs: convert metadata inode lookup keys to use paths
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Convert the magic metadata inode lookup keys to use actual strings for paths.
--- fs/xfs/libxfs/xfs_imeta.c | 48 ++++++++++++++++++++++++--------------------- fs/xfs/libxfs/xfs_imeta.h | 17 ++++++++++++++-- 2 files changed, 41 insertions(+), 24 deletions(-)
fs/xfs/libxfs/xfs_imeta.c +26 -22
@@ -49,26 +49,17 @@*/ /* Static metadata inode paths */ - -const struct xfs_imeta_path XFS_IMETA_RTBITMAP = { - .bogus =0 , -}; - -const struct xfs_imeta_path XFS_IMETA_RTSUMMARY = { - .bogus =1 , -}; - -const struct xfs_imeta_path XFS_IMETA_USRQUOTA = { - .bogus =2 , -}; - -const struct xfs_imeta_path XFS_IMETA_GRPQUOTA = { - .bogus =3 , -}; - -const struct xfs_imeta_path XFS_IMETA_PRJQUOTA = { - .bogus =4 , -}; +static const char *rtbitmap_path[] = {"realtime" ,"bitmap" }; +static const char *rtsummary_path[] = {"realtime" ,"summary" }; +static const char *usrquota_path[] = {"quota" ,"user" }; +static const char *grpquota_path[] = {"quota" ,"group" }; +static const char *prjquota_path[] = {"quota" ,"project" }; + +XFS_IMETA_DEFINE_PATH (XFS_IMETA_RTBITMAP , rtbitmap_path); +XFS_IMETA_DEFINE_PATH (XFS_IMETA_RTSUMMARY , rtsummary_path); +XFS_IMETA_DEFINE_PATH (XFS_IMETA_USRQUOTA , usrquota_path); +XFS_IMETA_DEFINE_PATH (XFS_IMETA_GRPQUOTA , grpquota_path); +XFS_IMETA_DEFINE_PATH (XFS_IMETA_PRJQUOTA , prjquota_path);/* Are these two paths equal? */ STATIC bool
@@ -76,7 +67,20 @@ xfs_imeta_path_compare(const struct xfs_imeta_path *a, const struct xfs_imeta_path *b) { - return a == b; + unsigned int i; + +if (a == b) +return true; + +if (a->im_depth != b->im_depth) +return false; + +for (i =0 ; i < a->im_depth; i++) +if (a->im_path[i] != b->im_path[i] && +strcmp (a->im_path[i], b->im_path[i])) +return false; + +return true; }/* Is this path ok? */
@@ -84,7 +88,7 @@ static inline boolxfs_imeta_path_check ( const struct xfs_imeta_path *path) { -return true; +return path->im_depth <=XFS_IMETA_MAX_DEPTH ; }/* Functions for storing and retrieving superblock inode values. */
fs/xfs/libxfs/xfs_imeta.h +15 -2
@@ -6,10 +6,23 @@#ifndef __XFS_IMETA_H__#define __XFS_IMETA_H__ +/* How deep can we nest metadata dirs? */ +#define XFS_IMETA_MAX_DEPTH 64 + +/* Form an imeta path from a simple array of strings. */ +#define XFS_IMETA_DEFINE_PATH (name, path) \ +const struct xfs_imeta_path name = { \ + .im_path = (path), \ + .im_depth = ARRAY_SIZE(path), \ +} +/* Key for looking up metadata inodes. */ struct xfs_imeta_path { -/* Temporary: integer to keep the static imeta definitions unique */ -int bogus; +/* Array of string pointers. */ +const char **im_path; + +/* Number of strings in path. */ +unsigned int im_depth; };/* Cleanup widget for metadata inode creation and deletion. */
PATCH 11/23 xfs: enforce metadata inode flag
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add checks for the metadata inode flag so that we don't ever leak metadata inodes out to userspace, and we don't ever try to read a regular inode as metadata.
--- fs/xfs/libxfs/xfs_inode_buf.c | 73 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_inode_buf.h | 3 ++ fs/xfs/scrub/common.c | 7 +++- fs/xfs/scrub/inode_repair.c | 10 ++++++ fs/xfs/xfs_icache.c | 2 + fs/xfs/xfs_inode.c | 13 +++++++ 6 files changed, 107 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_inode_buf.c +73 -0
@@ -457,6 +457,73 @@ xfs_dinode_verify_nrext64(return NULL ; } +/* +* Validate all the picky requirements we have for a file that claims to be +* filesystem metadata. +*/ +xfs_failaddr_t +xfs_dinode_verify_metaflag ( +struct xfs_mount *mp, +struct xfs_dinode *dip, +uint16_t mode, +uint16_t flags, +uint64_t flags2) +{ +if (!xfs_has_metadir (mp)) +return __this_address; + +/* V5 filesystem only */ +if (dip->di_version <3 ) +return __this_address; + +/* V3 inode fields that are always zero */ +if (dip->di_onlink) +return __this_address; +if ((flags2 &XFS_DIFLAG2_NREXT64 ) && dip->di_nrext64_pad) +return __this_address; +if (!(flags2 &XFS_DIFLAG2_NREXT64 ) && dip->di_flushiter) +return __this_address; + +/* Metadata files can only be directories or regular files */ +if (!S_ISDIR (mode) && !S_ISREG (mode)) +return __this_address; + +/* They must have zero access permissions */ +if (mode &0777 ) +return __this_address; + +/* DMAPI event and state masks are zero */ +if (dip->di_dmevmask || dip->di_dmstate) +return __this_address; + +/* User, group, and project IDs must be zero */ +if (dip->di_uid || dip->di_gid || + dip->di_projid_lo || dip->di_projid_hi) +return __this_address; + +/* Immutable, sync, noatime, nodump, and nodefrag flags must be set */ +if (!(flags &XFS_DIFLAG_IMMUTABLE )) +return __this_address; +if (!(flags &XFS_DIFLAG_SYNC )) +return __this_address; +if (!(flags &XFS_DIFLAG_NOATIME )) +return __this_address; +if (!(flags &XFS_DIFLAG_NODUMP )) +return __this_address; +if (!(flags &XFS_DIFLAG_NODEFRAG )) +return __this_address; + +/* Directories must have nosymlinks flags set */ +if (S_ISDIR (mode) && !(flags &XFS_DIFLAG_NOSYMLINKS )) +return __this_address; + +/* dax flags2 must not be set */ +if (flags2 &XFS_DIFLAG2_DAX ) +return __this_address; + +return NULL ; +} + xfs_failaddr_t xfs_dinode_verify( struct xfs_mount *mp,
@@ -610,6 +677,12 @@ xfs_dinode_verify( !xfs_has_bigtime(mp))return __this_address; +if (flags2 &XFS_DIFLAG2_METADATA ) { + fa =xfs_dinode_verify_metaflag (mp, dip, mode, flags, flags2); +if (fa) +return fa; + } +return NULL ; }
fs/xfs/libxfs/xfs_inode_buf.h +3 -0
@@ -28,6 +28,9 @@ int xfs_inode_from_disk(struct xfs_inode *ip, struct xfs_dinode *from);xfs_failaddr_t xfs_dinode_verify (struct xfs_mount *mp,xfs_ino_t ino,struct xfs_dinode *dip); +xfs_failaddr_t xfs_dinode_verify_metaflag (struct xfs_mount *mp, +struct xfs_dinode *dip,uint16_t mode,uint16_t flags, +uint64_t flags2);xfs_failaddr_t xfs_inode_validate_extsize (struct xfs_mount *mp,uint32_t extsize,uint16_t mode,uint16_t flags); xfs_failaddr_t xfs_inode_validate_cowextsize(struct xfs_mount *mp,
fs/xfs/scrub/common.c +6 -1
@@ -862,7 +862,12 @@ xchk_install_handle_inode( struct xfs_scrub *sc, struct xfs_inode *ip) { - if (VFS_I(ip)->i_generation != sc->sm->sm_gen) { +/* +* Only the directories in the metadata directory tree can be scrubbed +* by handle -- files must be checked through an explicit scrub type. +*/ +if ((xfs_is_metadata_inode (ip) && !S_ISDIR (VFS_I (ip)->i_mode)) || +VFS_I (ip)->i_generation != sc->sm->sm_gen) {xchk_irele (sc, ip);return -ENOENT ; }
fs/xfs/scrub/inode_repair.c +10 -0
@@ -400,6 +400,16 @@ xrep_dinode_flags( dip->di_nrext64_pad =0 ; else if (dip->di_version >= 3) dip->di_v3_pad = 0; + +if (flags2 &XFS_DIFLAG2_METADATA ) { +xfs_failaddr_t fa; + + fa =xfs_dinode_verify_metaflag (sc->mp, dip, mode, flags, + flags2); +if (fa) + flags2 &= ~XFS_DIFLAG2_METADATA ; + } + dip->di_flags =cpu_to_be16 (flags); dip->di_flags2 =cpu_to_be64 (flags2); }
fs/xfs/xfs_icache.c +2 -0
@@ -931,6 +931,8 @@ xfs_imeta_iget( goto bad_rele;if (xfs_mode_to_ftype (VFS_I (ip)->i_mode) != ftype) goto bad_rele; +if (xfs_has_metadir (mp) && !xfs_is_metadata_inode (ip)) + goto bad_rele; *ipp = ip;return 0 ;
fs/xfs/xfs_inode.c +13 -0
@@ -572,8 +572,19 @@ xfs_lookup(if (error) goto out_free_name; +/* +* Make sure that a corrupt directory cannot accidentally link to a +* metadata file. +*/ +if (XFS_IS_CORRUPT (dp->i_mount,xfs_is_metadata_inode (*ipp))) { + error = -EFSCORRUPTED ; + goto out_irele; + } +return 0 ; +out_irele: +xfs_irele (*ipp); out_free_name:if (ci_name)kmem_free (ci_name->name);
@@ -2714,6 +2725,8 @@ voidxfs_imeta_irele ( struct xfs_inode *ip) { +ASSERT (!xfs_has_metadir (ip->i_mount) ||xfs_is_metadata_inode (ip)); +xfs_irele (ip); }
PATCH 12/23 xfs: read and write metadata inode directory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Plumb in the bits we need to look up metadata inode numbers from the metadata inode directory and save them back.
--- fs/xfs/libxfs/xfs_imeta.c | 699 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_imeta.h | 17 + fs/xfs/libxfs/xfs_inode_util.c | 2 fs/xfs/libxfs/xfs_trans_resv.c | 8 fs/xfs/xfs_inode.c | 2 fs/xfs/xfs_inode.h | 4 fs/xfs/xfs_trace.h | 41 ++ 7 files changed, 765 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_imeta.c +694 -5
@@ -23,6 +23,9 @@#include "xfs_da_format.h" #include "xfs_da_btree.h" #include "xfs_trans_space.h" +#include "xfs_dir2.h" +#include "xfs_dir2_priv.h" +#include "xfs_ag.h" /* * Metadata Inode Number Management
@@ -43,9 +46,16 @@* this structure must be passed to xfs_imeta_end_update to free resources that * cannot be freed during the transaction. * -* Right now we only support callers passing in the predefined metadata inode -* paths; the goal is that callers will some day locate metadata inodes based -* on path lookups into a metadata directory structure. +* When the metadata directory tree (metadir) feature is enabled, we can create +* a complex directory tree in which to store metadata inodes. Inodes within +* the metadata directory tree should have the "metadata" inode flag set to +* prevent them from being exposed to the outside world. +* +* Callers are expected to take the IOLOCK of metadata directories when +* performing lookups or updates to the tree. They are expected to take the +* ILOCK of any inode in the metadata directory tree (just like the regular to +* synchronize access to that inode. It is not necessary to take the MMAPLOCK +* since metadata inodes should never be exposed to user space. */ /* Static metadata inode paths */
@@ -61,6 +71,11 @@ XFS_IMETA_DEFINE_PATH(XFS_IMETA_USRQUOTA, usrquota_path);XFS_IMETA_DEFINE_PATH (XFS_IMETA_GRPQUOTA , grpquota_path);XFS_IMETA_DEFINE_PATH (XFS_IMETA_PRJQUOTA , prjquota_path); +const struct xfs_imeta_path XFS_IMETA_METADIR = { + .im_depth =0 , + .im_ftype =XFS_DIR3_FT_DIR , +}; +/* Are these two paths equal? */ STATIC bool xfs_imeta_path_compare(
@@ -118,6 +133,10 @@ static const struct xfs_imeta_sbmap { .path = &XFS_IMETA_PRJQUOTA, .offset = offsetof(struct xfs_sb, sb_pquotino), }, + { + .path = &XFS_IMETA_METADIR, + .offset = offsetof(struct xfs_sb, sb_metadirino), + }, { NULL, 0 }, };
@@ -289,6 +308,523 @@ xfs_imeta_sb_link(return 0 ; } +/* Functions for storing and retrieving metadata directory inode values. */ + +static inline void +set_xname ( +struct xfs_name *xname, +const struct xfs_imeta_path *path, +unsigned int path_idx, +unsigned char ftype) +{ + xname->name = (const unsigned char *)path->im_path[path_idx]; + xname->len =strlen (path->im_path[path_idx]); + xname->type = ftype; +} + +/* Look up the inode number and filetype for an exact name in a directory. */ +static inline int +xfs_imeta_dir_lookup ( +struct xfs_inode *dp, +struct xfs_name *xname, +xfs_ino_t *ino) +{ +struct xfs_da_args args = { + .dp = dp, + .geo = dp->i_mount->m_dir_geo, + .name = xname->name, + .namelen = xname->len, + .hashval =xfs_dir2_hashname (dp->i_mount, xname), + .whichfork =XFS_DATA_FORK , + .op_flags =XFS_DA_OP_OKNOENT , + .owner = dp->i_ino, + }; +unsigned int lock_mode; +bool isblock, isleaf; +int error; + +if (xfs_is_shutdown (dp->i_mount)) +return -EIO ; + + lock_mode =xfs_ilock_data_map_shared (dp); +if (dp->i_df.if_format ==XFS_DINODE_FMT_LOCAL ) { + error =xfs_dir2_sf_lookup (&args); + goto out_unlock; + } + +/* dir2 functions require that the data fork is loaded */ + error =xfs_iread_extents (NULL , dp,XFS_DATA_FORK ); +if (error) + goto out_unlock; + + error =xfs_dir2_isblock (&args, &isblock); +if (error) + goto out_unlock; + +if (isblock) { + error =xfs_dir2_block_lookup (&args); + goto out_unlock; + } + + error =xfs_dir2_isleaf (&args, &isleaf); +if (error) + goto out_unlock; + +if (isleaf) { + error =xfs_dir2_leaf_lookup (&args); + goto out_unlock; + } + + error =xfs_dir2_node_lookup (&args); + +out_unlock: +xfs_iunlock (dp, lock_mode); +if (error == -EEXIST ) + error =0 ; +if (error) +return error; + + *ino = args.inumber; + xname->type = args.filetype; +return 0 ; +} +/* +* Given a parent directory @dp, a metadata inode @path and component +* @path_idx, and the expected file type @ftype of the path component, fill out +* the @xname and look up the inode number in the directory, returning it in +* @ino. +*/ +static inline int +xfs_imeta_dir_lookup_component ( +struct xfs_inode *dp, +struct xfs_name *xname, +xfs_ino_t *ino) +{ +int type_wanted = xname->type; +int error; + +trace_xfs_imeta_dir_lookup_component (dp, xname,NULLFSINO ); + +if (!S_ISDIR (VFS_I (dp)->i_mode)) +return -EFSCORRUPTED ; + + error =xfs_imeta_dir_lookup (dp, xname, ino); +if (error) +return error; +if (!xfs_verify_ino (dp->i_mount, *ino)) +return -EFSCORRUPTED ; +if (type_wanted !=XFS_DIR3_FT_UNKNOWN && xname->type != type_wanted) +return -EFSCORRUPTED ; + +trace_xfs_imeta_dir_lookup_found (dp, xname, *ino); +return 0 ; +} + +/* +* Traverse a metadata directory tree path, returning the inode corresponding +* to the parent of the last path component. If any of the path components do +* not exist, return -ENOENT. +*/ +STATIC int +xfs_imeta_dir_parent ( +struct xfs_mount *mp, +const struct xfs_imeta_path *path, +struct xfs_inode **dpp) +{ +struct xfs_name xname; +struct xfs_inode *dp; +xfs_ino_t ino; +unsigned int i; +int error; + +if (mp->m_metadirip ==NULL ) +return -ENOENT ; + +/* Grab the metadir root. */ + error =xfs_imeta_iget (mp, mp->m_metadirip->i_ino,XFS_DIR3_FT_DIR , + &dp); +if (error) +return error; + +/* Caller wanted the root, we're done! */ +if (path->im_depth ==0 ) { + *dpp = dp; +return 0 ; + } + +for (i =0 ; i < path->im_depth -1 ; i++) { +struct xfs_inode *ip =NULL ; + +xfs_ilock (dp,XFS_IOLOCK_SHARED ); + +/* Look up the name in the current directory. */ +set_xname (&xname, path, i,XFS_DIR3_FT_DIR ); + error =xfs_imeta_dir_lookup_component (dp, &xname, &ino); +if (error) + goto out_rele; + +/* +* Grab the child inode while we still have the parent +* directory locked. +*/ + error =xfs_imeta_iget (mp, ino,XFS_DIR3_FT_DIR , &ip); +if (error) + goto out_rele; + +xfs_iunlock (dp,XFS_IOLOCK_SHARED ); +xfs_imeta_irele (dp); + dp = ip; + } + + *dpp = dp; +return 0 ; + +out_rele: +xfs_iunlock (dp,XFS_IOLOCK_SHARED ); +xfs_imeta_irele (dp); +return error; +} + +/* +* Look up a metadata inode from the metadata directory. If the last path +* component doesn't exist, return NULLFSINO. If any other part of the path +* does not exist, return -ENOENT so we can distinguish the two. +*/ +STATIC int +xfs_imeta_dir_lookup_int ( +struct xfs_mount *mp, +const struct xfs_imeta_path *path, +xfs_ino_t *inop) +{ +struct xfs_name xname; +struct xfs_inode *dp =NULL ; +xfs_ino_t ino; +int error; + +/* metadir ino is recorded in superblock */ +if (xfs_imeta_path_compare (path, &XFS_IMETA_METADIR )) +return xfs_imeta_sb_lookup (mp, path, inop); + +ASSERT (path->im_depth >0 ); + +/* Find the parent of the last path component. */ + error =xfs_imeta_dir_parent (mp, path, &dp); +if (error) +return error; + +xfs_ilock (dp,XFS_IOLOCK_SHARED ); + +/* Look up the name in the current directory. */ +set_xname (&xname, path, path->im_depth -1 , path->im_ftype); + error =xfs_imeta_dir_lookup_component (dp, &xname, &ino); +switch (error) { +case 0 : + *inop = ino; +break ; +case -ENOENT : + *inop =NULLFSINO ; + error =0 ; +break ; + } + +xfs_iunlock (dp,XFS_IOLOCK_SHARED ); +xfs_imeta_irele (dp); +return error; +} + +/* +* Load all the metadata inode pointers that are cached in the in-core +* superblock but live somewhere in the metadata directory tree. +*/ +STATIC int +xfs_imeta_dir_mount ( +struct xfs_mount *mp) +{ +const struct xfs_imeta_sbmap *p; +xfs_ino_t *sb_inop; +int err2; +int error =0 ; + +for (p = xfs_imeta_sbmaps; p->path && p->path->im_depth >0 ; p++) { +if (p->path == &XFS_IMETA_METADIR ) +continue ; + sb_inop =xfs_imeta_sbmap_to_inop (mp, p); + err2 =xfs_imeta_dir_lookup_int (mp, p->path, sb_inop); +if (err2 == -ENOENT ) { + *sb_inop =NULLFSINO ; +continue ; + } +if (!error && err2) + error = err2; + } + +return error; +} + +/* Set up an inode to be recognized as a metadata inode. */ +void +xfs_imeta_set_metaflag ( +struct xfs_trans *tp, +struct xfs_inode *ip) +{ +VFS_I (ip)->i_mode &= ~0777 ; +VFS_I (ip)->i_uid =GLOBAL_ROOT_UID ; +VFS_I (ip)->i_gid =GLOBAL_ROOT_GID ; + ip->i_projid =0 ; + ip->i_diflags |= (XFS_DIFLAG_IMMUTABLE |XFS_DIFLAG_SYNC | +XFS_DIFLAG_NOATIME |XFS_DIFLAG_NODUMP | +XFS_DIFLAG_NODEFRAG ); +if (S_ISDIR (VFS_I (ip)->i_mode)) + ip->i_diflags |=XFS_DIFLAG_NOSYMLINKS ; + ip->i_diflags2 &= ~XFS_DIFLAG2_DAX ; + ip->i_diflags2 |=XFS_DIFLAG2_METADATA ; +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); +} + +/* +* Create a new metadata inode accessible via the given metadata directory path. +* Callers must ensure that the directory entry does not already exist; a new +* one will be created. +*/ +STATIC int +xfs_imeta_dir_create ( +struct xfs_trans **tpp, +const struct xfs_imeta_path *path, +umode_t mode, +unsigned int flags, +struct xfs_inode **ipp, +struct xfs_imeta_update *upd) +{ +struct xfs_icreate_args args = { + .nlink =S_ISDIR (mode) ?2 :1 , + }; +struct xfs_name xname; +struct xfs_mount *mp = (*tpp)->t_mountp; +struct xfs_inode *dp = upd->dp; +xfs_ino_t *sb_inop; +xfs_ino_t ino; +unsigned int resblks; +int error; + +xfs_icreate_args_rootfile (&args, mode); + +/* metadir ino is recorded in superblock; only mkfs gets to do this */ +if (xfs_imeta_path_compare (path, &XFS_IMETA_METADIR )) { + error =xfs_imeta_sb_create (tpp, path, mode, flags, ipp); +if (error) +return error; + +/* Set the metadata iflag, initialize directory. */ +xfs_imeta_set_metaflag (*tpp, *ipp); +return xfs_dir_init (*tpp, *ipp, *ipp); + } + +ASSERT (path->im_depth >0 ); + +/* Check that the name does not already exist in the directory. */ +set_xname (&xname, path, path->im_depth -1 ,XFS_DIR3_FT_UNKNOWN ); + error =xfs_imeta_dir_lookup_component (dp, &xname, &ino); +switch (error) { +case -ENOENT : +break ; +case 0 : + error = -EEXIST ; + fallthrough; +default : +return error; + } + +xfs_ilock (dp,XFS_ILOCK_EXCL |XFS_ILOCK_PARENT ); + args.pip = dp; + +/* +* A newly created regular or special file just has one directory +* entry pointing to them, but a directory also the "." entry +* pointing to itself. +*/ + error =xfs_dialloc (tpp, dp->i_ino, mode, &ino); +if (error) + goto out_ilock; + error =xfs_icreate (*tpp, ino, &args, ipp); +if (error) + goto out_ilock; +xfs_imeta_set_metaflag (*tpp, *ipp); + +/* +* Once we join the parent directory to the transaction we can't +* release it until after the transaction commits or cancels, so we +* must defer releasing it to end_update. This is different from +* regular file creation, where the vfs holds the parent dir reference +* and will free it. The caller is always responsible for releasing +* ipp, even if we failed. +*/ +xfs_trans_ijoin (*tpp, dp,XFS_ILOCK_EXCL ); + +/* Create the entry. */ +if (S_ISDIR (args.mode)) + resblks =XFS_MKDIR_SPACE_RES (mp, xname.len); +else + resblks =XFS_CREATE_SPACE_RES (mp, xname.len); + xname.type =xfs_mode_to_ftype (args.mode); +trace_xfs_imeta_dir_try_create (dp, &xname,NULLFSINO ); + error =xfs_dir_create_new_child (*tpp, resblks, dp, &xname, *ipp); +if (error) +return error; +trace_xfs_imeta_dir_created (*ipp, &xname, ino); + +/* Attach dquots to this file. Caller should have allocated them! */ +if (!(flags &XFS_IMETA_CREATE_NOQUOTA )) { + error =xfs_qm_dqattach_locked (*ipp, false); +if (error) +return error; +xfs_trans_mod_dquot_byino (*tpp, *ipp,XFS_TRANS_DQ_ICOUNT ,1 ); + } + +/* Update the in-core superblock value if there is one. */ + sb_inop =xfs_imeta_path_to_sb_inop (mp, path); +if (sb_inop) + *sb_inop = ino; +return 0 ; + +out_ilock: +xfs_iunlock (dp,XFS_ILOCK_EXCL ); +return error; +} + +/* +* Remove the given entry from the metadata directory and drop the link count +* of the metadata inode. +*/ +STATIC int +xfs_imeta_dir_unlink ( +struct xfs_trans **tpp, +const struct xfs_imeta_path *path, +struct xfs_inode *ip, +struct xfs_imeta_update *upd) +{ +struct xfs_name xname; +struct xfs_mount *mp = (*tpp)->t_mountp; +struct xfs_inode *dp = upd->dp; +xfs_ino_t *sb_inop; +xfs_ino_t ino; +unsigned int resblks; +int error; + +/* Metadata directory root cannot be unlinked. */ +if (xfs_imeta_path_compare (path, &XFS_IMETA_METADIR )) { +ASSERT (0 ); +return -EFSCORRUPTED ; + } + +ASSERT (path->im_depth >0 ); + +/* Look up the name in the current directory. */ +set_xname (&xname, path, path->im_depth -1 , +xfs_mode_to_ftype (VFS_I (ip)->i_mode)); + error =xfs_imeta_dir_lookup_component (dp, &xname, &ino); +switch (error) { +case 0 : +if (ino != ip->i_ino) + error = -ENOENT ; +break ; +case -ENOENT : + error = -EFSCORRUPTED ; +break ; + } +if (error) +return error; + +xfs_lock_two_inodes (dp,XFS_ILOCK_EXCL , ip,XFS_ILOCK_EXCL ); + +/* +* Once we join the parent directory to the transaction we can't +* release it until after the transaction commits or cancels, so we +* must defer releasing it to end_update. This is different from +* regular file removal, where the vfs holds the parent dir reference +* and will free it. The unlink caller is always responsible for +* releasing ip, so we don't need to take care of that. +*/ +xfs_trans_ijoin (*tpp, dp,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (*tpp, ip,XFS_ILOCK_EXCL ); + + resblks =XFS_REMOVE_SPACE_RES (mp); + error =xfs_dir_remove_child (*tpp, resblks, dp, &xname, ip); +if (error) +return error; +trace_xfs_imeta_dir_unlinked (dp, &xname, ip->i_ino); + +/* Update the in-core superblock value if there is one. */ + sb_inop =xfs_imeta_path_to_sb_inop (mp, path); +if (sb_inop) + *sb_inop =NULLFSINO ; +return 0 ; +} + +/* Set the given path in the metadata directory to point to an inode. */ +STATIC int +xfs_imeta_dir_link ( +struct xfs_trans *tp, +const struct xfs_imeta_path *path, +struct xfs_inode *ip, +struct xfs_imeta_update *upd) +{ +struct xfs_name xname; +struct xfs_mount *mp = tp->t_mountp; +struct xfs_inode *dp = upd->dp; +xfs_ino_t *sb_inop; +xfs_ino_t ino; +unsigned int resblks; +int error; + +/* Metadata directory root cannot be linked. */ +if (xfs_imeta_path_compare (path, &XFS_IMETA_METADIR )) { +ASSERT (0 ); +return -EFSCORRUPTED ; + } + +ASSERT (path->im_depth >0 ); + +/* Look up the name in the current directory. */ +set_xname (&xname, path, path->im_depth -1 , +xfs_mode_to_ftype (VFS_I (ip)->i_mode)); + error =xfs_imeta_dir_lookup_component (dp, &xname, &ino); +switch (error) { +case -ENOENT : +break ; +case 0 : + error = -EEXIST ; + fallthrough; +default : +return error; + } + +xfs_lock_two_inodes (ip,XFS_ILOCK_EXCL , dp,XFS_ILOCK_EXCL ); + +/* +* Once we join the parent directory to the transaction we can't +* release it until after the transaction commits or cancels, so we +* must defer releasing it to end_update. This is different from +* regular file removal, where the vfs holds the parent dir reference +* and will free it. The link caller is always responsible for +* releasing ip, so we don't need to take care of that. +*/ +xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, dp,XFS_ILOCK_EXCL ); + + resblks =XFS_LINK_SPACE_RES (mp, target_name->len); + error =xfs_dir_link_existing_child (tp, resblks, dp, &xname, ip); +if (error) +return error; + +trace_xfs_imeta_dir_link (dp, &xname, ip->i_ino); + +/* Update the in-core superblock value if there is one. */ + sb_inop =xfs_imeta_path_to_sb_inop (mp, path); +if (sb_inop) + *sb_inop = ip->i_ino; +return 0 ; +} +/* General functions for managing metadata inode pointers */ /*
@@ -318,7 +854,13 @@ xfs_imeta_lookup(ASSERT (xfs_imeta_path_check (path)); - error =xfs_imeta_sb_lookup (mp, path, &ino); +if (xfs_has_metadir (mp)) { + error =xfs_imeta_dir_lookup_int (mp, path, &ino); +if (error == -ENOENT ) +return -EFSCORRUPTED ; + }else { + error =xfs_imeta_sb_lookup (mp, path, &ino); + }if (error)return error;
@@ -351,12 +893,49 @@ xfs_imeta_create(struct xfs_inode **ipp, struct xfs_imeta_update *upd) { + struct xfs_mount *mp = (*tpp)->t_mountp; +ASSERT (xfs_imeta_path_check (path)); *ipp =NULL ; +if (xfs_has_metadir (mp)) +return xfs_imeta_dir_create (tpp, path, mode, flags, ipp, + upd);return xfs_imeta_sb_create (tpp, path, mode, flags, ipp); } +/* Free a file from the metadata directory tree. */ +STATIC int +xfs_imeta_ifree ( +struct xfs_trans *tp, +struct xfs_inode *ip) +{ +struct xfs_mount *mp = ip->i_mount; +struct xfs_perag *pag; +struct xfs_icluster xic = {0 }; +int error; + +ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); +ASSERT (VFS_I (ip)->i_nlink ==0 ); +ASSERT (ip->i_df.if_nextents ==0 ); +ASSERT (ip->i_disk_size ==0 || !S_ISREG (VFS_I (ip)->i_mode)); +ASSERT (ip->i_nblocks ==0 ); + + pag =xfs_perag_get (mp,XFS_INO_TO_AGNO (mp, ip->i_ino)); + + error =xfs_dir_ifree (tp, pag, ip, &xic); +if (error) + goto out; + +/* Metadata files do not support ownership changes or DMAPI. */ + +if (xic.deleted) + error =xfs_ifree_cluster (tp, pag, ip, &xic); +out: +xfs_perag_put (pag); +return error; +} +/* * Unlink a metadata inode @ip from the metadata directory given by @path. The * metadata inode must not be ILOCKed. Upon return, the inode will be ijoined
@@ -370,10 +949,28 @@ xfs_imeta_unlink(struct xfs_inode *ip, struct xfs_imeta_update *upd) { + struct xfs_mount *mp = (*tpp)->t_mountp; +int error; +ASSERT (xfs_imeta_path_check (path));ASSERT (xfs_imeta_verify ((*tpp)->t_mountp, ip->i_ino)); -return xfs_imeta_sb_unlink (tpp, path, ip); +if (xfs_has_metadir (mp)) + error =xfs_imeta_dir_unlink (tpp, path, ip, upd); +else + error =xfs_imeta_sb_unlink (tpp, path, ip); +if (error) +return error; + +/* +* Metadata files require explicit resource cleanup. In other words, +* the inactivation system will not touch these files, so we must free +* the ondisk inode by ourselves if warranted. +*/ +if (VFS_I (ip)->i_nlink >0 ) +return 0 ; + +return xfs_imeta_ifree (*tpp, ip); }/*
@@ -388,8 +985,12 @@ xfs_imeta_link(struct xfs_inode *ip, struct xfs_imeta_update *upd) { + struct xfs_mount *mp = tp->t_mountp; +ASSERT (xfs_imeta_path_check (path)); +if (xfs_has_metadir (mp)) +return xfs_imeta_dir_link (tp, path, ip, upd);return xfs_imeta_sb_link (tp, path, ip); }
@@ -404,6 +1005,14 @@ xfs_imeta_end_update( int error) {trace_xfs_imeta_end_update (mp, error, __return_address); + +if (upd->dp) { +if (upd->lock_mode) +xfs_iunlock (upd->dp, upd->lock_mode); +xfs_imeta_irele (upd->dp); + } + upd->lock_mode =0 ; + upd->dp =NULL ; }/* Start setting up for a metadata directory tree operation. */
@@ -413,9 +1022,32 @@ xfs_imeta_start_update(const struct xfs_imeta_path *path, struct xfs_imeta_update *upd) { + int error; +trace_xfs_imeta_start_update (mp,0 , __return_address);memset (upd,0 ,sizeof (struct xfs_imeta_update )); + +/* Metadir root directory does not have a parent. */ +if (!xfs_has_metadir (mp) || +xfs_imeta_path_compare (path, &XFS_IMETA_METADIR )) +return 0 ; + +ASSERT (path->im_depth >0 ); + +/* +* Find the parent of the last path component. If the parent path does +* not exist, we consider this corruption because paths are supposed +* to exist. +*/ + error =xfs_imeta_dir_parent (mp, path, &upd->dp); +if (error == -ENOENT ) +return -EFSCORRUPTED ; +if (error) +return error; + +xfs_ilock (upd->dp,XFS_IOLOCK_EXCL |XFS_IOLOCK_PARENT ); + upd->lock_mode =XFS_IOLOCK_EXCL ;return 0 ; }
@@ -442,6 +1074,9 @@ intxfs_imeta_mount ( struct xfs_mount *mp) { +if (xfs_has_metadir (mp)) +return xfs_imeta_dir_mount (mp); +return 0 ; }
@@ -450,6 +1085,9 @@ unsigned intxfs_imeta_create_space_res ( struct xfs_mount *mp) { +if (xfs_has_metadir (mp)) +return max (XFS_MKDIR_SPACE_RES (mp,NAME_MAX ), +XFS_CREATE_SPACE_RES (mp,NAME_MAX ));return XFS_IALLOC_SPACE_RES (mp); }
@@ -460,3 +1098,54 @@ xfs_imeta_unlink_space_res( {return XFS_REMOVE_SPACE_RES (mp); } + +/* Clear the metadata iflag if we're unlinking this inode. */ +void +xfs_imeta_droplink ( +struct xfs_inode *ip) +{ +if (VFS_I (ip)->i_nlink ==0 && +xfs_has_metadir (ip->i_mount) && +xfs_is_metadata_inode (ip)) + ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA ; +} + +/* +* Given a metadata directory update, look up the inode number of the last +* component in the path. +*/ +int +xfs_imeta_lookup_update ( +struct xfs_mount *mp, +const struct xfs_imeta_path *path, +struct xfs_imeta_update *upd, +xfs_ino_t *inop) +{ +struct xfs_name xname; +xfs_ino_t ino; +int error; + +ASSERT (xfs_isilocked (upd->dp,XFS_IOLOCK_SHARED |XFS_IOLOCK_EXCL )); + +/* metadir ino is recorded in superblock */ +if (!xfs_has_metadir (mp) || +xfs_imeta_path_compare (path, &XFS_IMETA_METADIR )) +return xfs_imeta_sb_lookup (mp, path, inop); + +ASSERT (path->im_depth >0 ); + +/* Check that the name does not already exist in the directory. */ +set_xname (&xname, path, path->im_depth -1 ,XFS_DIR3_FT_UNKNOWN ); + error =xfs_imeta_dir_lookup_component (upd->dp, &xname, &ino); +switch (error) { +case 0 : + *inop = ino; +break ; +case -ENOENT : + *inop =NULLFSINO ; + error =0 ; +break ; + } + +return error; +}
fs/xfs/libxfs/xfs_imeta.h +16 -1
@@ -13,6 +13,7 @@#define XFS_IMETA_DEFINE_PATH (name, path) \ const struct xfs_imeta_path name = { \ .im_path = (path), \ + .im_ftype = XFS_DIR3_FT_REG_FILE, \ .im_depth = ARRAY_SIZE(path), \ }
@@ -23,11 +24,18 @@ struct xfs_imeta_path {/* Number of strings in path. */ unsigned int im_depth; + +/* Expected file type. */ +unsigned int im_ftype; };/* Cleanup widget for metadata inode creation and deletion. */ struct xfs_imeta_update { -/* empty for now */ +/* Parent directory */ +struct xfs_inode *dp; + +/* Parent directory lock mode */ +unsigned int lock_mode; };/* Lookup keys for static metadata inodes. */
@@ -36,9 +44,15 @@ extern const struct xfs_imeta_path XFS_IMETA_RTSUMMARY;extern const struct xfs_imeta_path XFS_IMETA_USRQUOTA ;extern const struct xfs_imeta_path XFS_IMETA_GRPQUOTA ;extern const struct xfs_imeta_path XFS_IMETA_PRJQUOTA ; +extern const struct xfs_imeta_path XFS_IMETA_METADIR ;int xfs_imeta_lookup (struct xfs_mount *mp,const struct xfs_imeta_path *path,xfs_ino_t *ino); +int xfs_imeta_lookup_update (struct xfs_mount *mp, +const struct xfs_imeta_path *path, +struct xfs_imeta_update *upd,xfs_ino_t *inop); + +void xfs_imeta_set_metaflag (struct xfs_trans *tp,struct xfs_inode *ip);/* Don't allocate quota for this file. */ #define XFS_IMETA_CREATE_NOQUOTA (1 << 0)
@@ -57,6 +71,7 @@ int xfs_imeta_start_update(struct xfs_mount *mp,bool xfs_is_static_meta_ino (struct xfs_mount *mp,xfs_ino_t ino);int xfs_imeta_mount (struct xfs_mount *mp); +void xfs_imeta_droplink (struct xfs_inode *ip);unsigned int xfs_imeta_create_space_res (struct xfs_mount *mp);unsigned int xfs_imeta_unlink_space_res (struct xfs_mount *mp);
fs/xfs/libxfs/xfs_inode_util.c +2 -0
@@ -23,6 +23,7 @@#include "xfs_ag.h" #include "xfs_iunlink_item.h" #include "xfs_inode_item.h" +#include "xfs_imeta.h" uint16_t xfs_flags2diflags(
@@ -627,6 +628,7 @@ xfs_droplink(xfs_trans_ichgtime (tp, ip,XFS_ICHGTIME_CHG );drop_nlink (VFS_I (ip)); +xfs_imeta_droplink (ip);xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE );if (VFS_I (ip)->i_nlink)
fs/xfs/libxfs/xfs_trans_resv.c +7 -1
@@ -921,7 +921,10 @@ xfs_calc_imeta_create_resv(unsigned int ret; ret =xfs_calc_buf_res (1 , mp->m_sb.sb_sectsize); - ret += resp->tr_create.tr_logres; +if (xfs_has_metadir (mp)) + ret +=max (resp->tr_create.tr_logres, resp->tr_mkdir.tr_logres); +else + ret += resp->tr_create.tr_logres;return ret; }
@@ -931,6 +934,9 @@ xfs_calc_imeta_create_count( struct xfs_mount *mp, struct xfs_trans_resv *resp) { + if (xfs_has_metadir(mp)) + return max(resp->tr_create.tr_logcount, + resp->tr_mkdir.tr_logcount);return resp->tr_create.tr_logcount; }
fs/xfs/xfs_inode.c +1 -1
@@ -1796,7 +1796,7 @@ xfs_ifree_mark_inode_stale(* inodes that are in memory - they all must be marked stale and attached to * the cluster buffer. */ -static int +int xfs_ifree_cluster( struct xfs_trans *tp, struct xfs_perag *pag,
fs/xfs/xfs_inode.h +4 -0
@@ -439,6 +439,7 @@ static inline bool xfs_inode_has_bigrtextents(struct xfs_inode *ip)#define XFS_IOLOCK_SHIFT 16#define XFS_IOLOCK_MAX_SUBCLASS 3#define XFS_IOLOCK_DEP_MASK 0x000f0000u +#define XFS_IOLOCK_PARENT (I_MUTEX_PARENT << XFS_ILOCK_SHIFT)#define XFS_MMAPLOCK_SHIFT 20#define XFS_MMAPLOCK_NUMORDER 0
@@ -517,6 +518,9 @@ uint xfs_ilock_data_map_shared(struct xfs_inode *);uint xfs_ilock_attr_map_shared (struct xfs_inode *);int xfs_ifree (struct xfs_trans *,struct xfs_inode *); +int xfs_ifree_cluster (struct xfs_trans *tp,struct xfs_perag *pag, +struct xfs_inode *free_ip, +struct xfs_icluster *xic);int xfs_itruncate_extents_flags (struct xfs_trans **,struct xfs_inode *,int ,xfs_fsize_t ,int );void xfs_iext_realloc (xfs_inode_t *,int ,int );
fs/xfs/xfs_trace.h +41 -0
47 lines not on this page · raw message
PATCH 13/23 xfs: ensure metadata directory paths exist before creating files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Since xfs_imeta_create can create new metadata files arbitrarily deep in the metadata directory tree, we must supply a function that can ensure that all directories in a path exist, and call it before the quota functions create the quota inodes.
--- fs/xfs/libxfs/xfs_imeta.h | 2 + fs/xfs/xfs_inode.c | 103 +++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_qm.c | 16 +++++++ 3 files changed, 121 insertions(+)
fs/xfs/libxfs/xfs_imeta.h +2 -0
@@ -80,5 +80,7 @@ unsigned int xfs_imeta_unlink_space_res(struct xfs_mount *mp);int xfs_imeta_iget (struct xfs_mount *mp,xfs_ino_t ino,unsigned char ftype,struct xfs_inode **ipp);void xfs_imeta_irele (struct xfs_inode *ip); +int xfs_imeta_ensure_dirpath (struct xfs_mount *mp, +const struct xfs_imeta_path *path);#endif /* __XFS_IMETA_H__ */
fs/xfs/xfs_inode.c +103 -0
109 lines not on this page · raw message
fs/xfs/xfs_qm.c +16 -0
@@ -829,6 +829,22 @@ xfs_qm_qino_alloc(if (error)return error; +/* +* Ensure the quota directory exists, being careful to disable quotas +* while we do this. We'll have to quotacheck anyway, so the temporary +* undercount of the directory tree shouldn't affect the quota count. +*/ +if (xfs_has_metadir (mp)) { +unsigned int old_qflags; + + old_qflags = mp->m_qflags &XFS_ALL_QUOTA_ACCT ; + mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT ; + error =xfs_imeta_ensure_dirpath (mp, path); + mp->m_qflags |= old_qflags; +if (error) +return error; + } + error =xfs_imeta_start_update (mp, path, &upd);if (error)return error;
PATCH 14/23 xfs: disable the agi rotor for metadata inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Ideally, we'd put all the metadata inodes in one place if we could, so that the metadata all stay reasonably close together instead of spreading out over the disk. Furthermore, if the log is internal we'd probably prefer to keep the metadata near the log. Therefore, disable AGI rotoring for metadata inode allocations.
--- fs/xfs/libxfs/xfs_ialloc.c | 16 +++++++++------- fs/xfs/libxfs/xfs_ialloc.h | 2 +- fs/xfs/libxfs/xfs_imeta.c | 4 ++-- fs/xfs/scrub/tempfile.c | 2 +- fs/xfs/xfs_inode.c | 4 ++-- fs/xfs/xfs_symlink.c | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_ialloc.c +9 -7
@@ -1798,26 +1798,28 @@ xfs_dialloc_try_ag(int xfs_dialloc (struct xfs_trans **tpp, -xfs_ino_t parent, +struct xfs_inode *pip,umode_t mode,xfs_ino_t *new_ino) {struct xfs_mount *mp = (*tpp)->t_mountp; +struct xfs_perag *pag; +struct xfs_ino_geometry *igeo =M_IGEO (mp); +xfs_ino_t ino; +xfs_ino_t parent = pip ? pip->i_ino :0 ;xfs_agnumber_t agno; -int error =0 ;xfs_agnumber_t start_agno; -struct xfs_perag *pag; -struct xfs_ino_geometry *igeo =M_IGEO (mp);bool ok_alloc = true;int flags; -xfs_ino_t ino; +int error =0 ;/* * Directories, symlinks, and regular files frequently allocate at least * one block, so factor that potential expansion when we examine whether -* an AG has enough space for file creation. +* an AG has enough space for file creation. Try to keep metadata +* files all in the same AG. */ -if (S_ISDIR (mode)) +if (S_ISDIR (mode) && (!pip || !xfs_is_metadata_inode (pip))) start_agno =xfs_ialloc_next_ag (mp);else { start_agno =XFS_INO_TO_AGNO (mp, parent);
fs/xfs/libxfs/xfs_ialloc.h +1 -1
@@ -36,7 +36,7 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)* Allocate an inode on disk. Mode is used to tell whether the new inode will * need space, and whether it is a directory. */ -int xfs_dialloc (struct xfs_trans **tpp,xfs_ino_t parent,umode_t mode, +int xfs_dialloc (struct xfs_trans **tpp,struct xfs_inode *dp,umode_t mode,xfs_ino_t *new_ino); int xfs_difree(struct xfs_trans *tp, struct xfs_perag *pag,
fs/xfs/libxfs/xfs_imeta.c +2 -2
@@ -232,7 +232,7 @@ xfs_imeta_sb_create(return -EEXIST ;/* Create a new inode and set the sb pointer. */ - error =xfs_dialloc (tpp,0 , mode, &ino); + error =xfs_dialloc (tpp,NULL , mode, &ino);if (error)return error; error =xfs_icreate (*tpp, ino, &args, ipp);
@@ -642,7 +642,7 @@ xfs_imeta_dir_create(* entry pointing to them, but a directory also the "." entry * pointing to itself. */ - error =xfs_dialloc (tpp, dp->i_ino, mode, &ino); + error =xfs_dialloc (tpp, dp, mode, &ino);if (error) goto out_ilock; error =xfs_icreate (*tpp, ino, &args, ipp);
fs/xfs/scrub/tempfile.c +1 -1
@@ -87,7 +87,7 @@ xrep_tempfile_create( goto out_release_dquots;/* Allocate inode, set up directory. */ - error =xfs_dialloc (&tp, dp->i_ino, mode, &ino); + error =xfs_dialloc (&tp, dp, mode, &ino);if (error) goto out_trans_cancel; error =xfs_icreate (tp, ino, &args, &sc->tempip);
fs/xfs/xfs_inode.c +2 -2
@@ -864,7 +864,7 @@ xfs_create(* entry pointing to them, but a directory also the "." entry * pointing to itself. */ - error =xfs_dialloc (&tp, dp->i_ino, args->mode, &ino); + error =xfs_dialloc (&tp, dp, args->mode, &ino);if (!error) error =xfs_icreate (tp, ino, args, &ip);if (error)
@@ -980,7 +980,7 @@ xfs_create_tmpfile(if (error) goto out_release_dquots; - error =xfs_dialloc (&tp, dp->i_ino, args->mode, &ino); + error =xfs_dialloc (&tp, dp, args->mode, &ino);if (!error) error =xfs_icreate (tp, ino, args, &ip);if (error)
fs/xfs/xfs_symlink.c +1 -1
@@ -158,7 +158,7 @@ xfs_symlink(/* * Allocate an inode for the symlink. */ - error =xfs_dialloc (&tp, dp->i_ino,S_IFLNK , &ino); + error =xfs_dialloc (&tp, dp,S_IFLNK , &ino);if (!error) error =xfs_icreate (tp, ino, &args, &ip);if (error)
PATCH 15/23 xfs: hide metadata inodes from everyone because they are special
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Metadata inodes are private files and therefore cannot be exposed to userspace. This means no bulkstat, no open-by-handle, no linking them into the directory tree, and no feeding them to LSMs. As such, we mark them S_PRIVATE, which stops all that.
While we're at it, put them in a separate lockdep class so that it won't get confused by "recursive" i_rwsem locking such as what happens when we write to a rt file and need to allocate from the rt bitmap file.
--- fs/xfs/scrub/tempfile.c | 8 ++++++++ fs/xfs/xfs_iops.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-)
fs/xfs/scrub/tempfile.c +8 -0
@@ -805,6 +805,14 @@ xrep_is_tempfile( const struct xfs_inode *ip) {const struct inode *inode = &ip->i_vnode; +struct xfs_mount *mp = ip->i_mount; + +/* +* Files in the metadata directory tree also have S_PRIVATE set and +* IOP_XATTR unset, so we must distinguish them separately. +*/ +if (xfs_has_metadir (mp) && (ip->i_diflags2 &XFS_DIFLAG2_METADATA )) +return false;if (IS_PRIVATE (inode) && !(inode->i_opflags &IOP_XATTR ))return true;
fs/xfs/xfs_iops.c +32 -2
@@ -44,6 +44,15 @@static struct lock_class_key xfs_nondir_ilock_class;static struct lock_class_key xfs_dir_ilock_class; +/* +* Metadata directories and files are not exposed to userspace, which means +* that they never access any of the VFS IO locks and never experience page +* faults. Give them separate locking classes so that lockdep will not +* complain about conflicts that cannot happen. +*/ +static struct lock_class_key xfs_metadata_file_ilock_class; +static struct lock_class_key xfs_metadata_dir_ilock_class; + static int xfs_initxattrs( struct inode *inode,
@@ -1270,6 +1279,7 @@ xfs_setup_inode( {struct inode *inode = &ip->i_vnode;gfp_t gfp_mask; +bool is_meta =xfs_is_metadata_inode (ip); inode->i_ino = ip->i_ino; inode->i_state |=I_NEW ;
@@ -1281,6 +1291,16 @@ xfs_setup_inode(i_size_write (inode, ip->i_disk_size);xfs_diflags_to_iflags (ip, true); +/* +* Mark our metadata files as private so that LSMs and the ACL code +* don't try to add their own metadata or reason about these files, +* and users cannot ever obtain file handles to them. +*/ +if (is_meta) { + inode->i_flags |=S_PRIVATE ; + inode->i_opflags &= ~IOP_XATTR ; + } +if (S_ISDIR (inode->i_mode)) {/* * We set the i_rwsem class here to avoid potential races with
@@ -1290,9 +1310,19 @@ xfs_setup_inode(*/ lockdep_set_class (&inode->i_rwsem, &inode->i_sb->s_type->i_mutex_dir_key); -lockdep_set_class (&ip->i_lock.mr_lock, &xfs_dir_ilock_class); +if (is_meta) +lockdep_set_class (&ip->i_lock.mr_lock, + &xfs_metadata_dir_ilock_class); +else +lockdep_set_class (&ip->i_lock.mr_lock, + &xfs_dir_ilock_class); }else { -lockdep_set_class (&ip->i_lock.mr_lock, &xfs_nondir_ilock_class); +if (is_meta) +lockdep_set_class (&ip->i_lock.mr_lock, + &xfs_metadata_file_ilock_class); +else +lockdep_set_class (&ip->i_lock.mr_lock, + &xfs_nondir_ilock_class); }/*
PATCH 16/23 xfs: advertise metadata directory feature
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Advertise the existence of the metadata directory feature; this will be used by scrub to decide if it needs to scan the metadir too.
--- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/libxfs/xfs_sb.c | 2 ++ 2 files changed, 3 insertions(+)
fs/xfs/libxfs/xfs_fs.h +1 -0
@@ -239,6 +239,7 @@ typedef struct xfs_fsop_resblks {#define XFS_FSOP_GEOM_FLAGS_BIGTIME (1 << 21)/* 64-bit nsec timestamps */ #define XFS_FSOP_GEOM_FLAGS_INOBTCNT (1 << 22)/* inobt btree counter */ #define XFS_FSOP_GEOM_FLAGS_NREXT64 (1 << 23)/* large extent counters */ +#define XFS_FSOP_GEOM_FLAGS_METADIR (1 << 30)/* metadata directories */ #define XFS_FSOP_GEOM_FLAGS_ATOMIC_SWAP (1U << 31)/* atomic file extent swap */ /*
fs/xfs/libxfs/xfs_sb.c +2 -0
@@ -1233,6 +1233,8 @@ xfs_fs_geometry( geo->flags |=XFS_FSOP_GEOM_FLAGS_NREXT64 ;if (xfs_swapext_supported (mp)) geo->flags |=XFS_FSOP_GEOM_FLAGS_ATOMIC_SWAP ; +if (xfs_has_metadir (mp)) + geo->flags |=XFS_FSOP_GEOM_FLAGS_METADIR ; geo->rtsectsize = sbp->sb_blocksize; geo->dirblocksize =xfs_dir2_dirblock_bytes (sbp);
PATCH 17/23 xfs: allow bulkstat to return metadata directories
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Allow the V5 bulkstat ioctl to return information about metadata directory files so that xfs_scrub can find and scrub them, since they are otherwise ordinary directories.
(Metadata files of course require per-file scrub code and hence do not need exposure.)
--- fs/xfs/libxfs/xfs_fs.h | 10 +++++++++- fs/xfs/xfs_ioctl.c | 7 +++++++ fs/xfs/xfs_itable.c | 32 ++++++++++++++++++++++++++++---- fs/xfs/xfs_itable.h | 3 +++ 4 files changed, 47 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_fs.h +9 -1
@@ -485,9 +485,17 @@ struct xfs_bulk_ireq {*/ #define XFS_BULK_IREQ_NREXT64 (1U << 2) +/* +* Allow bulkstat to return information about metadata directories. This +* enables xfs_scrub to find them for scanning, as they are otherwise ordinary +* directories. +*/ +#define XFS_BULK_IREQ_METADIR (1U << 31) +#define XFS_BULK_IREQ_FLAGS_ALL (XFS_BULK_IREQ_AGNO | \ XFS_BULK_IREQ_SPECIAL | \ - XFS_BULK_IREQ_NREXT64) + XFS_BULK_IREQ_NREXT64 | \ + XFS_BULK_IREQ_METADIR)/* Operate on the root directory inode. */ #define XFS_BULK_IREQ_SPECIAL_ROOT (1)
fs/xfs/xfs_ioctl.c +7 -0
@@ -819,6 +819,10 @@ xfs_bulk_ireq_setup(if (hdr->flags &XFS_BULK_IREQ_NREXT64 ) breq->flags |=XFS_IBULK_NREXT64 ; +/* Caller wants to see metadata directories in bulkstat output. */ +if (hdr->flags &XFS_BULK_IREQ_METADIR ) + breq->flags |=XFS_IBULK_METADIR ; +return 0 ; }
@@ -909,6 +913,9 @@ xfs_ioc_inumbers(if (copy_from_user (&hdr, &arg->hdr,sizeof (hdr)))return -EFAULT ; +if (hdr.flags &XFS_BULK_IREQ_METADIR ) +return -EINVAL ; + error =xfs_bulk_ireq_setup (mp, &hdr, &breq, arg->inumbers);if (error == -ECANCELED ) goto out_teardown;
fs/xfs/xfs_itable.c +28 -4
@@ -36,6 +36,16 @@ struct xfs_bstat_chunk {struct xfs_bulkstat *buf; }; +static inline bool +want_metadir ( +struct xfs_inode *ip, +struct xfs_ibulk *breq) +{ +return xfs_is_metadata_inode (ip) && +S_ISDIR (VFS_I (ip)->i_mode) && + (breq->flags &XFS_IBULK_METADIR ); +} +/* * Fill out the bulkstat info for a single inode and report it somewhere. *
@@ -69,9 +79,6 @@ xfs_bulkstat_one_int(vfsuid_t vfsuid;vfsgid_t vfsgid; -if (xfs_internal_inum (mp, ino)) - goto out_advance; - error =xfs_iget (mp, tp, ino, (XFS_IGET_DONTCACHE |XFS_IGET_UNTRUSTED ),XFS_ILOCK_SHARED , &ip);
@@ -86,8 +93,25 @@ xfs_bulkstat_one_int( vfsuid =i_uid_into_vfsuid (mnt_userns, inode); vfsgid =i_gid_into_vfsgid (mnt_userns, inode); +/* If we want metadata directories, push out the bare minimum. */ +if (want_metadir (ip, bc->breq)) { +memset (buf,0 ,sizeof (*buf)); + buf->bs_ino = ino; + buf->bs_gen = inode->i_generation; + buf->bs_mode = inode->i_mode &S_IFMT ; +xfs_bulkstat_health (ip, buf); + buf->bs_version =XFS_BULKSTAT_VERSION_V5 ; +xfs_iunlock (ip,XFS_ILOCK_SHARED ); +xfs_irele (ip); + + error = bc->formatter (bc->breq, buf); +if (!error || error == -ECANCELED ) + goto out_advance; + goto out; + } +/* If this is a private inode, don't leak its details to userspace. */ -if (IS_PRIVATE (inode)) { +if (IS_PRIVATE (inode) ||xfs_internal_inum (mp, ino)) {xfs_iunlock (ip,XFS_ILOCK_SHARED );xfs_irele (ip); error = -EINVAL ;
fs/xfs/xfs_itable.h +3 -0
@@ -22,6 +22,9 @@ struct xfs_ibulk {/* Fill out the bs_extents64 field if set. */ #define XFS_IBULK_NREXT64 (1U << 1) +/* Signal that we can return metadata directories. */ +#define XFS_IBULK_METADIR (1U << 2) +/* * Advance the user buffer pointer by one record of the given size. If the * buffer is now full, return the appropriate error code.
PATCH 18/23 xfs: enable creation of dynamically allocated metadir path structures
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a few helper functions so that it's possible to allocate xfs_imeta_path objects dynamically, along with dynamically allocated path components. Eventually we're going to want to support paths of the form "/realtime/$rtgroup.rmap", and this is necessary for that.
--- fs/xfs/libxfs/xfs_imeta.c | 43 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_imeta.h | 8 ++++++++ 2 files changed, 51 insertions(+)
fs/xfs/libxfs/xfs_imeta.c +43 -0
@@ -1149,3 +1149,46 @@ xfs_imeta_lookup_update(return error; } + +/* Create a path to a file within the metadata directory tree. */ +int +xfs_imeta_create_file_path ( +struct xfs_mount *mp, +unsigned int nr_components, +struct xfs_imeta_path **pathp) +{ +struct xfs_imeta_path *p; +char **components; + + p =kmalloc (sizeof (struct xfs_imeta_path ),GFP_KERNEL ); +if (!p) +return -ENOMEM ; + + components =kvcalloc (nr_components,sizeof (char *),GFP_KERNEL ); +if (!components) { +kfree (p); +return -ENOMEM ; + } + + p->im_depth = nr_components; + p->im_path = (const char **)components; + p->im_ftype =XFS_DIR3_FT_REG_FILE ; + p->im_dynamicmask =0 ; + *pathp = p; +return 0 ; +} + +/* Free a metadata directory tree path. */ +void +xfs_imeta_free_path ( +struct xfs_imeta_path *path) +{ +unsigned int i; + +for (i =0 ; i < path->im_depth; i++) { +if ((path->im_dynamicmask & (1ULL << i)) && path->im_path[i]) +kfree (path->im_path[i]); + } +kfree (path->im_path); +kfree (path); +}
fs/xfs/libxfs/xfs_imeta.h +8 -0
@@ -15,6 +15,7 @@ const struct xfs_imeta_path name = { \ .im_path = (path), \ .im_ftype = XFS_DIR3_FT_REG_FILE, \ .im_depth = ARRAY_SIZE(path), \ + .im_dynamicmask = 0, \ }/* Key for looking up metadata inodes. */
@@ -27,6 +28,9 @@ struct xfs_imeta_path {/* Expected file type. */ unsigned int im_ftype; + +/* Each bit corresponds to an element of im_path needing to be freed */ +unsigned long long im_dynamicmask; };/* Cleanup widget for metadata inode creation and deletion. */
@@ -52,6 +56,10 @@ int xfs_imeta_lookup_update(struct xfs_mount *mp,const struct xfs_imeta_path *path, struct xfs_imeta_update *upd, xfs_ino_t *inop); +int xfs_imeta_create_file_path (struct xfs_mount *mp, +unsigned int nr_components,struct xfs_imeta_path **pathp); +void xfs_imeta_free_path (struct xfs_imeta_path *path); +void xfs_imeta_set_metaflag (struct xfs_trans *tp,struct xfs_inode *ip);/* Don't allocate quota for this file. */
PATCH 19/23 xfs: record health problems with the metadata directory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make a report to the health monitoring subsystem any time we encounter something in the metadata directory tree that looks like corruption.
--- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/libxfs/xfs_health.h | 4 +++- fs/xfs/libxfs/xfs_imeta.c | 28 ++++++++++++++++++++++------ fs/xfs/xfs_health.c | 1 + fs/xfs/xfs_icache.c | 1 + fs/xfs/xfs_inode.c | 1 + 6 files changed, 29 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_fs.h +1 -0
@@ -197,6 +197,7 @@ struct xfs_fsop_geom {#define XFS_FSOP_GEOM_SICK_RT_SUMMARY (1 << 5)/* realtime summary */ #define XFS_FSOP_GEOM_SICK_QUOTACHECK (1 << 6)/* quota counts */ #define XFS_FSOP_GEOM_SICK_NLINKS (1 << 7)/* inode link counts */ +#define XFS_FSOP_GEOM_SICK_METADIR (1 << 8)/* metadata directory */ /* Output for XFS_FS_COUNTS */ typedef struct xfs_fsop_counts {
fs/xfs/libxfs/xfs_health.h +3 -1
@@ -60,6 +60,7 @@ struct xfs_da_args;#define XFS_SICK_FS_PQUOTA (1 << 3)/* project quota */ #define XFS_SICK_FS_QUOTACHECK (1 << 4)/* quota counts */ #define XFS_SICK_FS_NLINKS (1 << 5)/* inode link counts */ +#define XFS_SICK_FS_METADIR (1 << 6)/* metadata directory tree */ /* Observable health issues for realtime volume metadata. */ #define XFS_SICK_RT_BITMAP (1 << 0)/* realtime bitmap */
@@ -96,7 +97,8 @@ struct xfs_da_args;XFS_SICK_FS_GQUOTA | \XFS_SICK_FS_PQUOTA | \XFS_SICK_FS_QUOTACHECK | \ - XFS_SICK_FS_NLINKS) +XFS_SICK_FS_NLINKS | \ + XFS_SICK_FS_METADIR) #define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \XFS_SICK_RT_SUMMARY )
fs/xfs/libxfs/xfs_imeta.c +22 -6
@@ -26,6 +26,7 @@#include "xfs_dir2.h" #include "xfs_dir2_priv.h" #include "xfs_ag.h" +#include "xfs_health.h" /* * Metadata Inode Number Management
@@ -405,16 +406,22 @@ xfs_imeta_dir_lookup_component(trace_xfs_imeta_dir_lookup_component (dp, xname,NULLFSINO ); -if (!S_ISDIR (VFS_I (dp)->i_mode)) +if (!S_ISDIR (VFS_I (dp)->i_mode)) { +xfs_fs_mark_sick (dp->i_mount,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + } error =xfs_imeta_dir_lookup (dp, xname, ino);if (error)return error; -if (!xfs_verify_ino (dp->i_mount, *ino)) +if (!xfs_verify_ino (dp->i_mount, *ino)) { +xfs_fs_mark_sick (dp->i_mount,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; -if (type_wanted !=XFS_DIR3_FT_UNKNOWN && xname->type != type_wanted) + } +if (type_wanted !=XFS_DIR3_FT_UNKNOWN && xname->type != type_wanted) { +xfs_fs_mark_sick (dp->i_mount,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + }trace_xfs_imeta_dir_lookup_found (dp, xname, *ino);return 0 ;
@@ -713,6 +720,7 @@ xfs_imeta_dir_unlink(/* Metadata directory root cannot be unlinked. */ if (xfs_imeta_path_compare (path, &XFS_IMETA_METADIR )) {ASSERT (0 ); +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; }
@@ -728,6 +736,7 @@ xfs_imeta_dir_unlink( error = -ENOENT ;break ;case -ENOENT : +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR ); error = -EFSCORRUPTED ;break ; }
@@ -779,6 +788,7 @@ xfs_imeta_dir_link(/* Metadata directory root cannot be linked. */ if (xfs_imeta_path_compare (path, &XFS_IMETA_METADIR )) {ASSERT (0 ); +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; }
@@ -856,16 +866,20 @@ xfs_imeta_lookup(if (xfs_has_metadir (mp)) { error =xfs_imeta_dir_lookup_int (mp, path, &ino); -if (error == -ENOENT ) +if (error == -ENOENT ) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + } }else { error =xfs_imeta_sb_lookup (mp, path, &ino); }if (error)return error; -if (!xfs_imeta_verify (mp, ino)) +if (!xfs_imeta_verify (mp, ino)) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + } *inop = ino;return 0 ;
@@ -1041,8 +1055,10 @@ xfs_imeta_start_update(* to exist. */ error =xfs_imeta_dir_parent (mp, path, &upd->dp); -if (error == -ENOENT ) +if (error == -ENOENT ) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + }if (error)return error;
fs/xfs/xfs_health.c +1 -0
@@ -360,6 +360,7 @@ static const struct ioctl_sick_map fs_map[] = { { XFS_SICK_FS_PQUOTA, XFS_FSOP_GEOM_SICK_PQUOTA }, { XFS_SICK_FS_QUOTACHECK, XFS_FSOP_GEOM_SICK_QUOTACHECK }, { XFS_SICK_FS_NLINKS, XFS_FSOP_GEOM_SICK_NLINKS }, + { XFS_SICK_FS_METADIR, XFS_FSOP_GEOM_SICK_METADIR }, { 0, 0 }, };
fs/xfs/xfs_icache.c +1 -0
@@ -940,6 +940,7 @@ xfs_imeta_iget(xfs_irele (ip); whine:xfs_err (mp,"metadata inode 0x%llx is corrupt" , ino); +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; }
fs/xfs/xfs_inode.c +1 -0
@@ -577,6 +577,7 @@ xfs_lookup(* metadata file. */ if (XFS_IS_CORRUPT (dp->i_mount,xfs_is_metadata_inode (*ipp))) { +xfs_fs_mark_sick (dp->i_mount,XFS_SICK_FS_METADIR ); error = -EFSCORRUPTED ; goto out_irele; }
PATCH 20/23 xfs: scrub metadata directories
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach online scrub about the metadata directory tree.
--- fs/xfs/scrub/dir.c | 9 +++++++++ fs/xfs/scrub/dir_repair.c | 6 ++++++ fs/xfs/scrub/parent.c | 18 ++++++++++++++++++ fs/xfs/scrub/parent_repair.c | 37 +++++++++++++++++++++++++++++++------ 4 files changed, 64 insertions(+), 6 deletions(-)
fs/xfs/scrub/dir.c +9 -0
@@ -59,6 +59,15 @@ xchk_dir_check_ftype(if (xfs_mode_to_ftype (VFS_I (ip)->i_mode) != ftype)xchk_fblock_set_corrupt (sc,XFS_DATA_FORK , offset); + +/* +* Metadata and regular inodes cannot cross trees. This property +* cannot change without a full inode free and realloc cycle, so it's +* safe to check this without holding locks. +*/ +if (xfs_is_metadata_inode (ip) ^xfs_is_metadata_inode (sc->ip)) +xchk_fblock_set_corrupt (sc,XFS_DATA_FORK , offset); + }/*
fs/xfs/scrub/dir_repair.c +6 -0
@@ -204,6 +204,12 @@ xrep_dir_salvage_entry(if (error)return 0 ; +/* Don't mix metadata and regular directory trees. */ +if (xfs_is_metadata_inode (ip) ^xfs_is_metadata_inode (rd->sc->ip)) { +xchk_irele (sc, ip); +return 0 ; + } + entry.ftype =xfs_mode_to_ftype (VFS_I (ip)->i_mode);xchk_irele (sc, ip);
fs/xfs/scrub/parent.c +18 -0
@@ -197,6 +197,16 @@ xchk_parent_validate( goto out_rele; } +/* +* Metadata and regular inodes cannot cross trees. This property +* cannot change without a full inode free and realloc cycle, so it's +* safe to check this without holding locks. +*/ +if (xfs_is_metadata_inode (dp) ^xfs_is_metadata_inode (sc->ip)) { +xchk_fblock_set_corrupt (sc,XFS_DATA_FORK ,0 ); + goto out_rele; + } +/* * We prefer to keep the inode locked while we lock and search its * alleged parent for a forward reference. If we can grab the iolock
@@ -302,5 +312,13 @@ xchk_parent(return 0 ; } +/* Is this the metadata root dir? Then '..' must point to itself. */ +if (sc->ip == mp->m_metadirip) { +if (sc->ip->i_ino != mp->m_sb.sb_metadirino || + sc->ip->i_ino != parent_ino) +xchk_fblock_set_corrupt (sc,XFS_DATA_FORK ,0 ); +return 0 ; + } +return xchk_parent_validate (sc, parent_ino); }
fs/xfs/scrub/parent_repair.c +31 -6
@@ -135,6 +135,10 @@ xrep_findparent_walk_directory(if (xrep_is_tempfile (dp))return 0 ; +/* Don't mix metadata and regular directory trees. */ +if (xfs_is_metadata_inode (dp) ^xfs_is_metadata_inode (sc->ip)) +return 0 ; +/* Try to lock dp; if we can, we're ready to scan! */ if (!xfs_ilock_nowait (dp,XFS_IOLOCK_SHARED )) {xfs_ino_t orig_parent, new_parent;
@@ -227,15 +231,30 @@ xrep_parent_confirm( };int error; -/* -* The root directory always points to itself. Unlinked dirs can point -* anywhere, so we point them at the root dir too. -*/ -if (sc->ip == sc->mp->m_rootip ||VFS_I (sc->ip)->i_nlink ==0 ) { +/* The root directory always points to itself. */ +if (sc->ip == sc->mp->m_rootip) { *parent_ino = sc->mp->m_sb.sb_rootino;return 0 ; } +/* The metadata root directory always points to itself. */ +if (sc->ip == sc->mp->m_metadirip) { + *parent_ino = sc->mp->m_sb.sb_metadirino; +return 0 ; + } + +/* +* Unlinked dirs can point anywhere, so we point them at the root dir +* of whichever tree is appropriate. +*/ +if (VFS_I (sc->ip)->i_nlink ==0 ) { +if (xfs_is_metadata_inode (sc->ip)) + *parent_ino = sc->mp->m_sb.sb_metadirino; +else + *parent_ino = sc->mp->m_sb.sb_rootino; +return 0 ; + } +/* Reject garbage parent inode numbers and self-referential parents. */ if (*parent_ino ==NULLFSINO )return 0 ;
@@ -389,8 +408,14 @@ xrep_parent_self_reference(if (sc->ip->i_ino == sc->mp->m_sb.sb_rootino)return sc->mp->m_sb.sb_rootino; -if (VFS_I (sc->ip)->i_nlink ==0 ) +if (sc->ip->i_ino == sc->mp->m_sb.sb_metadirino) +return sc->mp->m_sb.sb_metadirino; + +if (VFS_I (sc->ip)->i_nlink ==0 ) { +if (xfs_is_metadata_inode (sc->ip)) +return sc->mp->m_sb.sb_metadirino;return sc->mp->m_sb.sb_rootino; + }return NULLFSINO ; }
PATCH 21/23 xfs: teach nlink scrubber to deal with metadata directory roots
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enhance the inode link count online fsck code alter their behavior when they detect metadata directory tree roots, just like they do for the regular root directory.
--- fs/xfs/scrub/nlinks.c | 12 +++++++----- fs/xfs/scrub/nlinks_repair.c | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-)
fs/xfs/scrub/nlinks.c +7 -5
@@ -282,7 +282,7 @@ xchk_nlinks_collect_dirent(* Otherwise, increment the number of backrefs pointing back to ino. */ if (dotdot) { -if (dp == sc->mp->m_rootip) +if (dp == sc->mp->m_rootip || dp == sc->mp->m_metadirip) error =xchk_nlinks_update_incore (xnc, ino,1 ,0 ,0 );else error =xchk_nlinks_update_incore (xnc, ino,0 ,1 ,0 );
@@ -458,9 +458,11 @@ xchk_nlinks_collect(int error;/* Count the rt and quota files that are rooted in the superblock. */ - error =xchk_nlinks_collect_metafiles (xnc); -if (error) -return error; +if (!xfs_has_metadir (sc->mp)) { + error =xchk_nlinks_collect_metafiles (xnc); +if (error) +return error; + }/* * Set up for a potentially lengthy filesystem scan by reducing our
@@ -648,7 +650,7 @@ xchk_nlinks_compare_inode(xchk_ino_set_corrupt (sc, ip->i_ino); } -if (ip == sc->mp->m_rootip) { +if (ip == sc->mp->m_rootip || ip == sc->mp->m_metadirip) {/* * For the root of a directory tree, both the '.' and '..' * entries should point to the root directory. The dot entry
fs/xfs/scrub/nlinks_repair.c +1 -1
@@ -86,7 +86,7 @@ xrep_nlinks_is_orphaned(if (obs->parents !=0 )return false; -if (ip == mp->m_rootip || ip == sc->orphanage) +if (ip == mp->m_rootip || ip == sc->orphanage || ip == mp->m_metadirip)return false;return actual_nlink !=0 ; }
PATCH 22/23 xfs: don't check secondary super inode pointers when metadir enabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When metadata directories are enabled, the rt and quota inodes are no longer pointed to by the superblock, so it doesn't make sense to check these.
--- fs/xfs/scrub/agheader.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
fs/xfs/scrub/agheader.c +19 -10
@@ -144,11 +144,16 @@ xchk_superblock(if (sb->sb_rootino !=cpu_to_be64 (mp->m_sb.sb_rootino))xchk_block_set_preen (sc, bp); -if (sb->sb_rbmino !=cpu_to_be64 (mp->m_sb.sb_rbmino)) -xchk_block_set_preen (sc, bp); +if (xfs_has_metadir (sc->mp)) { +if (sb->sb_rbmino !=cpu_to_be64 (mp->m_sb.sb_metadirino)) +xchk_block_set_preen (sc, bp); + }else { +if (sb->sb_rbmino !=cpu_to_be64 (mp->m_sb.sb_rbmino)) +xchk_block_set_preen (sc, bp); -if (sb->sb_rsumino !=cpu_to_be64 (mp->m_sb.sb_rsumino)) -xchk_block_set_preen (sc, bp); +if (sb->sb_rsumino !=cpu_to_be64 (mp->m_sb.sb_rsumino)) +xchk_block_set_preen (sc, bp); + }if (sb->sb_rextsize !=cpu_to_be32 (mp->m_sb.sb_rextsize))xchk_block_set_corrupt (sc, bp);
@@ -225,11 +230,13 @@ xchk_superblock(* sb_icount, sb_ifree, sb_fdblocks, sb_frexents */ -if (sb->sb_uquotino !=cpu_to_be64 (mp->m_sb.sb_uquotino)) -xchk_block_set_preen (sc, bp); +if (!xfs_has_metadir (sc->mp)) { +if (sb->sb_uquotino !=cpu_to_be64 (mp->m_sb.sb_uquotino)) +xchk_block_set_preen (sc, bp); -if (sb->sb_gquotino !=cpu_to_be64 (mp->m_sb.sb_gquotino)) -xchk_block_set_preen (sc, bp); +if (sb->sb_gquotino !=cpu_to_be64 (mp->m_sb.sb_gquotino)) +xchk_block_set_preen (sc, bp); + }/* * Skip the quota flags since repair will force quotacheck.
@@ -338,8 +345,10 @@ xchk_superblock(if (sb->sb_spino_align !=cpu_to_be32 (mp->m_sb.sb_spino_align))xchk_block_set_corrupt (sc, bp); -if (sb->sb_pquotino !=cpu_to_be64 (mp->m_sb.sb_pquotino)) -xchk_block_set_preen (sc, bp); +if (!xfs_has_metadir (sc->mp)) { +if (sb->sb_pquotino !=cpu_to_be64 (mp->m_sb.sb_pquotino)) +xchk_block_set_preen (sc, bp); + }/* Don't care about sb_lsn */ }
PATCH 23/23 xfs: enable metadata directory feature
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable the metadata directory feature.
--- fs/xfs/libxfs/xfs_format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_format.h +2 -1
@@ -396,7 +396,8 @@ xfs_sb_has_ro_compat_feature( XFS_SB_FEAT_INCOMPAT_META_UUID| \ XFS_SB_FEAT_INCOMPAT_BIGTIME| \ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR| \ - XFS_SB_FEAT_INCOMPAT_NREXT64) + XFS_SB_FEAT_INCOMPAT_NREXT64 | \ + XFS_SB_FEAT_INCOMPAT_METADIR)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool
cover xfs: refactor btrees to support records in inode root
In reply to Darrick J. WongHi all,
This series prepares the btree code to support realtime reverse mapping btrees by refactoring xfs_ifork_realloc to be fed a per-btree ops structure so that it can handle multiple types of inode-rooted btrees. It moves on to refactoring the btree code to use the new realloc routines and to support storing btree rcords in the inode root, because the current bmbt code does not support this.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. 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=btree-ifork-records
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=btree-ifork-records
--- fs/xfs/libxfs/xfs_alloc_btree.c | 6 - fs/xfs/libxfs/xfs_alloc_btree.h | 3 fs/xfs/libxfs/xfs_attr_leaf.c | 8 - fs/xfs/libxfs/xfs_bmap.c | 59 ++---- fs/xfs/libxfs/xfs_bmap_btree.c | 93 ++++++++- fs/xfs/libxfs/xfs_bmap_btree.h | 219 +++++++++++++++------ fs/xfs/libxfs/xfs_btree.c | 382 ++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_btree.h | 4 fs/xfs/libxfs/xfs_btree_staging.c | 4 fs/xfs/libxfs/xfs_ialloc.c | 4 fs/xfs/libxfs/xfs_ialloc_btree.c | 6 - fs/xfs/libxfs/xfs_ialloc_btree.h | 3 fs/xfs/libxfs/xfs_inode_fork.c | 163 +++++++-------- fs/xfs/libxfs/xfs_inode_fork.h | 27 ++- fs/xfs/libxfs/xfs_refcount_btree.c | 5 fs/xfs/libxfs/xfs_refcount_btree.h | 3 fs/xfs/libxfs/xfs_rmap_btree.c | 9 - fs/xfs/libxfs/xfs_rmap_btree.h | 3 fs/xfs/libxfs/xfs_sb.c | 16 +- fs/xfs/libxfs/xfs_trans_resv.c | 2 fs/xfs/scrub/bmap_repair.c | 2 fs/xfs/scrub/inode_repair.c | 8 - fs/xfs/xfs_xchgrange.c | 4 23 files changed, 705 insertions(+), 328 deletions(-)
PATCH 1/14 xfs: replace shouty XFS_BM{BT,DR} macros
From: Darrick J. Wong <[email protected]>
Replace all the shouty bmap btree and bmap disk root macros with actual functions, and fix a type handling error in the xattr code that the macros previously didn't care about.
--- fs/xfs/libxfs/xfs_attr_leaf.c | 8 +- fs/xfs/libxfs/xfs_bmap.c | 40 ++++---- fs/xfs/libxfs/xfs_bmap_btree.c | 18 ++-- fs/xfs/libxfs/xfs_bmap_btree.h | 204 +++++++++++++++++++++++++++------------- fs/xfs/libxfs/xfs_inode_fork.c | 30 +++--- fs/xfs/libxfs/xfs_trans_resv.c | 2 fs/xfs/scrub/bmap_repair.c | 2 fs/xfs/scrub/inode_repair.c | 8 +- fs/xfs/xfs_xchgrange.c | 4 - 9 files changed, 196 insertions(+), 120 deletions(-)
fs/xfs/libxfs/xfs_attr_leaf.c +4 -4
@@ -649,7 +649,7 @@ xfs_attr_shortform_bytesfit(*/ if (!dp->i_forkoff && dp->i_df.if_bytes >xfs_default_attroffset (dp)) - dsize =XFS_BMDR_SPACE_CALC (MINDBTPTRS ); + dsize =xfs_bmdr_space_calc (MINDBTPTRS );break ;case XFS_DINODE_FMT_BTREE :/*
@@ -663,7 +663,7 @@ xfs_attr_shortform_bytesfit(return 0 ;return dp->i_forkoff; } - dsize =XFS_BMAP_BROOT_SPACE (mp, dp->i_df.if_broot); + dsize =xfs_bmap_bmdr_space (dp->i_df.if_broot);break ; }
@@ -671,11 +671,11 @@ xfs_attr_shortform_bytesfit(* A data fork btree root must have space for at least * MINDBTPTRS key/ptr pairs if the data fork is small or empty. */ - minforkoff =max_t (int64_t, dsize,XFS_BMDR_SPACE_CALC (MINDBTPTRS )); + minforkoff =max_t (int64_t, dsize,xfs_bmdr_space_calc (MINDBTPTRS )); minforkoff =roundup (minforkoff,8 ) >>3 ;/* attr fork btree root can have at least this many key/ptr pairs */ - maxforkoff =XFS_LITINO (mp) -XFS_BMDR_SPACE_CALC (MINABTPTRS ); + maxforkoff =XFS_LITINO (mp) -xfs_bmdr_space_calc (MINABTPTRS ); maxforkoff = maxforkoff >>3 ;/* rounded down */ if (offset >= maxforkoff)
fs/xfs/libxfs/xfs_bmap.c +20 -20
@@ -78,9 +78,9 @@ xfs_bmap_compute_maxlevels( maxleafents =xfs_iext_max_nextents (xfs_has_large_extent_counts (mp), whichfork);if (whichfork ==XFS_DATA_FORK ) - sz =XFS_BMDR_SPACE_CALC (MINDBTPTRS ); + sz =xfs_bmdr_space_calc (MINDBTPTRS );else - sz =XFS_BMDR_SPACE_CALC (MINABTPTRS ); + sz =xfs_bmdr_space_calc (MINABTPTRS ); maxrootrecs =xfs_bmdr_maxrecs (sz,0 ); minleafrecs = mp->m_bmap_dmnr[0 ];
@@ -101,8 +101,8 @@ xfs_bmap_compute_attr_offset( struct xfs_mount *mp) {if (mp->m_sb.sb_inodesize ==256 ) -return XFS_LITINO (mp) -XFS_BMDR_SPACE_CALC (MINABTPTRS ); -return XFS_BMDR_SPACE_CALC (6 *MINABTPTRS ); +return XFS_LITINO (mp) -xfs_bmdr_space_calc (MINABTPTRS ); +return xfs_bmdr_space_calc (6 *MINABTPTRS ); }STATIC int/* error */
@@ -275,7 +275,7 @@ xfs_check_block( prevp =NULL ;for ( i =1 ; i <=xfs_btree_get_numrecs (block); i++) { dmxr = mp->m_bmap_dmxr[0 ]; - keyp =XFS_BMBT_KEY_ADDR (mp, block, i); + keyp =xfs_bmbt_key_addr (mp, block, i);if (prevp) { ASSERT(be64_to_cpu(prevp->br_startoff) <
@@ -287,15 +287,15 @@ xfs_check_block(* Compare the block numbers to see if there are dups. */ if (root) - pp =XFS_BMAP_BROOT_PTR_ADDR (mp, block, i, sz); + pp =xfs_bmap_broot_ptr_addr (mp, block, i, sz);else - pp =XFS_BMBT_PTR_ADDR (mp, block, i, dmxr); + pp =xfs_bmbt_ptr_addr (mp, block, i, dmxr);for (j = i+1 ; j <=be16_to_cpu (block->bb_numrecs); j++) {if (root) - thispa =XFS_BMAP_BROOT_PTR_ADDR (mp, block, j, sz); + thispa =xfs_bmap_broot_ptr_addr (mp, block, j, sz);else - thispa =XFS_BMBT_PTR_ADDR (mp, block, j, dmxr); + thispa =xfs_bmbt_ptr_addr (mp, block, j, dmxr);if (*thispa == *pp) { xfs_warn(mp, "%s: thispa(%d) == pp(%d) %lld", __func__, j, i,
@@ -350,7 +350,7 @@ xfs_bmap_check_leaf_extents( level =be16_to_cpu (block->bb_level);ASSERT (level >0 );xfs_check_block (block, mp,1 , ifp->if_broot_bytes); - pp =XFS_BMAP_BROOT_PTR_ADDR (mp, block,1 , ifp->if_broot_bytes); + pp =xfs_bmap_broot_ptr_addr (mp, block,1 , ifp->if_broot_bytes); bno =be64_to_cpu (*pp);ASSERT (bno !=NULLFSBLOCK );
@@ -385,7 +385,7 @@ xfs_bmap_check_leaf_extents(*/ xfs_check_block (block, mp,0 ,0 ); - pp =XFS_BMBT_PTR_ADDR (mp, block,1 , mp->m_bmap_dmxr[1 ]); + pp =xfs_bmbt_ptr_addr (mp, block,1 , mp->m_bmap_dmxr[1 ]); bno =be64_to_cpu (*pp);if (XFS_IS_CORRUPT (mp, !xfs_verify_fsbno (mp, bno))) {xfs_btree_mark_sick (cur);
@@ -425,14 +425,14 @@ xfs_bmap_check_leaf_extents(* conform with the first entry in this one. */ - ep =XFS_BMBT_REC_ADDR (mp, block,1 ); + ep =xfs_bmbt_rec_addr (mp, block,1 );if (i) {ASSERT (xfs_bmbt_disk_get_startoff (&last) +xfs_bmbt_disk_get_blockcount (&last) <=xfs_bmbt_disk_get_startoff (ep)); }for (j =1 ; j < num_recs; j++) { - nextp =XFS_BMBT_REC_ADDR (mp, block, j +1 ); + nextp =xfs_bmbt_rec_addr (mp, block, j +1 );ASSERT (xfs_bmbt_disk_get_startoff (ep) +xfs_bmbt_disk_get_blockcount (ep) <=xfs_bmbt_disk_get_startoff (nextp));
@@ -567,7 +567,7 @@ xfs_bmap_btree_to_extents(ASSERT (be16_to_cpu (rblock->bb_numrecs) ==1 );ASSERT (xfs_bmbt_maxrecs (mp, ifp->if_broot_bytes,0 ) ==1 ); - pp =XFS_BMAP_BROOT_PTR_ADDR (mp, rblock,1 , ifp->if_broot_bytes); + pp =xfs_bmap_broot_ptr_addr (mp, rblock,1 , ifp->if_broot_bytes); cbno =be64_to_cpu (*pp);#ifdef DEBUG if (XFS_IS_CORRUPT (cur->bc_mp, !xfs_btree_check_lptr (cur, cbno,1 ))) {
@@ -701,7 +701,7 @@ xfs_bmap_extents_to_btree(for_each_xfs_iext (ifp, &icur, &rec) {if (isnullstartblock (rec.br_startblock))continue ; - arp =XFS_BMBT_REC_ADDR (mp, ablock,1 + cnt); + arp =xfs_bmbt_rec_addr (mp, ablock,1 + cnt);xfs_bmbt_disk_set_all (arp, &rec); cnt++; }
@@ -711,10 +711,10 @@ xfs_bmap_extents_to_btree(/* * Fill in the root key and pointer. */ - kp =XFS_BMBT_KEY_ADDR (mp, block,1 ); - arp =XFS_BMBT_REC_ADDR (mp, ablock,1 ); + kp =xfs_bmbt_key_addr (mp, block,1 ); + arp =xfs_bmbt_rec_addr (mp, ablock,1 ); kp->br_startoff =cpu_to_be64 (xfs_bmbt_disk_get_startoff (arp)); - pp =XFS_BMBT_PTR_ADDR (mp, block,1 ,xfs_bmbt_get_maxrecs (cur, + pp =xfs_bmbt_ptr_addr (mp, block,1 ,xfs_bmbt_get_maxrecs (cur,be16_to_cpu (block->bb_level))); *pp =cpu_to_be64 (args.fsbno);
@@ -888,7 +888,7 @@ xfs_bmap_add_attrfork_btree( mp = ip->i_mount; -if (XFS_BMAP_BMDR_SPACE (block) <=xfs_inode_data_fork_size (ip)) +if (xfs_bmap_bmdr_space (block) <=xfs_inode_data_fork_size (ip)) *flags |=XFS_ILOG_DBROOT ;else { cur =xfs_bmbt_init_cursor (mp, tp, ip,XFS_DATA_FORK );
@@ -1170,7 +1170,7 @@ xfs_iread_bmbt_block( }/* Copy records into the incore cache. */ - frp =XFS_BMBT_REC_ADDR (mp, block,1 ); + frp =xfs_bmbt_rec_addr (mp, block,1 );for (j =0 ; j < num_recs; j++, frp++, ir->loaded++) {struct xfs_bmbt_irec new;xfs_failaddr_t fa;
fs/xfs/libxfs/xfs_bmap_btree.c +9 -9
@@ -48,10 +48,10 @@ xfs_bmdr_to_bmbt(ASSERT (be16_to_cpu (rblock->bb_level) >0 ); rblock->bb_numrecs = dblock->bb_numrecs; dmxr =xfs_bmdr_maxrecs (dblocklen,0 ); - fkp =XFS_BMDR_KEY_ADDR (dblock,1 ); - tkp =XFS_BMBT_KEY_ADDR (mp, rblock,1 ); - fpp =XFS_BMDR_PTR_ADDR (dblock,1 , dmxr); - tpp =XFS_BMAP_BROOT_PTR_ADDR (mp, rblock,1 , rblocklen); + fkp =xfs_bmdr_key_addr (dblock,1 ); + tkp =xfs_bmbt_key_addr (mp, rblock,1 ); + fpp =xfs_bmdr_ptr_addr (dblock,1 , dmxr); + tpp =xfs_bmap_broot_ptr_addr (mp, rblock,1 , rblocklen); dmxr =be16_to_cpu (dblock->bb_numrecs);memcpy (tkp, fkp,sizeof (*fkp) * dmxr);memcpy (tpp, fpp,sizeof (*fpp) * dmxr);
@@ -151,10 +151,10 @@ xfs_bmbt_to_bmdr( dblock->bb_level = rblock->bb_level; dblock->bb_numrecs = rblock->bb_numrecs; dmxr =xfs_bmdr_maxrecs (dblocklen,0 ); - fkp =XFS_BMBT_KEY_ADDR (mp, rblock,1 ); - tkp =XFS_BMDR_KEY_ADDR (dblock,1 ); - fpp =XFS_BMAP_BROOT_PTR_ADDR (mp, rblock,1 , rblocklen); - tpp =XFS_BMDR_PTR_ADDR (dblock,1 , dmxr); + fkp =xfs_bmbt_key_addr (mp, rblock,1 ); + tkp =xfs_bmdr_key_addr (dblock,1 ); + fpp =xfs_bmap_broot_ptr_addr (mp, rblock,1 , rblocklen); + tpp =xfs_bmdr_ptr_addr (dblock,1 , dmxr); dmxr =be16_to_cpu (dblock->bb_numrecs);memcpy (tkp, fkp,sizeof (*fkp) * dmxr);memcpy (tpp, fpp,sizeof (*fpp) * dmxr);
@@ -688,7 +688,7 @@ xfs_bmbt_maxrecs( int blocklen, int leaf) { - blocklen -=XFS_BMBT_BLOCK_LEN (mp); + blocklen -=xfs_bmbt_block_len (mp);return xfs_bmbt_block_maxrecs (blocklen, leaf); }
fs/xfs/libxfs/xfs_bmap_btree.h +140 -64
214 lines not on this page · raw message
fs/xfs/libxfs/xfs_inode_fork.c +15 -15
@@ -181,7 +181,7 @@ xfs_iformat_btree( ifp =xfs_ifork_ptr (ip, whichfork); dfp = (xfs_bmdr_block_t *)XFS_DFORK_PTR (dip, whichfork); - size =XFS_BMAP_BROOT_SPACE (mp, dfp); + size =xfs_bmap_broot_space (mp, dfp); nrecs =be16_to_cpu (dfp->bb_numrecs); level =be16_to_cpu (dfp->bb_level);
@@ -194,7 +194,7 @@ xfs_iformat_btree(*/ if (unlikely (ifp->if_nextents <=XFS_IFORK_MAXEXT (ip, whichfork) || nrecs ==0 || -XFS_BMDR_SPACE_CALC (nrecs) > +xfs_bmdr_space_calc (nrecs) >XFS_DFORK_SIZE (dip, mp, whichfork) || ifp->if_nextents > ip->i_nblocks) || level ==0 || level >XFS_BM_MAXLEVELS (mp, whichfork)) {
@@ -391,7 +391,7 @@ xfs_iroot_realloc(* allocate it now and get out. */ if (ifp->if_broot_bytes ==0 ) { - new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, rec_diff); + new_size =xfs_bmap_broot_space_calc (mp, rec_diff); ifp->if_broot =kmem_alloc (new_size,KM_NOFS ); ifp->if_broot_bytes = (int )new_size;return ;
@@ -405,15 +405,15 @@ xfs_iroot_realloc(*/ cur_max =xfs_bmbt_maxrecs (mp, ifp->if_broot_bytes,0 ); new_max = cur_max + rec_diff; - new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, new_max); + new_size =xfs_bmap_broot_space_calc (mp, new_max); ifp->if_broot =krealloc (ifp->if_broot, new_size,GFP_NOFS | __GFP_NOFAIL); - op = (char *)XFS_BMAP_BROOT_PTR_ADDR (mp, ifp->if_broot,1 , + op = (char *)xfs_bmap_broot_ptr_addr (mp, ifp->if_broot,1 , ifp->if_broot_bytes); - np = (char *)XFS_BMAP_BROOT_PTR_ADDR (mp, ifp->if_broot,1 , + np = (char *)xfs_bmap_broot_ptr_addr (mp, ifp->if_broot,1 , (int )new_size); ifp->if_broot_bytes = (int )new_size; -ASSERT (XFS_BMAP_BMDR_SPACE (ifp->if_broot) <= +ASSERT (xfs_bmap_bmdr_space (ifp->if_broot) <=xfs_inode_fork_size (ip, whichfork));memmove (np, op, cur_max * (uint )sizeof (xfs_fsblock_t));return ;
@@ -429,7 +429,7 @@ xfs_iroot_realloc( new_max = cur_max + rec_diff;ASSERT (new_max >=0 );if (new_max >0 ) - new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, new_max); + new_size =xfs_bmap_broot_space_calc (mp, new_max);else new_size =0 ;if (new_size >0 ) {
@@ -438,7 +438,7 @@ xfs_iroot_realloc(* First copy over the btree block header. */ memcpy (new_broot, ifp->if_broot, -XFS_BMBT_BLOCK_LEN (ip->i_mount)); +xfs_bmbt_block_len (ip->i_mount)); }else { new_broot =NULL ; }
@@ -450,16 +450,16 @@ xfs_iroot_realloc(/* * First copy the records. */ - op = (char *)XFS_BMBT_REC_ADDR (mp, ifp->if_broot,1 ); - np = (char *)XFS_BMBT_REC_ADDR (mp, new_broot,1 ); + op = (char *)xfs_bmbt_rec_addr (mp, ifp->if_broot,1 ); + np = (char *)xfs_bmbt_rec_addr (mp, new_broot,1 );memcpy (np, op, new_max * (uint )sizeof (xfs_bmbt_rec_t));/* * Then copy the pointers. */ - op = (char *)XFS_BMAP_BROOT_PTR_ADDR (mp, ifp->if_broot,1 , + op = (char *)xfs_bmap_broot_ptr_addr (mp, ifp->if_broot,1 , ifp->if_broot_bytes); - np = (char *)XFS_BMAP_BROOT_PTR_ADDR (mp, new_broot,1 , + np = (char *)xfs_bmap_broot_ptr_addr (mp, new_broot,1 , (int )new_size);memcpy (np, op, new_max * (uint )sizeof (xfs_fsblock_t)); }
@@ -467,7 +467,7 @@ xfs_iroot_realloc( ifp->if_broot = new_broot; ifp->if_broot_bytes = (int )new_size;if (ifp->if_broot) -ASSERT (XFS_BMAP_BMDR_SPACE (ifp->if_broot) <= +ASSERT (xfs_bmap_bmdr_space (ifp->if_broot) <=xfs_inode_fork_size (ip, whichfork));return ; }
@@ -640,7 +640,7 @@ xfs_iflush_fork(if ((iip->ili_fields & brootflag[whichfork]) && (ifp->if_broot_bytes >0 )) {ASSERT (ifp->if_broot !=NULL ); -ASSERT (XFS_BMAP_BMDR_SPACE (ifp->if_broot) <= +ASSERT (xfs_bmap_bmdr_space (ifp->if_broot) <=xfs_inode_fork_size (ip, whichfork)); xfs_bmbt_to_bmdr(mp, ifp->if_broot, ifp->if_broot_bytes, (xfs_bmdr_block_t *)cp,
fs/xfs/libxfs/xfs_trans_resv.c +1 -1
@@ -128,7 +128,7 @@ xfs_calc_inode_res( (4 *sizeof (struct xlog_op_header ) +sizeof (struct xfs_inode_log_format ) + mp->m_sb.sb_inodesize + -2 *XFS_BMBT_BLOCK_LEN (mp)); +2 *xfs_bmbt_block_len (mp)); }/*
fs/xfs/scrub/bmap_repair.c +1 -1
@@ -437,7 +437,7 @@ xrep_bmap_iroot_size( {ASSERT (level >0 ); -return XFS_BMAP_BROOT_SPACE_CALC (cur->bc_mp, nr_this_level); +return xfs_bmap_broot_space_calc (cur->bc_mp, nr_this_level); }/* Update the inode counters. */
fs/xfs/scrub/inode_repair.c +4 -4
@@ -701,7 +701,7 @@ xrep_dinode_bad_btree_fork( nrecs =be16_to_cpu (dfp->bb_numrecs); level =be16_to_cpu (dfp->bb_level); -if (nrecs ==0 ||XFS_BMDR_SPACE_CALC (nrecs) > dfork_size) +if (nrecs ==0 ||xfs_bmdr_space_calc (nrecs) > dfork_size)return true;if (level ==0 || level >=XFS_BM_MAXLEVELS (sc->mp, whichfork))return true;
@@ -919,7 +919,7 @@ xrep_dinode_ensure_forkoff(struct xfs_bmdr_block *bmdr;struct xfs_scrub *sc = ri->sc;xfs_extnum_t attr_extents, data_extents; -size_t bmdr_minsz =XFS_BMDR_SPACE_CALC (1 ); +size_t bmdr_minsz =xfs_bmdr_space_calc (1 );unsigned int lit_sz =XFS_LITINO (sc->mp);unsigned int afork_min, dfork_min;
@@ -971,7 +971,7 @@ xrep_dinode_ensure_forkoff(case XFS_DINODE_FMT_BTREE :/* Must have space for btree header and key/pointers. */ bmdr =XFS_DFORK_PTR (dip,XFS_ATTR_FORK ); - afork_min =XFS_BMAP_BROOT_SPACE (sc->mp, bmdr); + afork_min =xfs_bmap_broot_space (sc->mp, bmdr);break ;default :/* We should never see any other formats. */
@@ -1021,7 +1021,7 @@ xrep_dinode_ensure_forkoff(case XFS_DINODE_FMT_BTREE :/* Must have space for btree header and key/pointers. */ bmdr =XFS_DFORK_PTR (dip,XFS_DATA_FORK ); - dfork_min =XFS_BMAP_BROOT_SPACE (sc->mp, bmdr); + dfork_min =xfs_bmap_broot_space (sc->mp, bmdr);break ;default : dfork_min =0 ;
fs/xfs/xfs_xchgrange.c +2 -2
@@ -163,7 +163,7 @@ xfs_swap_extents_check_format(*/ if (tifp->if_format ==XFS_DINODE_FMT_BTREE ) {if (xfs_inode_has_attr_fork (ip) && -XFS_BMAP_BMDR_SPACE (tifp->if_broot) >xfs_inode_fork_boff (ip)) +xfs_bmap_bmdr_space (tifp->if_broot) >xfs_inode_fork_boff (ip))return -EINVAL ;if (tifp->if_nextents <=XFS_IFORK_MAXEXT (ip,XFS_DATA_FORK ))return -EINVAL ;
@@ -172,7 +172,7 @@ xfs_swap_extents_check_format(/* Reciprocal target->temp btree format checks */ if (ifp->if_format ==XFS_DINODE_FMT_BTREE ) {if (xfs_inode_has_attr_fork (tip) && -XFS_BMAP_BMDR_SPACE (ip->i_df.if_broot) >xfs_inode_fork_boff (tip)) +xfs_bmap_bmdr_space (ip->i_df.if_broot) >xfs_inode_fork_boff (tip))return -EINVAL ;if (ifp->if_nextents <=XFS_IFORK_MAXEXT (tip,XFS_DATA_FORK ))return -EINVAL ;
PATCH 2/14 xfs: refactor the allocation and freeing of incore inode fork btree roots
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Refactor the code that allocates and freese the incore inode fork btree roots. This will help us disentangle some of the weird logic when we're creating and tearing down inode-based btrees.
--- fs/xfs/libxfs/xfs_inode_fork.c | 53 ++++++++++++++++++++++++++++------------ fs/xfs/libxfs/xfs_inode_fork.h | 3 ++ 2 files changed, 40 insertions(+), 16 deletions(-)
fs/xfs/libxfs/xfs_inode_fork.c +37 -16
@@ -207,8 +207,7 @@ xfs_iformat_btree(return -EFSCORRUPTED ; } - ifp->if_broot_bytes = size; - ifp->if_broot =kmem_alloc (size,KM_NOFS ); +xfs_iroot_alloc (ip, whichfork, size);ASSERT (ifp->if_broot !=NULL );/* * Copy and convert from the on-disk structure
@@ -344,6 +343,32 @@ xfs_iformat_attr_fork(return error; } +/* Allocate a new incore ifork btree root. */ +void +xfs_iroot_alloc ( +struct xfs_inode *ip, +int whichfork, +size_t bytes) +{ +struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork); + + ifp->if_broot =kmem_alloc (bytes,KM_NOFS ); + ifp->if_broot_bytes = bytes; +} + +/* Free all the memory and state associated with an incore ifork btree root. */ +void +xfs_iroot_free ( +struct xfs_inode *ip, +int whichfork) +{ +struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork); + + ifp->if_broot_bytes =0 ; +kmem_free (ifp->if_broot); + ifp->if_broot =NULL ; +} +/* * Reallocate the space for if_broot based on the number of records * being added or deleted as indicated in rec_diff. Move the records
@@ -392,8 +417,7 @@ xfs_iroot_realloc(*/ if (ifp->if_broot_bytes ==0 ) { new_size =xfs_bmap_broot_space_calc (mp, rec_diff); - ifp->if_broot =kmem_alloc (new_size,KM_NOFS ); - ifp->if_broot_bytes = (int )new_size; +xfs_iroot_alloc (ip, whichfork, new_size);return ; }
@@ -432,17 +456,15 @@ xfs_iroot_realloc( new_size =xfs_bmap_broot_space_calc (mp, new_max); else new_size =0 ; -if (new_size >0 ) { - new_broot =kmem_alloc (new_size,KM_NOFS ); -/* -* First copy over the btree block header. -*/ -memcpy (new_broot, ifp->if_broot, -xfs_bmbt_block_len (ip->i_mount)); - }else { - new_broot =NULL ; +if (new_size ==0 ) { +xfs_iroot_free (ip, whichfork); +return ; } +/* First copy over the btree block header. */ + new_broot =kmem_alloc (new_size,KM_NOFS ); +memcpy (new_broot, ifp->if_broot,xfs_bmbt_block_len (ip->i_mount)); +/* * Only copy the records and pointers if there are any. */
@@ -466,9 +488,8 @@ xfs_iroot_realloc(kmem_free (ifp->if_broot); ifp->if_broot = new_broot; ifp->if_broot_bytes = (int )new_size; -if (ifp->if_broot) -ASSERT (xfs_bmap_bmdr_space (ifp->if_broot) <= -xfs_inode_fork_size (ip, whichfork)); +ASSERT (xfs_bmap_bmdr_space (ifp->if_broot) <= +xfs_inode_fork_size (ip, whichfork));return ; }
fs/xfs/libxfs/xfs_inode_fork.h +3 -0
@@ -171,6 +171,9 @@ void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,void xfs_idestroy_fork (struct xfs_ifork *ifp);void xfs_idata_realloc (struct xfs_inode *ip,int64_t byte_diff,int whichfork); +void xfs_iroot_alloc (struct xfs_inode *ip,int whichfork, +size_t bytes); +void xfs_iroot_free (struct xfs_inode *ip,int whichfork);void xfs_iroot_realloc (struct xfs_inode *,int ,int );int xfs_iread_extents (struct xfs_trans *,struct xfs_inode *,int ); int xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,
PATCH 3/14 xfs: refactor creation of bmap btree roots
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that we've created inode fork helpers to allocate and free btree roots, create a new bmap btree helper to create a new bmbt root, and refactor the extents <-> btree conversion functions to use our new helpers.
--- fs/xfs/libxfs/xfs_bmap.c | 17 ++++------------- fs/xfs/libxfs/xfs_bmap_btree.c | 16 ++++++++++++++++ fs/xfs/libxfs/xfs_bmap_btree.h | 2 ++ 3 files changed, 22 insertions(+), 13 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +4 -13
@@ -591,7 +591,7 @@ xfs_bmap_btree_to_extents(xfs_trans_binval (tp, cbp);if (cur->bc_levels[0 ].bp == cbp) cur->bc_levels[0 ].bp =NULL ; -xfs_iroot_realloc (ip,-1 , whichfork); +xfs_iroot_free (ip, whichfork);ASSERT (ifp->if_broot ==NULL ); ifp->if_format =XFS_DINODE_FMT_EXTENTS ; *logflagsp |=XFS_ILOG_CORE |xfs_ilog_fext (whichfork);
@@ -631,20 +631,10 @@ xfs_bmap_extents_to_btree( ifp =xfs_ifork_ptr (ip, whichfork);ASSERT (ifp->if_format ==XFS_DINODE_FMT_EXTENTS ); -/* -* Make space in the inode incore. This needs to be undone if we fail -* to expand the root. -*/ -xfs_iroot_realloc (ip,1 , whichfork); - -/* -* Fill in the root. -*/ - block = ifp->if_broot; -xfs_btree_init_block (mp, block, &xfs_bmbt_ops,1 ,1 , ip->i_ino);/* * Need a cursor. Can't allocate until bb_level is filled in. */ +xfs_bmbt_iroot_alloc (ip, whichfork); cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); cur->bc_ino.flags = wasdel ?XFS_BTCUR_BMBT_WASDEL :0 ;/*
@@ -711,6 +701,7 @@ xfs_bmap_extents_to_btree(/* * Fill in the root key and pointer. */ + block = ifp->if_broot; kp =xfs_bmbt_key_addr (mp, block,1 ); arp =xfs_bmbt_rec_addr (mp, ablock,1 ); kp->br_startoff =cpu_to_be64 (xfs_bmbt_disk_get_startoff (arp));
@@ -732,7 +723,7 @@ xfs_bmap_extents_to_btree( out_unreserve_dquot:xfs_trans_mod_dquot_byino (tp, ip,XFS_TRANS_DQ_BCOUNT ,-1L ); out_root_realloc: -xfs_iroot_realloc (ip,-1 , whichfork); +xfs_iroot_free (ip, whichfork); ifp->if_format =XFS_DINODE_FMT_EXTENTS ;ASSERT (ifp->if_broot ==NULL );xfs_btree_del_cursor (cur,XFS_BTREE_ERROR );
fs/xfs/libxfs/xfs_bmap_btree.c +16 -0
@@ -796,3 +796,19 @@ xfs_bmbt_destroy_cur_cache(void)kmem_cache_destroy (xfs_bmbt_cur_cache); xfs_bmbt_cur_cache =NULL ; } + +/* Create an incore bmbt btree root block. */ +void +xfs_bmbt_iroot_alloc ( +struct xfs_inode *ip, +int whichfork) +{ +struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork); + +xfs_iroot_alloc (ip, whichfork, +xfs_bmap_broot_space_calc (ip->i_mount,1 )); + +/* Fill in the root. */ +xfs_btree_init_block (ip->i_mount, ifp->if_broot, &xfs_bmbt_ops,1 ,1 , + ip->i_ino); +}
fs/xfs/libxfs/xfs_bmap_btree.h +2 -0
@@ -196,4 +196,6 @@ xfs_bmap_bmdr_space(struct xfs_btree_block *bb) return xfs_bmdr_space_calc(be16_to_cpu(bb->bb_numrecs)); } +void xfs_bmbt_iroot_alloc (struct xfs_inode *ip,int whichfork); +#endif /* __XFS_BMAP_BTREE_H__ */
PATCH 4/14 xfs: fix a sloppy memory handling bug in xfs_iroot_realloc
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
While refactoring code, I noticed that when xfs_iroot_realloc tries to shrink a bmbt root block, it allocates a smaller new block and then copies "records" and pointers to the new block. However, bmbt root blocks cannot ever be leaves, which means that it's not technically correct to copy records. We /should/ be copying keys.
Note that this has never resulted in actual memory corruption because sizeof(bmbt_rec) == (sizeof(bmbt_key) + sizeof(bmbt_ptr)). However, this will no longer be true when we start adding realtime rmap stuff, so fix this now.
--- fs/xfs/libxfs/xfs_inode_fork.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_inode_fork.c +5 -5
@@ -466,15 +466,15 @@ xfs_iroot_realloc(memcpy (new_broot, ifp->if_broot,xfs_bmbt_block_len (ip->i_mount));/* -* Only copy the records and pointers if there are any. +* Only copy the keys and pointers if there are any. */ if (new_max >0 ) {/* -* First copy the records. +* First copy the keys. */ - op = (char *)xfs_bmbt_rec_addr (mp, ifp->if_broot,1 ); - np = (char *)xfs_bmbt_rec_addr (mp, new_broot,1 ); -memcpy (np, op, new_max * (uint )sizeof (xfs_bmbt_rec_t)); + op = (char *)xfs_bmbt_key_addr (mp, ifp->if_broot,1 ); + np = (char *)xfs_bmbt_key_addr (mp, new_broot,1 ); +memcpy (np, op, new_max * (uint )sizeof (xfs_bmbt_key_t));/* * Then copy the pointers.
PATCH 5/14 xfs: hoist the code that moves the incore inode fork broot memory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Whenever we change the size of the memory buffer holding an inode fork btree root block, we have to copy the contents over. Refactor all this into a single function that handles both, in preparation for making xfs_iroot_realloc more generic.
--- fs/xfs/libxfs/xfs_inode_fork.c | 99 +++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 42 deletions(-)
fs/xfs/libxfs/xfs_inode_fork.c +57 -42
@@ -369,6 +369,50 @@ xfs_iroot_free( ifp->if_broot =NULL ; } +/* Move the bmap btree root from one incore buffer to another. */ +static void +xfs_ifork_move_broot ( +struct xfs_inode *ip, +int whichfork, +struct xfs_btree_block *dst_broot, +size_t dst_bytes, +struct xfs_btree_block *src_broot, +size_t src_bytes, +unsigned int numrecs) +{ +struct xfs_mount *mp = ip->i_mount; +void *dptr; +void *sptr; + +ASSERT (xfs_bmap_bmdr_space (src_broot) <=xfs_inode_fork_size (ip, whichfork)); + +/* +* We always have to move the pointers because they are not butted +* against the btree block header. +*/ +if (numrecs) { + sptr =xfs_bmap_broot_ptr_addr (mp, src_broot,1 , src_bytes); + dptr =xfs_bmap_broot_ptr_addr (mp, dst_broot,1 , dst_bytes); +memmove (dptr, sptr, numrecs *sizeof (xfs_fsblock_t)); + } + +if (src_broot == dst_broot) +return ; + +/* +* If the root is being totally relocated, we have to migrate the block +* header and the keys that come after it. +*/ +memcpy (dst_broot, src_broot,xfs_bmbt_block_len (mp)); + +/* Now copy the keys, which come right after the header. */ +if (numrecs) { + sptr =xfs_bmbt_key_addr (mp, src_broot,1 ); + dptr =xfs_bmbt_key_addr (mp, dst_broot,1 ); +memcpy (dptr, sptr, numrecs *sizeof (struct xfs_bmbt_key )); + } +} +/* * Reallocate the space for if_broot based on the number of records * being added or deleted as indicated in rec_diff. Move the records
@@ -395,12 +439,11 @@ xfs_iroot_realloc( {struct xfs_mount *mp = ip->i_mount;int cur_max; -struct xfs_ifork *ifp; +struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork);struct xfs_btree_block *new_broot;int new_max;size_t new_size; -char *np; -char *op; +size_t old_size = ifp->if_broot_bytes;/* * Handle the degenerate case quietly.
@@ -409,13 +452,12 @@ xfs_iroot_realloc(return ; } - ifp =xfs_ifork_ptr (ip, whichfork);if (rec_diff >0 ) {/* * If there wasn't any memory allocated before, just * allocate it now and get out. */ -if (ifp->if_broot_bytes ==0 ) { +if (old_size ==0 ) { new_size =xfs_bmap_broot_space_calc (mp, rec_diff);xfs_iroot_alloc (ip, whichfork, new_size);return ;
@@ -424,22 +466,16 @@ xfs_iroot_realloc(/* * If there is already an existing if_broot, then we need * to realloc() it and shift the pointers to their new -* location. The records don't change location because -* they are kept butted up against the btree block header. +* location. */ - cur_max =xfs_bmbt_maxrecs (mp, ifp->if_broot_bytes,0 ); + cur_max =xfs_bmbt_maxrecs (mp, old_size,0 ); new_max = cur_max + rec_diff; new_size =xfs_bmap_broot_space_calc (mp, new_max); ifp->if_broot =krealloc (ifp->if_broot, new_size,GFP_NOFS | __GFP_NOFAIL); - op = (char *)xfs_bmap_broot_ptr_addr (mp, ifp->if_broot,1 , - ifp->if_broot_bytes); - np = (char *)xfs_bmap_broot_ptr_addr (mp, ifp->if_broot,1 , - (int )new_size); - ifp->if_broot_bytes = (int )new_size; -ASSERT (xfs_bmap_bmdr_space (ifp->if_broot) <= -xfs_inode_fork_size (ip, whichfork)); -memmove (np, op, cur_max * (uint )sizeof (xfs_fsblock_t)); + ifp->if_broot_bytes = new_size; +xfs_ifork_move_broot (ip, whichfork, ifp->if_broot, new_size, + ifp->if_broot, old_size, cur_max);return ; }
@@ -448,8 +484,8 @@ xfs_iroot_realloc(* if_broot buffer. It must already exist. If we go to zero * records, just get rid of the root and clear the status bit. */ -ASSERT ((ifp->if_broot !=NULL ) && (ifp->if_broot_bytes >0 )); - cur_max =xfs_bmbt_maxrecs (mp, ifp->if_broot_bytes,0 ); +ASSERT ((ifp->if_broot !=NULL ) && (old_size >0 )); + cur_max =xfs_bmbt_maxrecs (mp, old_size,0 ); new_max = cur_max + rec_diff;ASSERT (new_max >=0 );if (new_max >0 )
@@ -461,35 +497,14 @@ xfs_iroot_realloc(return ; } -/* First copy over the btree block header. */ +/* Reallocate the btree root and move the contents. */ new_broot =kmem_alloc (new_size,KM_NOFS ); -memcpy (new_broot, ifp->if_broot,xfs_bmbt_block_len (ip->i_mount)); +xfs_ifork_move_broot (ip, whichfork, new_broot, new_size, ifp->if_broot, + old_size, new_max); -/* -* Only copy the keys and pointers if there are any. -*/ -if (new_max >0 ) { -/* -* First copy the keys. -*/ - op = (char *)xfs_bmbt_key_addr (mp, ifp->if_broot,1 ); - np = (char *)xfs_bmbt_key_addr (mp, new_broot,1 ); -memcpy (np, op, new_max * (uint )sizeof (xfs_bmbt_key_t)); - -/* -* Then copy the pointers. -*/ - op = (char *)xfs_bmap_broot_ptr_addr (mp, ifp->if_broot,1 , - ifp->if_broot_bytes); - np = (char *)xfs_bmap_broot_ptr_addr (mp, new_broot,1 , - (int )new_size); -memcpy (np, op, new_max * (uint )sizeof (xfs_fsblock_t)); - }kmem_free (ifp->if_broot); ifp->if_broot = new_broot; ifp->if_broot_bytes = (int )new_size; -ASSERT (xfs_bmap_bmdr_space (ifp->if_broot) <= -xfs_inode_fork_size (ip, whichfork));return ; }
PATCH 6/14 xfs: move the zero records logic into xfs_bmap_broot_space_calc
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The bmap btree cannot ever have zero records in an incore btree block. If the number of records drops to zero, that means we're converting the fork to extents format and are trying to remove the tree. This logic won't hold for the future realtime rmap btree, so move the logic into the bmbt code.
--- fs/xfs/libxfs/xfs_bmap_btree.h | 7 +++++++ fs/xfs/libxfs/xfs_inode_fork.c | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_bmap_btree.h +7 -0
@@ -162,6 +162,13 @@ xfs_bmap_broot_space_calc( struct xfs_mount *mp, unsigned int nrecs) { +/* +* If the bmbt root block is empty, we should be converting the fork +* to extents format. Hence, the size is zero. +*/ +if (nrecs ==0 ) +return 0 ; +return xfs_bmbt_block_len (mp) + \ (nrecs * (sizeof (struct xfs_bmbt_key ) +sizeof (xfs_bmbt_ptr_t))); }
fs/xfs/libxfs/xfs_inode_fork.c +2 -4
@@ -488,10 +488,8 @@ xfs_iroot_realloc( cur_max =xfs_bmbt_maxrecs (mp, old_size,0 ); new_max = cur_max + rec_diff;ASSERT (new_max >=0 ); -if (new_max >0 ) - new_size =xfs_bmap_broot_space_calc (mp, new_max); -else - new_size =0 ; + + new_size =xfs_bmap_broot_space_calc (mp, new_max);if (new_size ==0 ) {xfs_iroot_free (ip, whichfork);return ;
PATCH 7/14 xfs: rearrange xfs_iroot_realloc a bit
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Rearrange the innards of xfs_iroot_realloc so that we can reduce duplicated code prior to genericizing the function. No functional changes.
--- fs/xfs/libxfs/xfs_inode_fork.c | 49 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 27 deletions(-)
fs/xfs/libxfs/xfs_inode_fork.c +22 -27
@@ -433,44 +433,46 @@ xfs_ifork_move_broot(*/ void xfs_iroot_realloc ( -xfs_inode_t *ip, +struct xfs_inode *ip,int rec_diff,int whichfork) {struct xfs_mount *mp = ip->i_mount; -int cur_max;struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork);struct xfs_btree_block *new_broot; -int new_max;size_t new_size;size_t old_size = ifp->if_broot_bytes; +int cur_max; +int new_max; + +/* Handle degenerate cases. */ +if (rec_diff ==0 ) +return ;/* -* Handle the degenerate case quietly. +* If there wasn't any memory allocated before, just allocate it now +* and get out. */ -if (rec_diff ==0 ) { +if (old_size ==0 ) { +ASSERT (rec_diff >0 ); + + new_size =xfs_bmap_broot_space_calc (mp, rec_diff); +xfs_iroot_alloc (ip, whichfork, new_size);return ; } +/* Compute the new and old record count and space requirements. */ + cur_max =xfs_bmbt_maxrecs (mp, old_size,0 ); + new_max = cur_max + rec_diff; +ASSERT (new_max >=0 ); + new_size =xfs_bmap_broot_space_calc (mp, new_max); +if (rec_diff >0 ) { -/* -* If there wasn't any memory allocated before, just -* allocate it now and get out. -*/ -if (old_size ==0 ) { - new_size =xfs_bmap_broot_space_calc (mp, rec_diff); -xfs_iroot_alloc (ip, whichfork, new_size); -return ; - } -/* * If there is already an existing if_broot, then we need * to realloc() it and shift the pointers to their new * location. */ - cur_max =xfs_bmbt_maxrecs (mp, old_size,0 ); - new_max = cur_max + rec_diff; - new_size =xfs_bmap_broot_space_calc (mp, new_max); ifp->if_broot =krealloc (ifp->if_broot, new_size,GFP_NOFS | __GFP_NOFAIL); ifp->if_broot_bytes = new_size;
@@ -482,14 +484,8 @@ xfs_iroot_realloc(/* * rec_diff is less than 0. In this case, we are shrinking the * if_broot buffer. It must already exist. If we go to zero -* records, just get rid of the root and clear the status bit. +* bytes, just get rid of the root and clear the status bit. */ -ASSERT ((ifp->if_broot !=NULL ) && (old_size >0 )); - cur_max =xfs_bmbt_maxrecs (mp, old_size,0 ); - new_max = cur_max + rec_diff; -ASSERT (new_max >=0 ); - - new_size =xfs_bmap_broot_space_calc (mp, new_max);if (new_size ==0 ) {xfs_iroot_free (ip, whichfork);return ;
@@ -502,8 +498,7 @@ xfs_iroot_realloc(kmem_free (ifp->if_broot); ifp->if_broot = new_broot; - ifp->if_broot_bytes = (int )new_size; -return ; + ifp->if_broot_bytes = new_size; }
PATCH 8/14 xfs: standardize the btree maxrecs function parameters
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Standardize the parameters in xfs_{alloc,bm,ino,rmap,refcount}bt_maxrecs so that we have consistent calling conventions. This doesn't affect the kernel that much, but enables us to clean up userspace a bit.
--- fs/xfs/libxfs/xfs_alloc_btree.c | 6 +++--- fs/xfs/libxfs/xfs_alloc_btree.h | 3 ++- fs/xfs/libxfs/xfs_bmap.c | 2 +- fs/xfs/libxfs/xfs_bmap_btree.c | 6 +++--- fs/xfs/libxfs/xfs_bmap_btree.h | 5 +++-- fs/xfs/libxfs/xfs_ialloc.c | 4 ++-- fs/xfs/libxfs/xfs_ialloc_btree.c | 6 +++--- fs/xfs/libxfs/xfs_ialloc_btree.h | 3 ++- fs/xfs/libxfs/xfs_inode_fork.c | 2 +- fs/xfs/libxfs/xfs_refcount_btree.c | 5 +++-- fs/xfs/libxfs/xfs_refcount_btree.h | 3 ++- fs/xfs/libxfs/xfs_rmap_btree.c | 9 +++++---- fs/xfs/libxfs/xfs_rmap_btree.h | 3 ++- fs/xfs/libxfs/xfs_sb.c | 16 ++++++++-------- 14 files changed, 40 insertions(+), 33 deletions(-)
fs/xfs/libxfs/xfs_alloc_btree.c +3 -3
@@ -609,11 +609,11 @@ xfs_allocbt_block_maxrecs(/* * Calculate number of records in an alloc btree block. */ -int +unsigned int xfs_allocbt_maxrecs (struct xfs_mount *mp, -int blocklen, -int leaf) +unsigned int blocklen, +bool leaf) { blocklen -=XFS_ALLOC_BLOCK_LEN (mp);return xfs_allocbt_block_maxrecs (blocklen, leaf);
fs/xfs/libxfs/xfs_alloc_btree.h +2 -1
@@ -53,7 +53,8 @@ extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *mp,struct xfs_btree_cur *xfs_allocbt_stage_cursor (struct xfs_mount *mp,struct xbtree_afakeroot *afake,struct xfs_perag *pag,xfs_btnum_t btnum); -extern int xfs_allocbt_maxrecs (struct xfs_mount *,int ,int ); +unsigned int xfs_allocbt_maxrecs (struct xfs_mount *mp,unsigned int blocklen, +bool leaf);extern xfs_extlen_t xfs_allocbt_calc_size (struct xfs_mount *mp,unsigned long long len);
fs/xfs/libxfs/xfs_bmap.c +1 -1
@@ -565,7 +565,7 @@ xfs_bmap_btree_to_extents(ASSERT (ifp->if_format ==XFS_DINODE_FMT_BTREE );ASSERT (be16_to_cpu (rblock->bb_level) ==1 );ASSERT (be16_to_cpu (rblock->bb_numrecs) ==1 ); -ASSERT (xfs_bmbt_maxrecs (mp, ifp->if_broot_bytes,0 ) ==1 ); +ASSERT (xfs_bmbt_maxrecs (mp, ifp->if_broot_bytes, false) ==1 ); pp =xfs_bmap_broot_ptr_addr (mp, rblock,1 , ifp->if_broot_bytes); cbno =be64_to_cpu (*pp);
fs/xfs/libxfs/xfs_bmap_btree.c +3 -3
@@ -682,11 +682,11 @@ xfs_bmbt_commit_staged_btree(/* * Calculate number of records in a bmap btree block. */ -int +unsigned int xfs_bmbt_maxrecs (struct xfs_mount *mp, -int blocklen, -int leaf) +unsigned int blocklen, +bool leaf) { blocklen -=xfs_bmbt_block_len (mp);return xfs_bmbt_block_maxrecs (blocklen, leaf);
fs/xfs/libxfs/xfs_bmap_btree.h +3 -2
@@ -35,7 +35,8 @@ extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,extern int xfs_bmbt_get_maxrecs (struct xfs_btree_cur *,int level);extern int xfs_bmdr_maxrecs (int blocklen,int leaf); -extern int xfs_bmbt_maxrecs (struct xfs_mount *,int blocklen,int leaf); +unsigned int xfs_bmbt_maxrecs (struct xfs_mount *mp,unsigned int blocklen, +bool leaf); extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip, int whichfork, xfs_ino_t new_owner,
@@ -150,7 +151,7 @@ xfs_bmap_broot_ptr_addr(unsigned int i, unsigned int sz) { - return xfs_bmbt_ptr_addr(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0)); + return xfs_bmbt_ptr_addr(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, false)); }/*
fs/xfs/libxfs/xfs_ialloc.c +2 -2
@@ -2880,8 +2880,8 @@ xfs_ialloc_setup_geometry(/* Compute inode btree geometry. */ igeo->agino_log = sbp->sb_inopblog + sbp->sb_agblklog; - igeo->inobt_mxr[0 ] =xfs_inobt_maxrecs (mp, sbp->sb_blocksize,1 ); - igeo->inobt_mxr[1 ] =xfs_inobt_maxrecs (mp, sbp->sb_blocksize,0 ); + igeo->inobt_mxr[0 ] =xfs_inobt_maxrecs (mp, sbp->sb_blocksize, true); + igeo->inobt_mxr[1 ] =xfs_inobt_maxrecs (mp, sbp->sb_blocksize, false); igeo->inobt_mnr[0 ] = igeo->inobt_mxr[0 ] /2 ; igeo->inobt_mnr[1 ] = igeo->inobt_mxr[1 ] /2 ;
fs/xfs/libxfs/xfs_ialloc_btree.c +3 -3
@@ -560,11 +560,11 @@ xfs_inobt_block_maxrecs(/* * Calculate number of records in an inobt btree block. */ -int +unsigned int xfs_inobt_maxrecs (struct xfs_mount *mp, -int blocklen, -int leaf) +unsigned int blocklen, +bool leaf) { blocklen -=XFS_INOBT_BLOCK_LEN (mp);return xfs_inobt_block_maxrecs (blocklen, leaf);
fs/xfs/libxfs/xfs_ialloc_btree.h +2 -1
@@ -52,7 +52,8 @@ extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *mp,struct xfs_btree_cur *xfs_inobt_stage_cursor (struct xfs_mount *mp,struct xbtree_afakeroot *afake,struct xfs_perag *pag,xfs_btnum_t btnum); -extern int xfs_inobt_maxrecs (struct xfs_mount *,int ,int ); +unsigned int xfs_inobt_maxrecs (struct xfs_mount *mp,unsigned int blocklen, +bool leaf);/* ir_holemask to inode allocation bitmap conversion */ uint64_t xfs_inobt_irec_to_allocmask (const struct xfs_inobt_rec_incore *irec);
fs/xfs/libxfs/xfs_inode_fork.c +1 -1
@@ -462,7 +462,7 @@ xfs_iroot_realloc( }/* Compute the new and old record count and space requirements. */ - cur_max =xfs_bmbt_maxrecs (mp, old_size,0 ); + cur_max =xfs_bmbt_maxrecs (mp, old_size, false); new_max = cur_max + rec_diff;ASSERT (new_max >=0 ); new_size =xfs_bmap_broot_space_calc (mp, new_max);
fs/xfs/libxfs/xfs_refcount_btree.c +3 -2
@@ -439,9 +439,10 @@ xfs_refcountbt_block_maxrecs(/* * Calculate the number of records in a refcount btree block. */ -int +unsigned int xfs_refcountbt_maxrecs ( -int blocklen, +struct xfs_mount *mp, +unsigned int blocklen,bool leaf) { blocklen -=XFS_REFCOUNT_BLOCK_LEN ;
fs/xfs/libxfs/xfs_refcount_btree.h +2 -1
@@ -50,7 +50,8 @@ extern struct xfs_btree_cur *xfs_refcountbt_init_cursor(struct xfs_mount *mp, struct xfs_perag *pag);struct xfs_btree_cur *xfs_refcountbt_stage_cursor (struct xfs_mount *mp,struct xbtree_afakeroot *afake,struct xfs_perag *pag); -extern int xfs_refcountbt_maxrecs (int blocklen,bool leaf); +unsigned int xfs_refcountbt_maxrecs (struct xfs_mount *mp,unsigned int blocklen, +bool leaf);extern void xfs_refcountbt_compute_maxlevels (struct xfs_mount *mp); extern xfs_extlen_t xfs_refcountbt_calc_size(struct xfs_mount *mp,
fs/xfs/libxfs/xfs_rmap_btree.c +5 -4
@@ -588,7 +588,7 @@ xfs_rmapbt_mem_verify( }return xfbtree_sblock_verify (bp, -xfs_rmapbt_maxrecs (xfo_to_b (1 ), level ==0 )); +xfs_rmapbt_maxrecs (mp,xfo_to_b (1 ), level ==0 )); } static void
@@ -715,10 +715,11 @@ xfs_rmapbt_block_maxrecs(/* * Calculate number of records in an rmap btree block. */ -int +unsigned int xfs_rmapbt_maxrecs ( -int blocklen, -int leaf) +struct xfs_mount *mp, +unsigned int blocklen, +bool leaf) { blocklen -=XFS_RMAP_BLOCK_LEN ;return xfs_rmapbt_block_maxrecs (blocklen, leaf);
fs/xfs/libxfs/xfs_rmap_btree.h +2 -1
@@ -48,7 +48,8 @@ struct xfs_btree_cur *xfs_rmapbt_stage_cursor(struct xfs_mount *mp, struct xbtree_afakeroot *afake, struct xfs_perag *pag);void xfs_rmapbt_commit_staged_btree (struct xfs_btree_cur *cur,struct xfs_trans *tp,struct xfs_buf *agbp); -int xfs_rmapbt_maxrecs (int blocklen,int leaf); +unsigned int xfs_rmapbt_maxrecs (struct xfs_mount *mp,unsigned int blocklen, +bool leaf);extern void xfs_rmapbt_compute_maxlevels (struct xfs_mount *mp); extern xfs_extlen_t xfs_rmapbt_calc_size(struct xfs_mount *mp,
fs/xfs/libxfs/xfs_sb.c +8 -8
@@ -1049,23 +1049,23 @@ xfs_sb_mount_common( mp->m_rgblklog =log2_if_power2 (sbp->sb_rgblocks); mp->m_rgblkmask =mask64_if_power2 (sbp->sb_rgblocks); - mp->m_alloc_mxr[0 ] =xfs_allocbt_maxrecs (mp, sbp->sb_blocksize,1 ); - mp->m_alloc_mxr[1 ] =xfs_allocbt_maxrecs (mp, sbp->sb_blocksize,0 ); + mp->m_alloc_mxr[0 ] =xfs_allocbt_maxrecs (mp, sbp->sb_blocksize, true); + mp->m_alloc_mxr[1 ] =xfs_allocbt_maxrecs (mp, sbp->sb_blocksize, false); mp->m_alloc_mnr[0 ] = mp->m_alloc_mxr[0 ] /2 ; mp->m_alloc_mnr[1 ] = mp->m_alloc_mxr[1 ] /2 ; - mp->m_bmap_dmxr[0 ] =xfs_bmbt_maxrecs (mp, sbp->sb_blocksize,1 ); - mp->m_bmap_dmxr[1 ] =xfs_bmbt_maxrecs (mp, sbp->sb_blocksize,0 ); + mp->m_bmap_dmxr[0 ] =xfs_bmbt_maxrecs (mp, sbp->sb_blocksize, true); + mp->m_bmap_dmxr[1 ] =xfs_bmbt_maxrecs (mp, sbp->sb_blocksize, false); mp->m_bmap_dmnr[0 ] = mp->m_bmap_dmxr[0 ] /2 ; mp->m_bmap_dmnr[1 ] = mp->m_bmap_dmxr[1 ] /2 ; - mp->m_rmap_mxr[0 ] =xfs_rmapbt_maxrecs (sbp->sb_blocksize,1 ); - mp->m_rmap_mxr[1 ] =xfs_rmapbt_maxrecs (sbp->sb_blocksize,0 ); + mp->m_rmap_mxr[0 ] =xfs_rmapbt_maxrecs (mp, sbp->sb_blocksize, true); + mp->m_rmap_mxr[1 ] =xfs_rmapbt_maxrecs (mp, sbp->sb_blocksize, false); mp->m_rmap_mnr[0 ] = mp->m_rmap_mxr[0 ] /2 ; mp->m_rmap_mnr[1 ] = mp->m_rmap_mxr[1 ] /2 ; - mp->m_refc_mxr[0 ] =xfs_refcountbt_maxrecs (sbp->sb_blocksize, true); - mp->m_refc_mxr[1 ] =xfs_refcountbt_maxrecs (sbp->sb_blocksize, false); + mp->m_refc_mxr[0 ] =xfs_refcountbt_maxrecs (mp, sbp->sb_blocksize, true); + mp->m_refc_mxr[1 ] =xfs_refcountbt_maxrecs (mp, sbp->sb_blocksize, false); mp->m_refc_mnr[0 ] = mp->m_refc_mxr[0 ] /2 ; mp->m_refc_mnr[1 ] = mp->m_refc_mxr[1 ] /2 ;
PATCH 9/14 xfs: generalize the btree root reallocation function
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In preparation for storing realtime rmap btree roots in an inode fork, make xfs_iroot_realloc take an ops structure that takes care of all the btree-specific geometry pieces.
--- fs/xfs/libxfs/xfs_bmap_btree.c | 51 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_btree.c | 22 +++++++---- fs/xfs/libxfs/xfs_btree.h | 3 + fs/xfs/libxfs/xfs_inode_fork.c | 82 ++++++++-------------------------------- fs/xfs/libxfs/xfs_inode_fork.h | 23 +++++++++++ 5 files changed, 107 insertions(+), 74 deletions(-)
fs/xfs/libxfs/xfs_bmap_btree.c +51 -0
@@ -527,6 +527,56 @@ xfs_bmbt_keys_contiguous( be64_to_cpu(key2->bmbt.br_startoff)); } +/* Move the bmap btree root from one incore buffer to another. */ +static void +xfs_bmbt_broot_move ( +struct xfs_inode *ip, +int whichfork, +struct xfs_btree_block *dst_broot, +size_t dst_bytes, +struct xfs_btree_block *src_broot, +size_t src_bytes, +unsigned int numrecs) +{ +struct xfs_mount *mp = ip->i_mount; +void *dptr; +void *sptr; + +ASSERT (xfs_bmap_bmdr_space (src_broot) <=xfs_inode_fork_size (ip, whichfork)); + +/* +* We always have to move the pointers because they are not butted +* against the btree block header. +*/ +if (numrecs) { + sptr =xfs_bmap_broot_ptr_addr (mp, src_broot,1 , src_bytes); + dptr =xfs_bmap_broot_ptr_addr (mp, dst_broot,1 , dst_bytes); +memmove (dptr, sptr, numrecs *sizeof (xfs_fsblock_t)); + } + +if (src_broot == dst_broot) +return ; + +/* +* If the root is being totally relocated, we have to migrate the block +* header and the keys that come after it. +*/ +memcpy (dst_broot, src_broot,xfs_bmbt_block_len (mp)); + +/* Now copy the keys, which come right after the header. */ +if (numrecs) { + sptr =xfs_bmbt_key_addr (mp, src_broot,1 ); + dptr =xfs_bmbt_key_addr (mp, dst_broot,1 ); +memcpy (dptr, sptr, numrecs *sizeof (struct xfs_bmbt_key )); + } +} + +static const struct xfs_ifork_broot_ops xfs_bmbt_iroot_ops = { + .maxrecs = xfs_bmbt_maxrecs, + .size = xfs_bmap_broot_space_calc, + .move = xfs_bmbt_broot_move, +}; +const struct xfs_btree_ops xfs_bmbt_ops = { .rec_len =sizeof (xfs_bmbt_rec_t), .key_len =sizeof (xfs_bmbt_key_t),
@@ -549,6 +599,7 @@ const struct xfs_btree_ops xfs_bmbt_ops = { .keys_inorder = xfs_bmbt_keys_inorder, .recs_inorder = xfs_bmbt_recs_inorder, .keys_contiguous = xfs_bmbt_keys_contiguous, + .iroot_ops = &xfs_bmbt_iroot_ops, };/*
fs/xfs/libxfs/xfs_btree.c +14 -8
@@ -3080,6 +3080,16 @@ xfs_btree_split(#define xfs_btree_split __xfs_btree_split#endif /* __KERNEL__ */ +static inline void +xfs_btree_iroot_realloc ( +struct xfs_btree_cur *cur, +int rec_diff) +{ +ASSERT (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ); + +xfs_iroot_realloc (cur->bc_ino.ip, cur->bc_ino.whichfork, + cur->bc_ops->iroot_ops, rec_diff); +}/* * Copy the old inode root contents into a real block and make the
@@ -3164,9 +3174,7 @@ xfs_btree_new_iroot(xfs_btree_copy_ptrs (cur, pp, &nptr,1 ); -xfs_iroot_realloc (cur->bc_ino.ip, -1 -xfs_btree_get_numrecs (cblock), - cur->bc_ino.whichfork); +xfs_btree_iroot_realloc (cur,1 -xfs_btree_get_numrecs (cblock));xfs_btree_setbuf (cur, level, cbp);
@@ -3336,7 +3344,7 @@ xfs_btree_make_block_unfull(if (numrecs < cur->bc_ops->get_dmaxrecs (cur, level)) {/* A root block that can be made bigger. */ -xfs_iroot_realloc (ip,1 , cur->bc_ino.whichfork); +xfs_btree_iroot_realloc (cur,1 ); *stat =1 ; }else {/* A root block that needs replacing */
@@ -3744,8 +3752,7 @@ xfs_btree_kill_iroot( index = numrecs - cur->bc_ops->get_maxrecs (cur, level);if (index) { -xfs_iroot_realloc (cur->bc_ino.ip, index, - cur->bc_ino.whichfork); +xfs_btree_iroot_realloc (cur, index); block = ifp->if_broot; }
@@ -3942,8 +3949,7 @@ xfs_btree_delrec(*/ if (level == cur->bc_nlevels -1 ) {if (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) { -xfs_iroot_realloc (cur->bc_ino.ip,-1 , - cur->bc_ino.whichfork); +xfs_btree_iroot_realloc (cur,-1 ); error =xfs_btree_kill_iroot (cur);if (error)
fs/xfs/libxfs/xfs_btree.h +3 -0
@@ -202,6 +202,9 @@ struct xfs_btree_ops {const union xfs_btree_key *key1, const union xfs_btree_key *key2, const union xfs_btree_key *mask); + +/* Functions for manipulating the btree root block. */ +const struct xfs_ifork_broot_ops *iroot_ops; };/*
fs/xfs/libxfs/xfs_inode_fork.c +17 -65
129 lines not on this page · raw message
fs/xfs/libxfs/xfs_inode_fork.h +22 -1
@@ -174,7 +174,6 @@ void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,void xfs_iroot_alloc (struct xfs_inode *ip,int whichfork,size_t bytes);void xfs_iroot_free (struct xfs_inode *ip,int whichfork); -void xfs_iroot_realloc (struct xfs_inode *,int ,int );int xfs_iread_extents (struct xfs_trans *,struct xfs_inode *,int );int xfs_iextents_copy (struct xfs_inode *,struct xfs_bmbt_rec *,int );
@@ -272,4 +271,26 @@ static inline bool xfs_need_iread_extents(struct xfs_ifork *ifp) return ifp->if_format == XFS_DINODE_FMT_BTREE && ifp->if_height == 0; } +struct xfs_ifork_broot_ops { +/* Calculate the number of records/keys in the incore btree block. */ +unsigned int (*maxrecs)(struct xfs_mount *mp,unsigned int blocksize, +bool leaf); + +/* Calculate the bytes required for the incore btree root block. */ +size_t (*size)(struct xfs_mount *mp,unsigned int nrecs); + +/* +* Move an incore btree root from one buffer to another. Note that +* src_broot and dst_broot could be the same or they could be totally +* separate memory regions. +*/ +void (*move)(struct xfs_inode *ip,int whichfork, +struct xfs_btree_block *dst_broot,size_t dst_bytes, +struct xfs_btree_block *src_broot,size_t src_bytes, +unsigned int numrecs); +}; + +void xfs_iroot_realloc (struct xfs_inode *ip,int whichfork, +const struct xfs_ifork_broot_ops *ops,int rec_diff); +#endif /* __XFS_INODE_FORK_H__ */
PATCH 10/14 xfs: support leaves in the incore btree root block in xfs_iroot_realloc
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add some logic to xfs_iroot_realloc so that we can handle leaf records in the btree root block correctly.
--- fs/xfs/libxfs/xfs_bmap_btree.c | 4 +++- fs/xfs/libxfs/xfs_bmap_btree.h | 5 ++++- fs/xfs/libxfs/xfs_inode_fork.c | 12 +++++++----- fs/xfs/libxfs/xfs_inode_fork.h | 5 +++-- fs/xfs/scrub/bmap_repair.c | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_bmap_btree.c +3 -1
@@ -536,6 +536,7 @@ xfs_bmbt_broot_move(size_t dst_bytes, struct xfs_btree_block *src_broot, size_t src_bytes, + unsigned int level, unsigned int numrecs) { struct xfs_mount *mp = ip->i_mount;
@@ -543,6 +544,7 @@ xfs_bmbt_broot_move(void *sptr;ASSERT (xfs_bmap_bmdr_space (src_broot) <=xfs_inode_fork_size (ip, whichfork)); +ASSERT (level >0 );/* * We always have to move the pointers because they are not butted
@@ -857,7 +859,7 @@ xfs_bmbt_iroot_alloc(struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork);xfs_iroot_alloc (ip, whichfork, -xfs_bmap_broot_space_calc (ip->i_mount,1 )); +xfs_bmap_broot_space_calc (ip->i_mount,1 ,1 ));/* Fill in the root. */ xfs_btree_init_block(ip->i_mount, ifp->if_broot, &xfs_bmbt_ops, 1, 1,
fs/xfs/libxfs/xfs_bmap_btree.h +4 -1
@@ -161,8 +161,11 @@ xfs_bmap_broot_ptr_addr(static inline size_t xfs_bmap_broot_space_calc (struct xfs_mount *mp, +unsigned int level,unsigned int nrecs) { +ASSERT (level >0 ); +/* * If the bmbt root block is empty, we should be converting the fork * to extents format. Hence, the size is zero.
@@ -183,7 +186,7 @@ xfs_bmap_broot_space(struct xfs_mount *mp, struct xfs_bmdr_block *bb) { - return xfs_bmap_broot_space_calc(mp, be16_to_cpu(bb->bb_numrecs)); + return xfs_bmap_broot_space_calc(mp, 1, be16_to_cpu(bb->bb_numrecs)); }/* Compute the space required for the ondisk root block. */
fs/xfs/libxfs/xfs_inode_fork.c +7 -5
@@ -395,6 +395,7 @@ xfs_iroot_realloc(struct xfs_btree_block *new_broot;size_t new_size;size_t old_size = ifp->if_broot_bytes; +unsigned int level;int cur_max;int new_max;
@@ -409,16 +410,17 @@ xfs_iroot_realloc(if (old_size ==0 ) {ASSERT (rec_diff >0 ); - new_size = ops->size (mp, rec_diff); + new_size = ops->size (mp,0 , rec_diff);xfs_iroot_alloc (ip, whichfork, new_size);return ; }/* Compute the new and old record count and space requirements. */ - cur_max = ops->maxrecs (mp, old_size, false); + level =be16_to_cpu (ifp->if_broot->bb_level); + cur_max = ops->maxrecs (mp, old_size, level ==0 ); new_max = cur_max + rec_diff;ASSERT (new_max >=0 ); - new_size = ops->size (mp, new_max); + new_size = ops->size (mp, level, new_max);if (rec_diff >0 ) {/*
@@ -430,7 +432,7 @@ xfs_iroot_realloc( GFP_NOFS | __GFP_NOFAIL); ifp->if_broot_bytes = new_size; ops->move (ip, whichfork, ifp->if_broot, new_size, - ifp->if_broot, old_size, cur_max); + ifp->if_broot, old_size, level, cur_max);return ; }
@@ -447,7 +449,7 @@ xfs_iroot_realloc(/* Reallocate the btree root and move the contents. */ new_broot =kmem_alloc (new_size,KM_NOFS ); ops->move (ip, whichfork, new_broot, new_size, ifp->if_broot, - ifp->if_broot_bytes, new_max); + ifp->if_broot_bytes, level, new_max);kmem_free (ifp->if_broot); ifp->if_broot = new_broot;
fs/xfs/libxfs/xfs_inode_fork.h +3 -2
@@ -277,7 +277,8 @@ struct xfs_ifork_broot_ops { bool leaf);/* Calculate the bytes required for the incore btree root block. */ -size_t (*size)(struct xfs_mount *mp,unsigned int nrecs); +size_t (*size)(struct xfs_mount *mp,unsigned int level, +unsigned int nrecs);/* * Move an incore btree root from one buffer to another. Note that
@@ -287,7 +288,7 @@ struct xfs_ifork_broot_ops {void (*move)(struct xfs_inode *ip,int whichfork,struct xfs_btree_block *dst_broot,size_t dst_bytes,struct xfs_btree_block *src_broot,size_t src_bytes, -unsigned int numrecs); +unsigned int level,unsigned int numrecs); }; void xfs_iroot_realloc(struct xfs_inode *ip, int whichfork,
fs/xfs/scrub/bmap_repair.c +1 -1
@@ -437,7 +437,7 @@ xrep_bmap_iroot_size( {ASSERT (level >0 ); -return xfs_bmap_broot_space_calc (cur->bc_mp, nr_this_level); +return xfs_bmap_broot_space_calc (cur->bc_mp, level, nr_this_level); }/* Update the inode counters. */
PATCH 11/14 xfs: hoist the node iroot update code out of xfs_btree_new_iroot
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In preparation for allowing records in an inode btree root, hoist the code that copies keyptrs from an existing node root into a child block to a separate function. Note that the new function explicitly computes the keys of the new child block and stores that in the root block; while the bmap btree could rely on leaving the key alone, realtime rmap needs to set the new high key.
--- fs/xfs/libxfs/xfs_btree.c | 113 +++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 39 deletions(-)
fs/xfs/libxfs/xfs_btree.c +74 -39
@@ -3091,6 +3091,77 @@ xfs_btree_iroot_realloc( cur->bc_ops->iroot_ops, rec_diff); } +/* +* Move the keys and pointers from a root block to a separate block. +* +* Since the keyptr size does not change, all we have to do is increase the +* tree height, copy the keyptrs to the new internal node (cblock), shrink +* the root, and copy the pointers there. +*/ +STATIC int +xfs_btree_promote_node_iroot ( +struct xfs_btree_cur *cur, +struct xfs_btree_block *block, +int level, +struct xfs_buf *cbp, +union xfs_btree_ptr *cptr, +struct xfs_btree_block *cblock) +{ +union xfs_btree_key *ckp; +union xfs_btree_key *kp; +union xfs_btree_ptr *cpp; +union xfs_btree_ptr *pp; +int i; +int error; +int numrecs =xfs_btree_get_numrecs (block); + +/* +* Increase tree height, adjusting the root block level to match. +* We cannot change the root btree node size until we've copied the +* block contents to the new child block. +*/ +be16_add_cpu (&block->bb_level,1 ); + cur->bc_nlevels++; + cur->bc_levels[level +1 ].ptr =1 ; + +/* +* Adjust the root btree record count, then copy the keys from the old +* root to the new child block. +*/ +xfs_btree_set_numrecs (block,1 ); + kp =xfs_btree_key_addr (cur,1 , block); + ckp =xfs_btree_key_addr (cur,1 , cblock); +xfs_btree_copy_keys (cur, ckp, kp, numrecs); + +/* Check the pointers and copy them to the new child block. */ + pp =xfs_btree_ptr_addr (cur,1 , block); + cpp =xfs_btree_ptr_addr (cur,1 , cblock); +for (i =0 ; i < numrecs; i++) { + error =xfs_btree_debug_check_ptr (cur, pp, i, level); +if (error) +return error; + } +xfs_btree_copy_ptrs (cur, cpp, pp, numrecs); + +/* +* Set the first keyptr to point to the new child block, then shrink +* the memory buffer for the root block. +*/ + error =xfs_btree_debug_check_ptr (cur, cptr,0 , level); +if (error) +return error; +xfs_btree_copy_ptrs (cur, pp, cptr,1 ); +xfs_btree_get_keys (cur, cblock, kp); +xfs_btree_iroot_realloc (cur,1 - numrecs); + +/* Attach the new block to the cursor and log it. */ +xfs_btree_setbuf (cur, level, cbp); +xfs_btree_log_block (cur, cbp,XFS_BB_ALL_BITS ); +xfs_btree_log_keys (cur, cbp,1 , numrecs); +xfs_btree_log_ptrs (cur, cbp,1 , numrecs); +return 0 ; +} +/* * Copy the old inode root contents into a real block and make the * broot point to it.
@@ -3104,14 +3175,10 @@ xfs_btree_new_iroot(struct xfs_buf *cbp;/* buffer for cblock */ struct xfs_btree_block *block;/* btree block */ struct xfs_btree_block *cblock;/* child btree block */ -union xfs_btree_key *ckp;/* child key pointer */ -union xfs_btree_ptr *cpp;/* child ptr pointer */ -union xfs_btree_key *kp;/* pointer to btree key */ -union xfs_btree_ptr *pp;/* pointer to block addr */ +union xfs_btree_ptr *pp;union xfs_btree_ptr nptr;/* new block addr */ int level;/* btree level */ int error;/* error return code */ -int i;/* loop counter */ XFS_BTREE_STATS_INC (cur, newroot);
@@ -3149,43 +3216,11 @@ xfs_btree_new_iroot( cblock->bb_u.s.bb_blkno = bno; } -be16_add_cpu (&block->bb_level,1 ); -xfs_btree_set_numrecs (block,1 ); - cur->bc_nlevels++; -ASSERT (cur->bc_nlevels <= cur->bc_maxlevels); - cur->bc_levels[level +1 ].ptr =1 ; - - kp =xfs_btree_key_addr (cur,1 , block); - ckp =xfs_btree_key_addr (cur,1 , cblock); -xfs_btree_copy_keys (cur, ckp, kp,xfs_btree_get_numrecs (cblock)); - - cpp =xfs_btree_ptr_addr (cur,1 , cblock); -for (i =0 ; i <be16_to_cpu (cblock->bb_numrecs); i++) { - error =xfs_btree_debug_check_ptr (cur, pp, i, level); -if (error) - goto error0; - } - -xfs_btree_copy_ptrs (cur, cpp, pp,xfs_btree_get_numrecs (cblock)); - - error =xfs_btree_debug_check_ptr (cur, &nptr,0 , level); + error =xfs_btree_promote_node_iroot (cur, block, level, cbp, &nptr, + cblock);if (error) goto error0; -xfs_btree_copy_ptrs (cur, pp, &nptr,1 ); - -xfs_btree_iroot_realloc (cur,1 -xfs_btree_get_numrecs (cblock)); - -xfs_btree_setbuf (cur, level, cbp); - -/* -* Do all this logging at the end so that -* the root is at the right level. -*/ -xfs_btree_log_block (cur, cbp,XFS_BB_ALL_BITS ); -xfs_btree_log_keys (cur, cbp,1 ,be16_to_cpu (cblock->bb_numrecs)); -xfs_btree_log_ptrs (cur, cbp,1 ,be16_to_cpu (cblock->bb_numrecs)); - *logflags |=XFS_ILOG_CORE |xfs_ilog_fbroot (cur->bc_ino.whichfork); *stat =1 ;
PATCH 12/14 xfs: hoist the node iroot update code out of xfs_btree_kill_iroot
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In preparation for allowing records in an inode btree root, hoist the code that copies keyptrs from an existing node child into the root block to a separate function. Remove some unnecessary conditionals and clean up a few function calls in the new function. Note that this change reorders the ->free_block call with respect to the change in bc_nlevels to make it easier to support inode root leaf blocks in the next patch.
--- fs/xfs/libxfs/xfs_btree.c | 94 +++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 34 deletions(-)
fs/xfs/libxfs/xfs_btree.c +60 -34
@@ -3716,6 +3716,63 @@ xfs_btree_insert(return error; } +/* +* Move the keyptrs from a child node block to the root block. +* +* Since the keyptr size does not change, all we have to do is increase the +* tree height, copy the keyptrs to the new internal node (cblock), shrink +* the root, and copy the pointers there. +*/ +STATIC int +xfs_btree_demote_node_child ( +struct xfs_btree_cur *cur, +struct xfs_btree_block *cblock, +int level, +int numrecs) +{ +struct xfs_btree_block *block; +union xfs_btree_key *ckp; +union xfs_btree_key *kp; +union xfs_btree_ptr *cpp; +union xfs_btree_ptr *pp; +int i; +int error; +int diff; + +/* +* Adjust the root btree node size and the record count to match the +* doomed child so that we can copy the keyptrs ahead of changing the +* tree shape. +*/ + diff = numrecs - cur->bc_ops->get_maxrecs (cur, level); +xfs_btree_iroot_realloc (cur, diff); + block =xfs_btree_get_iroot (cur); + +xfs_btree_set_numrecs (block, numrecs); +ASSERT (block->bb_numrecs == cblock->bb_numrecs); + +/* Copy keys from the doomed block. */ + kp =xfs_btree_key_addr (cur,1 , block); + ckp =xfs_btree_key_addr (cur,1 , cblock); +xfs_btree_copy_keys (cur, kp, ckp, numrecs); + +/* Copy pointers from the doomed block. */ + pp =xfs_btree_ptr_addr (cur,1 , block); + cpp =xfs_btree_ptr_addr (cur,1 , cblock); +for (i =0 ; i < numrecs; i++) { + error =xfs_btree_debug_check_ptr (cur, cpp, i, level -1 ); +if (error) +return error; + } +xfs_btree_copy_ptrs (cur, pp, cpp, numrecs); + +/* Decrease tree height, adjusting the root block level to match. */ + cur->bc_levels[level -1 ].bp =NULL ; +be16_add_cpu (&block->bb_level,-1 ); + cur->bc_nlevels--; +return 0 ; +} +/* * Try to merge a non-leaf block back into the inode root. *
@@ -3728,24 +3785,16 @@ STATIC intxfs_btree_kill_iroot ( struct xfs_btree_cur *cur) { -int whichfork = cur->bc_ino.whichfork;struct xfs_inode *ip = cur->bc_ino.ip; -struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork);struct xfs_btree_block *block;struct xfs_btree_block *cblock; -union xfs_btree_key *kp; -union xfs_btree_key *ckp; -union xfs_btree_ptr *pp; -union xfs_btree_ptr *cpp;struct xfs_buf *cbp;int level; -int index;int numrecs;int error;#ifdef DEBUG union xfs_btree_ptr ptr;#endif -int i;ASSERT (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE );ASSERT (cur->bc_nlevels >1 );
@@ -3785,39 +3834,16 @@ xfs_btree_kill_iroot(ASSERT (xfs_btree_ptr_is_null (cur, &ptr));#endif - index = numrecs - cur->bc_ops->get_maxrecs (cur, level); -if (index) { -xfs_btree_iroot_realloc (cur, index); - block = ifp->if_broot; - } - -be16_add_cpu (&block->bb_numrecs, index); -ASSERT (block->bb_numrecs == cblock->bb_numrecs); - - kp =xfs_btree_key_addr (cur,1 , block); - ckp =xfs_btree_key_addr (cur,1 , cblock); -xfs_btree_copy_keys (cur, kp, ckp, numrecs); - - pp =xfs_btree_ptr_addr (cur,1 , block); - cpp =xfs_btree_ptr_addr (cur,1 , cblock); - -for (i =0 ; i < numrecs; i++) { - error =xfs_btree_debug_check_ptr (cur, cpp, i, level -1 ); -if (error) -return error; - } - -xfs_btree_copy_ptrs (cur, pp, cpp, numrecs); + error =xfs_btree_demote_node_child (cur, cblock, level, numrecs); +if (error) +return error; error =xfs_btree_free_block (cur, cbp);if (error)return error; - cur->bc_levels[level -1 ].bp =NULL ; -be16_add_cpu (&block->bb_level,-1 );xfs_trans_log_inode (cur->bc_tp, ip,XFS_ILOG_CORE |xfs_ilog_fbroot (cur->bc_ino.whichfork)); - cur->bc_nlevels--; out0:return 0 ; }
PATCH 13/14 xfs: support storing records in the inode core root
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add the necessary flags and code so that we can support storing leaf records in the inode root block of a btree. This hasn't been necessary before, but the realtime rmapbt will need to be able to do this.
--- fs/xfs/libxfs/xfs_btree.c | 150 ++++++++++++++++++++++++++++++++++--- fs/xfs/libxfs/xfs_btree.h | 1 fs/xfs/libxfs/xfs_btree_staging.c | 4 + 3 files changed, 141 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_btree.c +137 -13
@@ -267,6 +267,11 @@ xfs_btree_check_block( int level, /* level of the btree block */ struct xfs_buf *bp) /* buffer containing block, if any */ { +/* Don't check the inode-core root. */ +if ((cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ) && + level == cur->bc_nlevels -1 ) +return 0 ; +if (cur->bc_flags &XFS_BTREE_LONG_PTRS )return xfs_btree_check_lblock (cur, block, level, bp);else
@@ -1570,12 +1575,16 @@ xfs_btree_log_recs( int first, int last) { +if (!bp) { +xfs_trans_log_inode (cur->bc_tp, cur->bc_ino.ip, +xfs_ilog_fbroot (cur->bc_ino.whichfork)); +return ; + }xfs_trans_buf_set_type (cur->bc_tp, bp,XFS_BLFT_BTREE_BUF );xfs_trans_log_buf (cur->bc_tp, bp,xfs_btree_rec_offset (cur, first),xfs_btree_rec_offset (cur, last +1 ) -1 ); - }/*
@@ -3091,6 +3100,64 @@ xfs_btree_iroot_realloc( cur->bc_ops->iroot_ops, rec_diff); } +/* +* Move the records from a root leaf block to a separate block. +* +* Trickery here: The amount of memory that we need per record for the incore +* root block changes when we convert a leaf block to an internal block. +* Therefore, we copy leaf records into the new btree block (cblock) before +* freeing the incore root block and changing the tree height. +* +* Once we've changed the tree height, we allocate a new incore root block +* (which will now be an internal root block) and populate it with a pointer to +* cblock and the relevant keys. +*/ +STATIC void +xfs_btree_promote_leaf_iroot ( +struct xfs_btree_cur *cur, +struct xfs_btree_block *block, +struct xfs_buf *cbp, +union xfs_btree_ptr *cptr, +struct xfs_btree_block *cblock) +{ +union xfs_btree_rec *rp; +union xfs_btree_rec *crp; +union xfs_btree_key *kp; +union xfs_btree_ptr *pp; +size_t size; +int numrecs =xfs_btree_get_numrecs (block); + +/* Copy the records from the leaf root into the new child block. */ + rp =xfs_btree_rec_addr (cur,1 , block); + crp =xfs_btree_rec_addr (cur,1 , cblock); +xfs_btree_copy_recs (cur, crp, rp, numrecs); + +/* Zap the old root and change the tree height. */ +xfs_iroot_free (cur->bc_ino.ip, cur->bc_ino.whichfork); + cur->bc_nlevels++; + cur->bc_levels[1 ].ptr =1 ; + +/* +* Allocate a new internal root block buffer and reinitialize it to +* point to a single new child. +*/ + size = cur->bc_ops->iroot_ops->size (cur->bc_mp, cur->bc_nlevels -1 ,1 ); +xfs_iroot_alloc (cur->bc_ino.ip, cur->bc_ino.whichfork, size); + block =xfs_btree_get_iroot (cur); +xfs_btree_init_block (cur->bc_mp, block, cur->bc_ops, + cur->bc_nlevels -1 ,1 , cur->bc_ino.ip->i_ino); + + pp =xfs_btree_ptr_addr (cur,1 , block); + kp =xfs_btree_key_addr (cur,1 , block); +xfs_btree_copy_ptrs (cur, pp, cptr,1 ); +xfs_btree_get_keys (cur, cblock, kp); + +/* Attach the new block to the cursor and log it. */ +xfs_btree_setbuf (cur,0 , cbp); +xfs_btree_log_block (cur, cbp,XFS_BB_ALL_BITS ); +xfs_btree_log_recs (cur, cbp,1 , numrecs); +} +/* * Move the keys and pointers from a root block to a separate block. *
@@ -3175,7 +3242,7 @@ xfs_btree_new_iroot(struct xfs_buf *cbp;/* buffer for cblock */ struct xfs_btree_block *block;/* btree block */ struct xfs_btree_block *cblock;/* child btree block */ -union xfs_btree_ptr *pp; +union xfs_btree_ptr aptr;union xfs_btree_ptr nptr;/* new block addr */ int level;/* btree level */ int error;/* error return code */
@@ -3187,10 +3254,15 @@ xfs_btree_new_iroot( level = cur->bc_nlevels -1 ; block =xfs_btree_get_iroot (cur); - pp =xfs_btree_ptr_addr (cur,1 , block); +ASSERT (level >0 || (cur->bc_flags &XFS_BTREE_IROOT_RECORDS )); +if (level >0 ) + aptr = *xfs_btree_ptr_addr (cur,1 , block); +else + aptr.l =cpu_to_be64 (XFS_INO_TO_FSB (cur->bc_mp, + cur->bc_ino.ip->i_ino));/* Allocate the new block. If we can't do it, we're toast. Give up. */ - error =xfs_btree_alloc_block (cur, pp, &nptr, stat); + error =xfs_btree_alloc_block (cur, &aptr, &nptr, stat);if (error) goto error0;if (*stat ==0 )
@@ -3216,10 +3288,14 @@ xfs_btree_new_iroot( cblock->bb_u.s.bb_blkno = bno; } - error =xfs_btree_promote_node_iroot (cur, block, level, cbp, &nptr, - cblock); -if (error) - goto error0; +if (level >0 ) { + error =xfs_btree_promote_node_iroot (cur, block, level, cbp, + &nptr, cblock); +if (error) + goto error0; + }else { +xfs_btree_promote_leaf_iroot (cur, block, cbp, &nptr, cblock); + } *logflags |=XFS_ILOG_CORE |xfs_ilog_fbroot (cur->bc_ino.whichfork);
@@ -3716,6 +3792,45 @@ xfs_btree_insert(return error; } +/* +* Move the records from a child leaf block to the root block. +* +* Trickery here: The amount of memory we need per record for the incore root +* block changes when we convert a leaf block to an internal block. Therefore, +* we free the incore root block, change the tree height, allocate a new incore +* root, and copy the records from the doomed block into the new root. +*/ +STATIC void +xfs_btree_demote_leaf_child ( +struct xfs_btree_cur *cur, +struct xfs_btree_block *cblock, +int numrecs) +{ +union xfs_btree_rec *rp; +union xfs_btree_rec *crp; +struct xfs_btree_block *block; +size_t size; + +/* Zap the old root and change the tree height. */ +xfs_iroot_free (cur->bc_ino.ip, cur->bc_ino.whichfork); + cur->bc_levels[0 ].bp =NULL ; + cur->bc_nlevels--; + +/* +* Allocate a new internal root block buffer and reinitialize it with +* the leaf records in the child. +*/ + size = cur->bc_ops->iroot_ops->size (cur->bc_mp,0 , numrecs); +xfs_iroot_alloc (cur->bc_ino.ip, cur->bc_ino.whichfork, size); + block =xfs_btree_get_iroot (cur); +xfs_btree_init_block (cur->bc_mp, block, cur->bc_ops,0 , numrecs, + cur->bc_ino.ip->i_ino); + + rp =xfs_btree_rec_addr (cur,1 , block); + crp =xfs_btree_rec_addr (cur,1 , cblock); +xfs_btree_copy_recs (cur, rp, crp, numrecs); +} +/* * Move the keyptrs from a child node block to the root block. *
@@ -3797,14 +3912,19 @@ xfs_btree_kill_iroot(#endif ASSERT (cur->bc_flags &XFS_BTREE_ROOT_IN_INODE ); -ASSERT (cur->bc_nlevels >1 ); +ASSERT ((cur->bc_flags &XFS_BTREE_IROOT_RECORDS ) || + cur->bc_nlevels >1 );/* * Don't deal with the root block needs to be a leaf case. * We're just going to turn the thing back into extents anyway. */ level = cur->bc_nlevels -1 ; -if (level ==1 ) +if (level ==1 && !(cur->bc_flags &XFS_BTREE_IROOT_RECORDS )) + goto out0; + +/* If we're already a leaf, jump out. */ +if (level ==0 ) goto out0;/*
@@ -3834,9 +3954,13 @@ xfs_btree_kill_iroot(ASSERT (xfs_btree_ptr_is_null (cur, &ptr));#endif - error =xfs_btree_demote_node_child (cur, cblock, level, numrecs); -if (error) -return error; +if (level >1 ) { + error =xfs_btree_demote_node_child (cur, cblock, level, + numrecs); +if (error) +return error; + }else +xfs_btree_demote_leaf_child (cur, cblock, numrecs); error =xfs_btree_free_block (cur, cbp);if (error)
fs/xfs/libxfs/xfs_btree.h +1 -0
@@ -334,6 +334,7 @@ xfs_btree_cur_sizeof(unsigned int nlevels)* is dynamically allocated and must be freed when the cursor is deleted. */ #define XFS_BTREE_STAGING (1<<5) +#define XFS_BTREE_IROOT_RECORDS (1<<6)/* iroot can store records */ /* btree stored in memory; not compatible with ROOT_IN_INODE */ #ifdef CONFIG_XFS_IN_MEMORY_BTREE
fs/xfs/libxfs/xfs_btree_staging.c +3 -1
@@ -699,7 +699,9 @@ xfs_btree_bload_compute_geometry(* * Note that bmap btrees forbid records in the root. */ -if (level !=0 && nr_this_level <= avg_per_block) { +if ((level !=0 || + (cur->bc_flags &XFS_BTREE_IROOT_RECORDS )) && + nr_this_level <= avg_per_block) { nr_blocks++;break ; }
PATCH 14/14 xfs: update btree keys correctly when _insrec splits an inode root block
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In commit 2c813ad66a72, I partially fixed a bug wherein xfs_btree_insrec would erroneously try to update the parent's key for a block that had been split if we decided to insert the new record into the new block. The solution was to detect this situation and update the in-core key value that we pass up to the caller so that the caller will (eventually) add the new block to the parent level of the tree with the correct key.
However, I missed a subtlety about the way inode-rooted btrees work. If the full block was a maximally sized inode root block, we'll solve that fullness by moving the root block's records to a new block, resizing the root block, and updating the root to point to the new block. We don't pass a pointer to the new block to the caller because that work has already been done. The new record will /always/ land in the new block, so in this case we need to use xfs_btree_update_keys to update the keys.
This bug can theoretically manifest itself in the very rare case that we split a bmbt root block and the new record lands in the very first slot of the new block, though I've never managed to trigger it in practice. However, it is very easy to reproduce by running generic/522 with the realtime rmapbt patchset if rtinherit=1.
--- fs/xfs/libxfs/xfs_btree.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_btree.c +23 -6
@@ -3665,14 +3665,31 @@ xfs_btree_insrec(xfs_btree_log_block (cur, bp,XFS_BB_NUMRECS );/* -* If we just inserted into a new tree block, we have to -* recalculate nkey here because nkey is out of date. +* Update btree keys to reflect the newly added record or keyptr. +* There are three cases here to be aware of. Normally, all we have to +* do is walk towards the root, updating keys as necessary. * -* Otherwise we're just updating an existing block (having shoved -* some records into the new tree block), so use the regular key -* update mechanism. +* If the caller had us target a full block for the insertion, we dealt +* with that by calling the _make_block_unfull function. If the +* "make unfull" function splits the block, it'll hand us back the key +* and pointer of the new block. We haven't yet added the new block to +* the next level up, so if we decide to add the new record to the new +* block (bp->b_bn != old_bn), we have to update the caller's pointer +* so that the caller adds the new block with the correct key. +* +* However, there is a third possibility-- if the selected block is the +* root block of an inode-rooted btree and cannot be expanded further, +* the "make unfull" function moves the root block contents to a new +* block and updates the root block to point to the new block. In this +* case, no block pointer is passed back because the block has already +* been added to the btree. In this case, we need to use the regular +* key update function, just like the first case. This is critical for +* overlapping btrees, because the high key must be updated to reflect +* the entire tree, not just the subtree accessible through the first +* child of the root (which is now two levels down from the root). */ -if (bp &&xfs_buf_daddr (bp) != old_bn) { +if (!xfs_btree_ptr_is_null (cur, &nptr) && + bp &&xfs_buf_daddr (bp) != old_bn) {xfs_btree_get_keys (cur, block, lkey); }else if (xfs_btree_needs_key_update (cur, optr)) { error =xfs_btree_update_keys (cur, level);
cover xfs: clean up realtime type usage
In reply to Darrick J. WongHi all,
The realtime code uses xfs_rtblock_t and xfs_fsblock_t in a lot of places, and it's very confusing. Clean up all the type usage so that an xfs_rtblock_t is always a block within the realtime volume, an xfs_fileoff_t is always a file offset within a realtime metadata file, and an xfs_rtxnumber_t is always a rt extent within the realtime volume.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. 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=clean-up-realtime-units
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=clean-up-realtime-units
--- fs/xfs/libxfs/xfs_bmap.c | 4 - fs/xfs/libxfs/xfs_format.h | 2 fs/xfs/libxfs/xfs_rtbitmap.c | 121 ++++++++++----------- fs/xfs/libxfs/xfs_rtbitmap.h | 79 ++++++++++++++ fs/xfs/libxfs/xfs_sb.h | 2 fs/xfs/libxfs/xfs_types.c | 4 - fs/xfs/libxfs/xfs_types.h | 8 + fs/xfs/scrub/bmap.c | 4 + fs/xfs/scrub/common.c | 58 ++++++++++ fs/xfs/scrub/common.h | 17 +++ fs/xfs/scrub/fscounters.c | 2 fs/xfs/scrub/rtbitmap.c | 23 ++-- fs/xfs/scrub/rtsummary.c | 30 ++--- fs/xfs/scrub/scrub.c | 1 fs/xfs/scrub/scrub.h | 9 ++ fs/xfs/scrub/trace.h | 7 + fs/xfs/xfs_bmap_item.c | 2 fs/xfs/xfs_bmap_util.c | 18 +-- fs/xfs/xfs_fsmap.c | 2 fs/xfs/xfs_rtalloc.c | 245 ++++++++++++++++++++++-------------------- fs/xfs/xfs_rtalloc.h | 99 ++--------------- 21 files changed, 417 insertions(+), 320 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_rtbitmap.h
PATCH 1/11 xfs: refactor realtime scrubbing context management
From: Darrick J. Wong <[email protected]>
Create a pair of helpers to deal with setting up the necessary incore context to check metadata records against the realtime metadata. Right now this is limited to locking the realtime bitmap and summary inodes, but as we add rmap and reflink to the realtime device this will grow to include btree cursors.
--- fs/xfs/scrub/bmap.c | 2 ++ fs/xfs/scrub/common.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/common.h | 17 +++++++++++++ fs/xfs/scrub/rtbitmap.c | 7 ++---- fs/xfs/scrub/rtsummary.c | 24 +++++-------------- fs/xfs/scrub/scrub.c | 1 + fs/xfs/scrub/scrub.h | 9 +++++++ 7 files changed, 95 insertions(+), 23 deletions(-)
fs/xfs/scrub/bmap.c +2 -0
@@ -318,8 +318,10 @@ xchk_bmap_rt_iextent_xref(struct xchk_bmap_info *info, struct xfs_bmbt_irec *irec) { + xchk_rt_init(info->sc, &info->sc->sr, XCHK_RTLOCK_BITMAP_SHARED);xchk_xref_is_used_rt_space (info->sc, irec->br_startblock, irec->br_blockcount); +xchk_rt_unlock (info->sc, &info->sc->sr); }/* Cross-reference a single datadev extent record. */
fs/xfs/scrub/common.c +58 -0
64 lines not on this page · raw message
fs/xfs/scrub/common.h +17 -0
@@ -152,6 +152,23 @@ xchk_ag_init_existing(return error == -ENOENT ? -EFSCORRUPTED : error; } +/* Lock the rt bitmap in exclusive mode */ +#define XCHK_RTLOCK_BITMAP (1U << 31) +/* Lock the rt bitmap in shared mode */ +#define XCHK_RTLOCK_BITMAP_SHARED (1U << 30) +/* Lock the rt summary in exclusive mode */ +#define XCHK_RTLOCK_SUMMARY (1U << 29) +/* Lock the rt summary in shared mode */ +#define XCHK_RTLOCK_SUMMARY_SHARED (1U << 28) + +#define XCHK_RTLOCK_ALL (XCHK_RTLOCK_BITMAP | \ + XCHK_RTLOCK_BITMAP_SHARED | \ + XCHK_RTLOCK_SUMMARY | \ + XCHK_RTLOCK_SUMMARY_SHARED) + +void xchk_rt_init (struct xfs_scrub *sc,struct xchk_rt *sr, +unsigned int xchk_rtlock_flags); +void xchk_rt_unlock (struct xfs_scrub *sc,struct xchk_rt *sr);int xchk_ag_read_headers (struct xfs_scrub *sc,xfs_agnumber_t agno,struct xchk_ag *sa);void xchk_ag_btcur_free (struct xchk_ag *sa);
fs/xfs/scrub/rtbitmap.c +2 -5
@@ -44,7 +44,7 @@ xchk_setup_rtbitmap(if (error)return error; -xchk_ilock (sc,XFS_ILOCK_EXCL |XFS_ILOCK_RTBITMAP ); +xchk_rt_init (sc, &sc->sr,XCHK_RTLOCK_BITMAP );return 0 ; }
@@ -157,13 +157,10 @@ xchk_xref_is_used_rt_space(do_div (startext, sc->mp->m_sb.sb_rextsize);do_div (endext, sc->mp->m_sb.sb_rextsize); extcount = endext - startext +1 ; -xfs_ilock (sc->mp->m_rbmip,XFS_ILOCK_SHARED |XFS_ILOCK_RTBITMAP ); error =xfs_rtalloc_extent_is_free (sc->mp, sc->tp, startext, extcount, &is_free);if (!xchk_should_check_xref (sc, &error,NULL )) - goto out_unlock; +return ;if (is_free)xchk_ino_xref_set_corrupt (sc, sc->mp->m_rbmip->i_ino); -out_unlock: -xfs_iunlock (sc->mp->m_rbmip,XFS_ILOCK_SHARED |XFS_ILOCK_RTBITMAP ); }
fs/xfs/scrub/rtsummary.c +6 -18
@@ -75,14 +75,8 @@ xchk_setup_rtsummary(if (error)return error; -/* -* Locking order requires us to take the rtbitmap first. We must be -* careful to unlock it ourselves when we are done with the rtbitmap -* file since the scrub infrastructure won't do that for us. Only -* then we can lock the rtsummary inode. -*/ -xfs_ilock (mp->m_rbmip,XFS_ILOCK_SHARED |XFS_ILOCK_RTBITMAP ); -xchk_ilock (sc,XFS_ILOCK_EXCL |XFS_ILOCK_RTSUM ); +xchk_rt_init (sc, &sc->sr, +XCHK_RTLOCK_SUMMARY |XCHK_RTLOCK_BITMAP_SHARED );return 0 ; }
@@ -248,7 +242,7 @@ xchk_rtsummary(/* Invoke the fork scrubber. */ error =xchk_metadata_inode_forks (sc);if (error || (sc->sm->sm_flags &XFS_SCRUB_OFLAG_CORRUPT )) - goto out_rbm; +return error;/* Construct the new summary file from the rtbitmap. */ error =xchk_rtsum_compute (sc);
@@ -258,17 +252,11 @@ xchk_rtsummary(* error since we're checking the summary file. */ xchk_ino_xref_set_corrupt (sc, mp->m_rbmip->i_ino); - error =0 ; - goto out_rbm; +return 0 ; }if (error) - goto out_rbm; +return error;/* Does the computed summary file match the actual rtsummary file? */ - error =xchk_rtsum_compare (sc); - -out_rbm: -/* Unlock the rtbitmap since we're done with it. */ -xfs_iunlock (mp->m_rbmip,XFS_ILOCK_SHARED |XFS_ILOCK_RTBITMAP ); -return error; +return xchk_rtsum_compare (sc); }
fs/xfs/scrub/scrub.c +1 -0
@@ -189,6 +189,7 @@ xchk_teardown(xfs_trans_cancel (sc->tp); sc->tp =NULL ; } +xchk_rt_unlock (sc, &sc->sr);if (sc->ip) {if (sc->ilock_flags)xchk_iunlock (sc, sc->ilock_flags);
fs/xfs/scrub/scrub.h +9 -0
@@ -67,6 +67,12 @@ struct xchk_ag {struct xfs_btree_cur *refc_cur; }; +/* Inode lock state for the RT volume. */ +struct xchk_rt { +/* XCHK_RTLOCK_* lock state */ +unsigned int rtlock_flags; +}; +struct xfs_scrub {/* General scrub state. */ struct xfs_mount *mp;
@@ -125,6 +131,9 @@ struct xfs_scrub {/* State tracking for single-AG operations. */ struct xchk_ag sa; + +/* State tracking for realtime operations. */ +struct xchk_rt sr; };/* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
PATCH 2/11 xfs: bump max fsgeom struct version
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The latest version of the fs geometry structure is v5.
--- fs/xfs/libxfs/xfs_sb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/libxfs/xfs_sb.h +1 -1
@@ -25,7 +25,7 @@ extern uint64_t xfs_sb_version_to_features(struct xfs_sb *sbp);extern int xfs_update_secondary_sbs (struct xfs_mount *mp); -#define XFS_FS_GEOM_MAX_STRUCT_VER (4) +#define XFS_FS_GEOM_MAX_STRUCT_VER (5)extern void xfs_fs_geometry (struct xfs_mount *mp,struct xfs_fsop_geom *geo,int struct_version); extern int xfs_sb_read_secondary(struct xfs_mount *mp,
PATCH 3/11 xfs: prevent rt growfs when quota is enabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Quotas aren't (yet) supported with realtime, so we shouldn't allow userspace to set up a realtime section when quotas are enabled, even if they attached one via mount options. IOWS, you shouldn't be able to do:
# mkfs.xfs -f /dev/sda # mount /dev/sda /mnt -o rtdev=/dev/sdb # xfs_growfs -r /mnt
--- fs/xfs/xfs_rtalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_rtalloc.c +1 -1
@@ -959,7 +959,7 @@ xfs_growfs_rt(return -EINVAL ;/* Unsupported realtime features. */ -if (xfs_has_rmapbt (mp) ||xfs_has_reflink (mp)) +if (xfs_has_rmapbt (mp) ||xfs_has_reflink (mp) ||xfs_has_quota (mp))return -EOPNOTSUPP ; nrblocks = in->newblocks;
PATCH 4/11 xfs: rt stubs should return negative errnos when rt disabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When realtime support is not compiled into the kernel, these functions should return negative errnos, not positive errnos. While we're at it, fix a broken macro declaration.
--- fs/xfs/xfs_rtalloc.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
fs/xfs/xfs_rtalloc.h +12 -12
@@ -143,17 +143,17 @@ int xfs_rtalloc_reinit_frextents(struct xfs_mount *mp);int xfs_rtfile_convert_unwritten (struct xfs_inode *ip,loff_t pos,uint64_t len);#else -# define xfs_rtallocate_extent (t,b,min,max,l,f,p,rb) (ENOSYS) -# define xfs_rtfree_extent (t,b,l) (ENOSYS) -# define xfs_rtfree_blocks (t,rb,rl) (ENOSYS) -# define xfs_rtpick_extent (m,t,l,rb) (ENOSYS) -# define xfs_growfs_rt (mp,in) (ENOSYS) -# define xfs_rtalloc_query_range (t,l,h,f,p) (ENOSYS) -# define xfs_rtalloc_query_all (m,t,f,p) (ENOSYS) -# define xfs_rtbuf_get (m,t,b,i,p) (ENOSYS) -# define xfs_verify_rtbno (m, r) (false) -# define xfs_rtalloc_extent_is_free (m,t,s,l,i) (ENOSYS) -# define xfs_rtalloc_reinit_frextents (m) (0) +# define xfs_rtallocate_extent (t,b,min,max,l,f,p,rb) (-ENOSYS) +# define xfs_rtfree_extent (t,b,l) (-ENOSYS) +# define xfs_rtfree_blocks (t,rb,rl) (-ENOSYS) +# define xfs_rtpick_extent (m,t,l,rb) (-ENOSYS) +# define xfs_growfs_rt (mp,in) (-ENOSYS) +# define xfs_rtalloc_query_range (m,t,l,h,f,p) (-ENOSYS) +# define xfs_rtalloc_query_all (m,t,f,p) (-ENOSYS) +# define xfs_rtbuf_get (m,t,b,i,p) (-ENOSYS) +# define xfs_verify_rtbno (m, r) (false) +# define xfs_rtalloc_extent_is_free (m,t,s,l,i) (-ENOSYS) +# define xfs_rtalloc_reinit_frextents (m) (0)static inline int /* error */ xfs_rtmount_init (xfs_mount_t *mp)/* file system mount structure */
@@ -164,7 +164,7 @@ xfs_rtmount_init(xfs_warn (mp,"Not built with CONFIG_XFS_RT" ); return -ENOSYS; } -# define xfs_rtmount_inodes (m) (((mp)->m_sb.sb_rblocks == 0)? 0 : (ENOSYS)) +# define xfs_rtmount_inodes (m) (((mp)->m_sb.sb_rblocks == 0)? 0 : (-ENOSYS))# define xfs_rtunmount_inodes (m)# define xfs_rtfile_convert_unwritten (ip, pos, len) (0)#endif /* CONFIG_XFS_RT */
PATCH 5/11 xfs: make sure maxlen is still congruent with prod when rounding down
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In commit 2a6ca4baed62, we tried to fix an overflow problem in the realtime allocator that was caused by an overly large maxlen value causing xfs_rtcheck_range to run off the end of the realtime bitmap. Unfortunately, there is a subtle bug here -- maxlen (and minlen) both have to be aligned with @prod, but @prod can be larger than 1 if the user has set an extent size hint on the file, and that extent size hint is larger than the realtime extent size.
If the rt free space extents are not aligned to this file's extszhint because other files without extent size hints allocated space (or the number of rt extents is similarly not aligned), then it's possible that maxlen after clamping to sb_rextents will no longer be aligned to prod. The allocation will succeed just fine, but we still trip the assertion.
Fix the problem by reducing maxlen by any misalignment with prod. While we're at it, split the assertions into two so that we can tell which value had the bad alignment.
--- fs/xfs/xfs_rtalloc.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
fs/xfs/xfs_rtalloc.c +19 -5
@@ -252,8 +252,13 @@ xfs_rtallocate_extent_block( end =XFS_BLOCKTOBIT (mp, bbno +1 ) -1 ; i <= end; i++) { -/* Make sure we don't scan off the end of the rt volume. */ +/* +* Make sure we don't run off the end of the rt volume. Be +* careful that adjusting maxlen downwards doesn't cause us to +* fail the alignment checks. +*/ maxlen =min (mp->m_sb.sb_rextents, i + maxlen) - i; + maxlen -= maxlen % prod;/* * See if there's a free extent of maxlen starting at i.
@@ -360,7 +365,8 @@ xfs_rtallocate_extent_exact(int isfree;/* extent is free */ xfs_rtblock_t next;/* next block to try (dummy) */ -ASSERT (minlen % prod ==0 && maxlen % prod ==0 ); +ASSERT (minlen % prod ==0 ); +ASSERT (maxlen % prod ==0 );/* * Check if the range in question (for maxlen) is free. */
@@ -443,7 +449,9 @@ xfs_rtallocate_extent_near(xfs_rtblock_t n;/* next block to try */ xfs_rtblock_t r;/* result block */ -ASSERT (minlen % prod ==0 && maxlen % prod ==0 ); +ASSERT (minlen % prod ==0 ); +ASSERT (maxlen % prod ==0 ); +/* * If the block number given is off the end, silently set it to * the last block.
@@ -451,8 +459,13 @@ xfs_rtallocate_extent_near(if (bno >= mp->m_sb.sb_rextents) bno = mp->m_sb.sb_rextents -1 ; -/* Make sure we don't run off the end of the rt volume. */ +/* +* Make sure we don't run off the end of the rt volume. Be careful +* that adjusting maxlen downwards doesn't cause us to fail the +* alignment checks. +*/ maxlen =min (mp->m_sb.sb_rextents, bno + maxlen) - bno; + maxlen -= maxlen % prod;if (maxlen < minlen) { *rtblock =NULLRTBLOCK ;return 0 ;
@@ -643,7 +656,8 @@ xfs_rtallocate_extent_size(xfs_rtblock_t r;/* result block number */ xfs_suminfo_t sum;/* summary information for extents */ -ASSERT (minlen % prod ==0 && maxlen % prod ==0 ); +ASSERT (minlen % prod ==0 ); +ASSERT (maxlen % prod ==0 );ASSERT (maxlen !=0 );/*
PATCH 6/11 xfs: move the xfs_rtbitmap.c declarations to xfs_rtbitmap.h
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move all the declarations for functionality in xfs_rtbitmap.c into a separate xfs_rtbitmap.h header file.
--- fs/xfs/libxfs/xfs_bmap.c | 2 + fs/xfs/libxfs/xfs_rtbitmap.c | 1 + fs/xfs/libxfs/xfs_rtbitmap.h | 82 ++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/fscounters.c | 2 + fs/xfs/scrub/rtbitmap.c | 2 + fs/xfs/scrub/rtsummary.c | 2 + fs/xfs/xfs_fsmap.c | 2 + fs/xfs/xfs_rtalloc.c | 1 + fs/xfs/xfs_rtalloc.h | 73 ------------------------------------- 9 files changed, 89 insertions(+), 78 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_rtbitmap.h
fs/xfs/libxfs/xfs_bmap.c +1 -1
@@ -21,7 +21,7 @@#include "xfs_bmap.h" #include "xfs_bmap_util.h" #include "xfs_bmap_btree.h" -#include "xfs_rtalloc.h" +#include "xfs_rtbitmap.h" #include "xfs_errortag.h" #include "xfs_error.h" #include "xfs_quota.h"
fs/xfs/libxfs/xfs_rtbitmap.c +1 -0
@@ -17,6 +17,7 @@#include "xfs_rtalloc.h" #include "xfs_error.h" #include "xfs_health.h" +#include "xfs_rtbitmap.h" /* * Realtime allocator bitmap functions shared with userspace.
fs/xfs/libxfs/xfs_rtbitmap.h new file +82 -0
82 lines not on this page · raw message
fs/xfs/scrub/fscounters.c +1 -1
@@ -14,7 +14,7 @@#include "xfs_health.h" #include "xfs_btree.h" #include "xfs_ag.h" -#include "xfs_rtalloc.h" +#include "xfs_rtbitmap.h" #include "xfs_inode.h" #include "xfs_icache.h" #include "scrub/scrub.h"
fs/xfs/scrub/rtbitmap.c +1 -1
@@ -11,7 +11,7 @@#include "xfs_mount.h" #include "xfs_log_format.h" #include "xfs_trans.h" -#include "xfs_rtalloc.h" +#include "xfs_rtbitmap.h" #include "xfs_inode.h" #include "xfs_bmap.h" #include "scrub/scrub.h"
fs/xfs/scrub/rtsummary.c +1 -1
@@ -13,7 +13,7 @@#include "xfs_inode.h" #include "xfs_log_format.h" #include "xfs_trans.h" -#include "xfs_rtalloc.h" +#include "xfs_rtbitmap.h" #include "xfs_bit.h" #include "xfs_bmap.h" #include "scrub/scrub.h"
fs/xfs/xfs_fsmap.c +1 -1
@@ -23,7 +23,7 @@#include "xfs_refcount.h" #include "xfs_refcount_btree.h" #include "xfs_alloc_btree.h" -#include "xfs_rtalloc.h" +#include "xfs_rtbitmap.h" #include "xfs_ag.h" /* Convert an xfs_fsmap to an fsmap. */
fs/xfs/xfs_rtalloc.c +1 -0
@@ -24,6 +24,7 @@#include "xfs_trace.h" #include "xfs_da_format.h" #include "xfs_imeta.h" +#include "xfs_rtbitmap.h" /* * Read and return the summary information for a given extent size,
fs/xfs/xfs_rtalloc.h +0 -73
98 lines not on this page · raw message
PATCH 7/11 xfs: convert xfs_extlen_t to xfs_rtxlen_t in the rt allocator
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In most of the filesystem, we use xfs_extlen_t to store the length of a file (or AG) space mapping in units of fs blocks. Unfortunately, the realtime allocator also uses it to store the length of a rt space mapping in units of rt extents. This is confusing, since one rt extent can consist of many fs blocks.
Separate the two by introducing a new type (xfs_rtxlen_t) to store the length of a space mapping (in units of realtime extents) that would be found in a file.
--- fs/xfs/libxfs/xfs_rtbitmap.c | 12 +++++----- fs/xfs/libxfs/xfs_rtbitmap.h | 11 ++++----- fs/xfs/libxfs/xfs_types.h | 1 + fs/xfs/scrub/rtbitmap.c | 2 +- fs/xfs/xfs_bmap_util.c | 6 +++-- fs/xfs/xfs_rtalloc.c | 50 +++++++++++++++++++++--------------------- fs/xfs/xfs_rtalloc.h | 10 ++++---- 7 files changed, 46 insertions(+), 46 deletions(-)
fs/xfs/libxfs/xfs_rtbitmap.c +6 -6
@@ -541,7 +541,7 @@ xfs_rtmodify_range( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ xfs_rtblock_t start, /* starting block to modify */ - xfs_extlen_t len, /* length of extent to modify */ + xfs_rtxlen_t len, /* length of extent to modify */ int val) /* 1 for free, 0 for allocated */ { xfs_rtword_t *b;/* current word in buffer */
@@ -697,7 +697,7 @@ xfs_rtfree_range( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ xfs_rtblock_t start, /* starting block to free */ - xfs_extlen_t len, /* length to free */ + xfs_rtxlen_t len, /* length to free */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fsblock_t *rsb) /* in/out: summary block number */ {
@@ -773,7 +773,7 @@ xfs_rtcheck_range( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ xfs_rtblock_t start, /* starting block number of extent */ - xfs_extlen_t len, /* length of extent */ + xfs_rtxlen_t len, /* length of extent */ int val, /* 1 for free, 0 for allocated */ xfs_rtblock_t *new,/* out: first block not matching */ int *stat) /* out: 1 for matches, 0 for not */
@@ -949,7 +949,7 @@ xfs_rtcheck_alloc_range( xfs_mount_t *mp, /* file system mount point */ xfs_trans_t *tp, /* transaction pointer */ xfs_rtblock_t bno, /* starting block number of extent */ - xfs_extlen_t len) /* length of extent */ + xfs_rtxlen_t len) /* length of extent */ {xfs_rtblock_t new;/* dummy for xfs_rtcheck_range */ int stat;
@@ -972,7 +972,7 @@ int /* error */xfs_rtfree_extent ( xfs_trans_t *tp,/* transaction pointer */ xfs_rtblock_t bno, /* starting block number to free */ - xfs_extlen_t len) /* length of extent freed */ + xfs_rtxlen_t len) /* length of extent freed */ {int error;/* error value */ xfs_mount_t *mp;/* file system mount structure */
@@ -1123,7 +1123,7 @@ xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp, xfs_rtblock_t start, - xfs_extlen_t len, + xfs_rtxlen_t len, bool *is_free) { xfs_rtblock_t end;
fs/xfs/libxfs/xfs_rtbitmap.h +5 -6
@@ -26,7 +26,7 @@ typedef int (*xfs_rtalloc_query_range_fn)(int xfs_rtbuf_get (struct xfs_mount *mp,struct xfs_trans *tp,xfs_rtblock_t block,int issum,struct xfs_buf **bpp);int xfs_rtcheck_range (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_extlen_t len,int val, +xfs_rtblock_t start,xfs_rtxlen_t len,int val,xfs_rtblock_t *new,int *stat); int xfs_rtfind_back(struct xfs_mount *mp, struct xfs_trans *tp, xfs_rtblock_t start, xfs_rtblock_t limit,
@@ -35,7 +35,7 @@ int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp, xfs_rtblock_t start, xfs_rtblock_t limit, xfs_rtblock_t *rtblock);int xfs_rtmodify_range (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_extlen_t len,int val); +xfs_rtblock_t start,xfs_rtxlen_t len,int val); int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp, int log, xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp, xfs_fsblock_t *rsb,
@@ -44,7 +44,7 @@ int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log, xfs_rtblock_t bbno, int delta, struct xfs_buf **rbpp, xfs_fsblock_t *rsb);int xfs_rtfree_range (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_extlen_t len, +xfs_rtblock_t start,xfs_rtxlen_t len,struct xfs_buf **rbpp,xfs_fsblock_t *rsb); int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp, const struct xfs_rtalloc_rec *low_rec,
@@ -53,9 +53,8 @@ int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp,int xfs_rtalloc_query_all (struct xfs_mount *mp,struct xfs_trans *tp,xfs_rtalloc_query_range_fn fn,void *priv); -bool xfs_verify_rtbno (struct xfs_mount *mp,xfs_rtblock_t rtbno);int xfs_rtalloc_extent_is_free (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_extlen_t len, +xfs_rtblock_t start,xfs_rtxlen_t len,bool *is_free);/* * Free an extent in the realtime subvolume. Length is expressed in
@@ -65,7 +64,7 @@ int /* error */xfs_rtfree_extent ( struct xfs_trans *tp, /* transaction pointer */ xfs_rtblock_t bno, /* starting block number to free */ - xfs_extlen_t len); /* length of extent freed */ + xfs_rtxlen_t len); /* length of extent freed *//* Same as above, but in units of rt blocks. */ int xfs_rtfree_blocks(struct xfs_trans *tp, xfs_fsblock_t rtbno,
fs/xfs/libxfs/xfs_types.h +1 -0
@@ -11,6 +11,7 @@ typedef uint32_t prid_t; /* project ID */typedef uint32_t xfs_agblock_t ;/* blockno in alloc. group */ typedef uint32_t xfs_agino_t ;/* inode # within allocation grp */ typedef uint32_t xfs_extlen_t ;/* extent length in blocks */ +typedef uint32_t xfs_rtxlen_t ;/* file extent length in rtextents */ typedef uint32_t xfs_agnumber_t ;/* allocation group number */ typedef uint64_t xfs_extnum_t ;/* # of extents in a file */ typedef uint32_t xfs_aextnum_t ;/* # extents in an attribute fork */
fs/xfs/scrub/rtbitmap.c +1 -1
@@ -145,7 +145,7 @@ xchk_xref_is_used_rt_space( {xfs_rtblock_t startext;xfs_rtblock_t endext; -xfs_rtblock_t extcount; +xfs_rtxlen_t extcount;bool is_free;int error;
fs/xfs/xfs_bmap_util.c +3 -3
@@ -77,13 +77,13 @@ xfs_bmap_rtalloc(struct xfs_mount *mp = ap->ip->i_mount;xfs_fileoff_t orig_offset = ap->offset;xfs_rtblock_t rtb; -xfs_extlen_t prod =0 ;/* product factor for allocators */ +xfs_rtxlen_t prod =0 ;/* product factor for allocators */ xfs_extlen_t mod =0 ;/* product factor for allocators */ -xfs_extlen_t ralen =0 ;/* realtime allocation length */ +xfs_rtxlen_t ralen =0 ;/* realtime allocation length */ xfs_extlen_t align;/* minimum allocation alignment */ xfs_extlen_t orig_length = ap->length;xfs_extlen_t minlen = mp->m_sb.sb_rextsize; -xfs_extlen_t raminlen; +xfs_rtxlen_t raminlen;bool rtlocked = false;bool ignore_locality = false;int error;
fs/xfs/xfs_rtalloc.c +25 -25
117 lines not on this page · raw message
fs/xfs/xfs_rtalloc.h +5 -5
@@ -25,11 +25,11 @@ int /* error */xfs_rtallocate_extent ( struct xfs_trans *tp, /* transaction pointer */ xfs_rtblock_t bno, /* starting block number to allocate */ - xfs_extlen_t minlen, /* minimum length to allocate */ - xfs_extlen_t maxlen, /* maximum length to allocate */ - xfs_extlen_t *len, /* out: actual length allocated */ + xfs_rtxlen_t minlen, /* minimum length to allocate */ + xfs_rtxlen_t maxlen, /* maximum length to allocate */ + xfs_rtxlen_t *len, /* out: actual length allocated */ int wasdel, /* was a delayed allocation extent */ - xfs_extlen_t prod, /* extent product factor */ + xfs_rtxlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock); /* out: start block allocated */
@@ -62,7 +62,7 @@ int /* error */xfs_rtpick_extent ( struct xfs_mount *mp, /* file system mount point */ struct xfs_trans *tp, /* transaction pointer */ - xfs_extlen_t len, /* allocation length (rtextents) */ + xfs_rtxlen_t len, /* allocation length (rtextents) */ xfs_rtblock_t *pick); /* result rt extent *//*
PATCH 8/11 xfs: convert rt bitmap/summary block numbers to xfs_fileoff_t
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
We should use xfs_fileoff_t to store the file block offset of any location within the realtime bitmap or summary files.
--- fs/xfs/libxfs/xfs_rtbitmap.c | 22 +++++++++++----------- fs/xfs/libxfs/xfs_rtbitmap.h | 12 ++++++------ fs/xfs/scrub/rtbitmap.c | 2 +- fs/xfs/xfs_rtalloc.c | 34 +++++++++++++++++----------------- 4 files changed, 35 insertions(+), 35 deletions(-)
fs/xfs/libxfs/xfs_rtbitmap.c +11 -11
@@ -56,7 +56,7 @@ intxfs_rtbuf_get ( xfs_mount_t *mp,/* file system mount structure */ xfs_trans_t *tp,/* transaction pointer */ - xfs_rtblock_t block, /* block number in bitmap or summary */ + xfs_fileoff_t block, /* block number in bitmap or summary */ int issum, /* is summary not bitmap */ struct xfs_buf **bpp) /* output: buffer for the block */ {
@@ -108,7 +108,7 @@ xfs_rtfind_back( {xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */ -xfs_rtblock_t block;/* bitmap block number */ +xfs_fileoff_t block;/* bitmap block number */ struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */
@@ -283,7 +283,7 @@ xfs_rtfind_forw( {xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */ -xfs_rtblock_t block;/* bitmap block number */ +xfs_fileoff_t block;/* bitmap block number */ struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */
@@ -453,15 +453,15 @@ xfs_rtmodify_summary_int( xfs_mount_t *mp, /* file system mount structure */ xfs_trans_t *tp, /* transaction pointer */ int log, /* log2 of extent size */ - xfs_rtblock_t bbno, /* bitmap block number */ + xfs_fileoff_t bbno, /* bitmap block number */ int delta, /* change to make to summary info */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb, /* in/out: summary block number */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_suminfo_t *sum) /* out: summary info for this block */ {struct xfs_buf *bp;/* buffer for the summary block */ int error;/* error value */ -xfs_fsblock_t sb;/* summary fsblock */ +xfs_fileoff_t sb;/* summary fsblock */ int so;/* index into the summary file */ xfs_suminfo_t *sp;/* pointer to returned data */
@@ -523,10 +523,10 @@ xfs_rtmodify_summary( xfs_mount_t *mp, /* file system mount structure */ xfs_trans_t *tp, /* transaction pointer */ int log, /* log2 of extent size */ - xfs_rtblock_t bbno, /* bitmap block number */ + xfs_fileoff_t bbno, /* bitmap block number */ int delta, /* change to make to summary info */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb) /* in/out: summary block number */ + xfs_fileoff_t *rsb) /* in/out: summary block number */ {return xfs_rtmodify_summary_int (mp, tp, log, bbno, delta, rbpp, rsb,NULL );
@@ -546,7 +546,7 @@ xfs_rtmodify_range( {xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */ -xfs_rtblock_t block;/* bitmap block number */ +xfs_fileoff_t block;/* bitmap block number */ struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */
@@ -699,7 +699,7 @@ xfs_rtfree_range(xfs_rtblock_t start,/* starting block to free */ xfs_rtxlen_t len, /* length to free */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb) /* in/out: summary block number */ + xfs_fileoff_t *rsb) /* in/out: summary block number */ { xfs_rtblock_t end; /* end of the freed extent */int error;/* error value */
@@ -780,7 +780,7 @@ xfs_rtcheck_range( {xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */ -xfs_rtblock_t block;/* bitmap block number */ +xfs_fileoff_t block;/* bitmap block number */ struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */
fs/xfs/libxfs/xfs_rtbitmap.h +6 -6
@@ -24,7 +24,7 @@ typedef int (*xfs_rtalloc_query_range_fn)(#ifdef CONFIG_XFS_RT int xfs_rtbuf_get (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t block,int issum,struct xfs_buf **bpp); +xfs_fileoff_t block,int issum,struct xfs_buf **bpp);int xfs_rtcheck_range (struct xfs_mount *mp,struct xfs_trans *tp,xfs_rtblock_t start,xfs_rtxlen_t len,int val,xfs_rtblock_t *new,int *stat);
@@ -37,15 +37,15 @@ int xfs_rtfind_forw(struct xfs_mount *mp, struct xfs_trans *tp,int xfs_rtmodify_range (struct xfs_mount *mp,struct xfs_trans *tp,xfs_rtblock_t start,xfs_rtxlen_t len,int val);int xfs_rtmodify_summary_int (struct xfs_mount *mp,struct xfs_trans *tp, -int log,xfs_rtblock_t bbno,int delta, -struct xfs_buf **rbpp,xfs_fsblock_t *rsb, +int log,xfs_fileoff_t bbno,int delta, +struct xfs_buf **rbpp,xfs_fileoff_t *rsb,xfs_suminfo_t *sum);int xfs_rtmodify_summary (struct xfs_mount *mp,struct xfs_trans *tp,int log, -xfs_rtblock_t bbno,int delta,struct xfs_buf **rbpp, -xfs_fsblock_t *rsb); +xfs_fileoff_t bbno,int delta,struct xfs_buf **rbpp, +xfs_fileoff_t *rsb);int xfs_rtfree_range (struct xfs_mount *mp,struct xfs_trans *tp,xfs_rtblock_t start,xfs_rtxlen_t len, -struct xfs_buf **rbpp,xfs_fsblock_t *rsb); +struct xfs_buf **rbpp,xfs_fileoff_t *rsb); int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp, const struct xfs_rtalloc_rec *low_rec, const struct xfs_rtalloc_rec *high_rec,
fs/xfs/scrub/rtbitmap.c +1 -1
@@ -77,7 +77,7 @@ xchk_rtbitmap_check_extents( {struct xfs_mount *mp = sc->mp;struct xfs_bmbt_irec map; -xfs_rtblock_t off; +xfs_fileoff_t off;int nmap;int error =0 ;
fs/xfs/xfs_rtalloc.c +17 -17
@@ -37,9 +37,9 @@ xfs_rtget_summary( xfs_mount_t *mp, /* file system mount structure */ xfs_trans_t *tp, /* transaction pointer */ int log, /* log2 of extent size */ - xfs_rtblock_t bbno, /* bitmap block number */ + xfs_fileoff_t bbno, /* bitmap block number */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb, /* in/out: summary block number */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_suminfo_t *sum) /* out: summary info for this block */ {return xfs_rtmodify_summary_int (mp, tp, log, bbno,0 , rbpp, rsb, sum);
@@ -55,9 +55,9 @@ xfs_rtany_summary(xfs_trans_t *tp,/* transaction pointer */ int low, /* low log2 extent size */ int high, /* high log2 extent size */ - xfs_rtblock_t bbno, /* bitmap block number */ + xfs_fileoff_t bbno, /* bitmap block number */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb, /* in/out: summary block number */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ int *stat) /* out: any good extents here? */ { int error; /* error value */
@@ -109,12 +109,12 @@ xfs_rtcopy_summary( xfs_mount_t *nmp, /* new file system mount point */ xfs_trans_t *tp) /* transaction pointer */ { -xfs_rtblock_t bbno;/* bitmap block number */ +xfs_fileoff_t bbno;/* bitmap block number */ struct xfs_buf *bp;/* summary buffer */ int error;/* error return value */ int log;/* summary level number (log length) */ xfs_suminfo_t sum;/* summary data */ -xfs_fsblock_t sumbno;/* summary block number */ +xfs_fileoff_t sumbno;/* summary block number */ bp =NULL ;for (log = omp->m_rsumlevels -1 ; log >=0 ; log--) {
@@ -151,7 +151,7 @@ xfs_rtallocate_range(xfs_rtblock_t start,/* start block to allocate */ xfs_rtxlen_t len, /* length to allocate */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb) /* in/out: summary block number */ + xfs_fileoff_t *rsb) /* in/out: summary block number */ { xfs_rtblock_t end; /* end of the allocated extent */int error;/* error value */
@@ -227,13 +227,13 @@ STATIC int /* error */xfs_rtallocate_extent_block ( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ - xfs_rtblock_t bbno, /* bitmap block number */ + xfs_fileoff_t bbno, /* bitmap block number */ xfs_rtxlen_t minlen, /* minimum length to allocate */ xfs_rtxlen_t maxlen, /* maximum length to allocate */ xfs_rtxlen_t *len,/* out: actual length allocated */ xfs_rtblock_t *nextp,/* out: next block to try */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb,/* in/out: summary block number */ + xfs_fileoff_t *rsb,/* in/out: summary block number */ xfs_rtxlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock) /* out: start block allocated */ {
@@ -357,7 +357,7 @@ xfs_rtallocate_extent_exact(xfs_rtxlen_t maxlen,/* maximum length to allocate */ xfs_rtxlen_t *len, /* out: actual length allocated */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb, /* in/out: summary block number */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_rtxlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock) /* out: start block allocated */ {
@@ -437,12 +437,12 @@ xfs_rtallocate_extent_near(xfs_rtxlen_t maxlen,/* maximum length to allocate */ xfs_rtxlen_t *len, /* out: actual length allocated */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb, /* in/out: summary block number */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_rtxlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock) /* out: start block allocated */ { int any; /* any useful extents from summary */ -xfs_rtblock_t bbno;/* bitmap block number */ +xfs_fileoff_t bbno;/* bitmap block number */ int error;/* error value */ int i;/* bitmap block offset (loop control) */ int j;/* secondary loop control */
@@ -646,12 +646,12 @@ xfs_rtallocate_extent_size(xfs_rtxlen_t maxlen,/* maximum length to allocate */ xfs_rtxlen_t *len, /* out: actual length allocated */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ - xfs_fsblock_t *rsb, /* in/out: summary block number */ + xfs_fileoff_t *rsb, /* in/out: summary block number */ xfs_rtxlen_t prod, /* extent product factor */ xfs_rtblock_t *rtblock) /* out: start block allocated */ { int error; /* error value */ -int i;/* bitmap block number */ +xfs_fileoff_t i;/* bitmap block number */ int l;/* level number (loop control) */ xfs_rtblock_t n;/* next block to be tried */ xfs_rtblock_t r;/* result block number */
@@ -927,7 +927,7 @@ xfs_growfs_rt( xfs_mount_t *mp, /* mount point for filesystem */ xfs_growfs_rt_t *in) /* growfs rt input struct */ { -xfs_rtblock_t bmbno;/* bitmap block number */ +xfs_fileoff_t bmbno;/* bitmap block number */ struct xfs_buf *bp;/* temporary buffer */ int error;/* error return value */ xfs_mount_t *nmp;/* new (fake) mount structure */
@@ -942,7 +942,7 @@ xfs_growfs_rt(xfs_extlen_t rbmblocks;/* current number of rt bitmap blocks */ xfs_extlen_t rsumblocks;/* current number of rt summary blks */ xfs_sb_t *sbp;/* old superblock */ -xfs_fsblock_t sumbno;/* summary block number */ +xfs_fileoff_t sumbno;/* summary block number */ uint8_t *rsum_cache;/* old summary cache */ sbp = &mp->m_sb;
@@ -1205,7 +1205,7 @@ xfs_rtallocate_extent(xfs_mount_t *mp = tp->t_mountp;int error;/* error value */ xfs_rtblock_t r;/* result allocated block */ -xfs_fsblock_t sb;/* summary file block number */ +xfs_fileoff_t sb;/* summary file block number */ struct xfs_buf *sumbp;/* summary file block buffer */ ASSERT (xfs_isilocked (mp->m_rbmip,XFS_ILOCK_EXCL ));
PATCH 9/11 xfs: convert rt bitmap extent lengths to xfs_rtbxlen_t
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
XFS uses xfs_rtblock_t for many different uses, which makes it much more difficult to perform a unit analysis on the codebase. One of these (ab)uses is when we need to store the length of a free space extent as stored in the realtime bitmap. Because there can be up to 2^64 realtime extents in a filesystem, we need a new type that is larger than xfs_rtxlen_t for callers that are querying the bitmap directly. This means scrub and growfs.
Create this type as "xfs_rtbxlen_t" and use it to store 64-bit rtx lengths. 'b' stands for 'bitmap' or 'big'; reader's choice.
--- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/libxfs/xfs_rtbitmap.h | 2 +- fs/xfs/libxfs/xfs_types.h | 1 + fs/xfs/scrub/trace.h | 3 ++- 4 files changed, 5 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_format.h +1 -1
@@ -97,7 +97,7 @@ typedef struct xfs_sb {uint32_t sb_blocksize;/* logical block size, bytes */ xfs_rfsblock_t sb_dblocks;/* number of data blocks */ xfs_rfsblock_t sb_rblocks;/* number of realtime blocks */ -xfs_rtblock_t sb_rextents;/* number of realtime extents */ +xfs_rtbxlen_t sb_rextents;/* number of realtime extents */ uuid_t sb_uuid;/* user-visible file system unique id */ xfs_fsblock_t sb_logstart;/* starting block of log if internal */ xfs_ino_t sb_rootino;/* root inode number */
fs/xfs/libxfs/xfs_rtbitmap.h +1 -1
@@ -13,7 +13,7 @@*/ struct xfs_rtalloc_rec {xfs_rtblock_t ar_startext; -xfs_rtblock_t ar_extcount; +xfs_rtbxlen_t ar_extcount; }; typedef int (*xfs_rtalloc_query_range_fn)(
fs/xfs/libxfs/xfs_types.h +1 -0
@@ -32,6 +32,7 @@ typedef uint64_t xfs_rfsblock_t; /* blockno in filesystem (raw) */typedef uint64_t xfs_rtblock_t ;/* extent (block) in realtime area */ typedef uint64_t xfs_fileoff_t ;/* block number in a file */ typedef uint64_t xfs_filblks_t ;/* number of blocks in a file */ +typedef uint64_t xfs_rtbxlen_t ;/* rtbitmap extent length in rtextents */ typedef int64_t xfs_srtblock_t ;/* signed version of xfs_rtblock_t */
fs/xfs/scrub/trace.h +2 -1
@@ -1082,7 +1082,8 @@ TRACE_EVENT(xfarray_sort_stats,#ifdef CONFIG_XFS_RT TRACE_EVENT(xchk_rtsum_record_free, TP_PROTO(struct xfs_mount *mp, xfs_rtblock_t start, - uint64_t len, unsigned int log, loff_t pos, xfs_suminfo_t v), + xfs_rtbxlen_t len, unsigned int log, loff_t pos, + xfs_suminfo_t v), TP_ARGS(mp, start, len, log, pos, v), TP_STRUCT__entry( __field(dev_t, dev)
PATCH 10/11 xfs: rename xfs_verify_rtext to xfs_verify_rtbext
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
This helper function validates that a range of *blocks* in the realtime section is completely contained within the realtime section. It does /not/ validate ranges of *rtextents*. Rename the function to avoid suggesting that it does, and change the type of the @len parameter since xfs_rtblock_t is a position unit, not a length unit.
--- fs/xfs/libxfs/xfs_bmap.c | 2 +- fs/xfs/libxfs/xfs_types.c | 4 ++-- fs/xfs/libxfs/xfs_types.h | 4 ++-- fs/xfs/scrub/bmap.c | 2 +- fs/xfs/scrub/rtbitmap.c | 4 ++-- fs/xfs/scrub/rtsummary.c | 2 +- fs/xfs/xfs_bmap_item.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +1 -1
@@ -6292,7 +6292,7 @@ xfs_bmap_validate_extent_raw(return __this_address;if (rtfile && whichfork ==XFS_DATA_FORK ) { -if (!xfs_verify_rtext (mp, irec->br_startblock, +if (!xfs_verify_rtbext (mp, irec->br_startblock, irec->br_blockcount))return __this_address; }else {
fs/xfs/libxfs/xfs_types.c +2 -2
@@ -147,10 +147,10 @@ xfs_verify_rtbno(/* Verify that a realtime device extent is fully contained inside the volume. */ bool -xfs_verify_rtext ( +xfs_verify_rtbext (struct xfs_mount *mp,xfs_rtblock_t rtbno, -xfs_rtblock_t len) +xfs_filblks_t len) {if (rtbno + len <= rtbno)return false;
fs/xfs/libxfs/xfs_types.h +2 -2
@@ -240,8 +240,8 @@ bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);bool xfs_internal_inum (struct xfs_mount *mp,xfs_ino_t ino);bool xfs_verify_dir_ino (struct xfs_mount *mp,xfs_ino_t ino);bool xfs_verify_rtbno (struct xfs_mount *mp,xfs_rtblock_t rtbno); -bool xfs_verify_rtext (struct xfs_mount *mp,xfs_rtblock_t rtbno, -xfs_rtblock_t len); +bool xfs_verify_rtbext (struct xfs_mount *mp,xfs_rtblock_t rtbno, +xfs_filblks_t len);bool xfs_verify_icount (struct xfs_mount *mp,unsigned long long icount);bool xfs_verify_dablk (struct xfs_mount *mp,xfs_fileoff_t off); void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
fs/xfs/scrub/bmap.c +1 -1
@@ -469,7 +469,7 @@ xchk_bmap_iextent(xchk_fblock_set_corrupt (info->sc, info->whichfork, irec->br_startoff);if (info->is_rt && - !xfs_verify_rtext (mp, irec->br_startblock, irec->br_blockcount)) + !xfs_verify_rtbext (mp, irec->br_startblock, irec->br_blockcount))xchk_fblock_set_corrupt (info->sc, info->whichfork, irec->br_startoff); if (!info->is_rt &&
fs/xfs/scrub/rtbitmap.c +2 -2
@@ -60,12 +60,12 @@ xchk_rtbitmap_rec( {struct xfs_scrub *sc = priv;xfs_rtblock_t startblock; -xfs_rtblock_t blockcount; +xfs_filblks_t blockcount; startblock = rec->ar_startext * mp->m_sb.sb_rextsize; blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize; -if (!xfs_verify_rtext (mp, startblock, blockcount)) +if (!xfs_verify_rtbext (mp, startblock, blockcount))xchk_fblock_set_corrupt (sc,XFS_DATA_FORK ,0 );return 0 ; }
fs/xfs/scrub/rtsummary.c +1 -1
@@ -141,7 +141,7 @@ xchk_rtsum_record_free( rtbno = rec->ar_startext * mp->m_sb.sb_rextsize; rtlen = rec->ar_extcount * mp->m_sb.sb_rextsize; -if (!xfs_verify_rtext (mp, rtbno, rtlen)) { +if (!xfs_verify_rtbext (mp, rtbno, rtlen)) {xchk_ino_xref_set_corrupt (sc, mp->m_rbmip->i_ino);return -EFSCORRUPTED ; }
fs/xfs/xfs_bmap_item.c +1 -1
@@ -476,7 +476,7 @@ xfs_bui_validate(return false;if (map->me_flags &XFS_BMAP_EXTENT_REALTIME ) -return xfs_verify_rtext (mp, map->me_startblock, map->me_len); +return xfs_verify_rtbext (mp, map->me_startblock, map->me_len);return xfs_verify_fsbext (mp, map->me_startblock, map->me_len); }
PATCH 11/11 xfs: convert rt extent numbers to xfs_rtxnum_t
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Further disambiguate the xfs_rtblock_t uses by creating a new type, xfs_rtxnum_t, to store the position of an extent within the realtime section, in units of rtextents.
--- fs/xfs/libxfs/xfs_rtbitmap.c | 86 +++++++++++++-------------- fs/xfs/libxfs/xfs_rtbitmap.h | 26 ++++---- fs/xfs/libxfs/xfs_types.h | 2 + fs/xfs/scrub/rtbitmap.c | 6 +- fs/xfs/scrub/rtsummary.c | 2 - fs/xfs/scrub/trace.h | 4 + fs/xfs/xfs_bmap_util.c | 12 ++-- fs/xfs/xfs_rtalloc.c | 134 +++++++++++++++++++++--------------------- fs/xfs/xfs_rtalloc.h | 6 +- 9 files changed, 138 insertions(+), 140 deletions(-)
fs/xfs/libxfs/xfs_rtbitmap.c +43 -43
@@ -102,9 +102,9 @@ intxfs_rtfind_back ( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ - xfs_rtblock_t start, /* starting block to look at */ - xfs_rtblock_t limit, /* last block to look at */ - xfs_rtblock_t *rtblock) /* out: start block found */ + xfs_rtxnum_t start, /* starting rtext to look at */ + xfs_rtxnum_t limit, /* last rtext to look at */ + xfs_rtxnum_t *rtx) /* out: start rtext found */ {xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */
@@ -112,9 +112,9 @@ xfs_rtfind_back(struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */ -xfs_rtblock_t firstbit;/* first useful bit in the word */ -xfs_rtblock_t i;/* current bit number rel. to start */ -xfs_rtblock_t len;/* length of inspected area */ +xfs_rtxnum_t firstbit;/* first useful bit in the word */ +xfs_rtxnum_t i;/* current bit number rel. to start */ +xfs_rtxnum_t len;/* length of inspected area */ xfs_rtword_t mask;/* mask of relevant bits for value */ xfs_rtword_t want;/* mask for "good" values */ xfs_rtword_t wdiff;/* difference from wanted value */
@@ -163,7 +163,7 @@ xfs_rtfind_back(*/ xfs_trans_brelse (tp, bp); i = bit -XFS_RTHIBIT (wdiff); - *rtblock = start - i +1 ; + *rtx = start - i +1 ;return 0 ; } i = bit - firstbit +1 ;
@@ -209,7 +209,7 @@ xfs_rtfind_back(*/ xfs_trans_brelse (tp, bp); i +=XFS_NBWORD -1 -XFS_RTHIBIT (wdiff); - *rtblock = start - i +1 ; + *rtx = start - i +1 ;return 0 ; } i +=XFS_NBWORD ;
@@ -256,7 +256,7 @@ xfs_rtfind_back(*/ xfs_trans_brelse (tp, bp); i +=XFS_NBWORD -1 -XFS_RTHIBIT (wdiff); - *rtblock = start - i +1 ; + *rtx = start - i +1 ;return 0 ; }else i = len;
@@ -265,7 +265,7 @@ xfs_rtfind_back(* No match, return that we scanned the whole area. */ xfs_trans_brelse (tp, bp); - *rtblock = start - i +1 ; + *rtx = start - i +1 ;return 0 ; }
@@ -277,9 +277,9 @@ intxfs_rtfind_forw ( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ - xfs_rtblock_t start, /* starting block to look at */ - xfs_rtblock_t limit, /* last block to look at */ - xfs_rtblock_t *rtblock) /* out: start block found */ + xfs_rtxnum_t start, /* starting rtext to look at */ + xfs_rtxnum_t limit, /* last rtext to look at */ + xfs_rtxnum_t *rtx) /* out: start rtext found */ {xfs_rtword_t *b;/* current word in buffer */ int bit;/* bit number in the word */
@@ -287,9 +287,9 @@ xfs_rtfind_forw(struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */ -xfs_rtblock_t i;/* current bit number rel. to start */ -xfs_rtblock_t lastbit;/* last useful bit in the word */ -xfs_rtblock_t len;/* length of inspected area */ +xfs_rtxnum_t i;/* current bit number rel. to start */ +xfs_rtxnum_t lastbit;/* last useful bit in the word */ +xfs_rtxnum_t len;/* length of inspected area */ xfs_rtword_t mask;/* mask of relevant bits for value */ xfs_rtword_t want;/* mask for "good" values */ xfs_rtword_t wdiff;/* difference from wanted value */
@@ -337,7 +337,7 @@ xfs_rtfind_forw(*/ xfs_trans_brelse (tp, bp); i =XFS_RTLOBIT (wdiff) - bit; - *rtblock = start + i -1 ; + *rtx = start + i -1 ;return 0 ; } i = lastbit - bit;
@@ -382,7 +382,7 @@ xfs_rtfind_forw(*/ xfs_trans_brelse (tp, bp); i +=XFS_RTLOBIT (wdiff); - *rtblock = start + i -1 ; + *rtx = start + i -1 ;return 0 ; } i +=XFS_NBWORD ;
@@ -426,7 +426,7 @@ xfs_rtfind_forw(*/ xfs_trans_brelse (tp, bp); i +=XFS_RTLOBIT (wdiff); - *rtblock = start + i -1 ; + *rtx = start + i -1 ;return 0 ; }else i = len;
@@ -435,7 +435,7 @@ xfs_rtfind_forw(* No match, return that we scanned the whole area. */ xfs_trans_brelse (tp, bp); - *rtblock = start + i -1 ; + *rtx = start + i -1 ;return 0 ; }
@@ -540,7 +540,7 @@ intxfs_rtmodify_range ( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ - xfs_rtblock_t start, /* starting block to modify */ + xfs_rtxnum_t start, /* starting rtext to modify */ xfs_rtxlen_t len, /* length of extent to modify */ int val) /* 1 for free, 0 for allocated */ {
@@ -696,15 +696,15 @@ intxfs_rtfree_range ( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ - xfs_rtblock_t start, /* starting block to free */ + xfs_rtxnum_t start, /* starting rtext to free */ xfs_rtxlen_t len, /* length to free */ struct xfs_buf **rbpp, /* in/out: summary block buffer */ xfs_fileoff_t *rsb) /* in/out: summary block number */ { -xfs_rtblock_t end;/* end of the freed extent */ +xfs_rtxnum_t end;/* end of the freed extent */ int error;/* error value */ -xfs_rtblock_t postblock;/* first block freed > end */ -xfs_rtblock_t preblock;/* first block freed < start */ +xfs_rtxnum_t postblock;/* first rtext freed > end */ +xfs_rtxnum_t preblock;/* first rtext freed < start */ end = start + len -1 ;/*
@@ -772,10 +772,10 @@ intxfs_rtcheck_range ( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ - xfs_rtblock_t start, /* starting block number of extent */ + xfs_rtxnum_t start, /* starting rtext number of extent */ xfs_rtxlen_t len, /* length of extent */ int val, /* 1 for free, 0 for allocated */ - xfs_rtblock_t *new,/* out: first block not matching */ + xfs_rtxnum_t *new,/* out: first rtext not matching */ int *stat) /* out: 1 for matches, 0 for not */ {xfs_rtword_t *b;/* current word in buffer */
@@ -784,8 +784,8 @@ xfs_rtcheck_range(struct xfs_buf *bp;/* buf for the block */ xfs_rtword_t *bufp;/* starting word in buffer */ int error;/* error value */ -xfs_rtblock_t i;/* current bit number rel. to start */ -xfs_rtblock_t lastbit;/* last useful bit in word */ +xfs_rtxnum_t i;/* current bit number rel. to start */ +xfs_rtxnum_t lastbit;/* last useful bit in word */ xfs_rtword_t mask;/* mask of relevant bits for value */ xfs_rtword_t wdiff;/* difference from wanted value */ int word;/* word number in the buffer */
@@ -948,14 +948,14 @@ STATIC int /* error */xfs_rtcheck_alloc_range ( xfs_mount_t *mp,/* file system mount point */ xfs_trans_t *tp,/* transaction pointer */ - xfs_rtblock_t bno, /* starting block number of extent */ + xfs_rtxnum_t start, /* starting rtext number of extent */ xfs_rtxlen_t len) /* length of extent */ { -xfs_rtblock_t new;/* dummy for xfs_rtcheck_range */ +xfs_rtxnum_t new;/* dummy for xfs_rtcheck_range */ int stat;int error; - error =xfs_rtcheck_range (mp, tp, bno, len,0 , &new, &stat); + error =xfs_rtcheck_range (mp, tp, start, len,0 , &new, &stat);if (error)return error;ASSERT (stat);
@@ -971,7 +971,7 @@ xfs_rtcheck_alloc_range(int /* error */ xfs_rtfree_extent (xfs_trans_t *tp,/* transaction pointer */ -xfs_rtblock_t bno,/* starting block number to free */ +xfs_rtxnum_t start,/* starting rtext number to free */ xfs_rtxlen_t len)/* length of extent freed */ {int error;/* error value */
@@ -984,14 +984,14 @@ xfs_rtfree_extent(ASSERT (mp->m_rbmip->i_itemp !=NULL );ASSERT (xfs_isilocked (mp->m_rbmip,XFS_ILOCK_EXCL )); - error =xfs_rtcheck_alloc_range (mp, tp, bno, len); + error =xfs_rtcheck_alloc_range (mp, tp, start, len);if (error)return error;/* * Free the range of realtime blocks. */ - error =xfs_rtfree_range (mp, tp, bno, len, &sumbp, &sb); + error =xfs_rtfree_range (mp, tp, start, len, &sumbp, &sb);if (error) {return error; }
@@ -1025,7 +1025,7 @@ xfs_rtfree_blocks( xfs_filblks_t rtlen) {struct xfs_mount *mp = tp->t_mountp; -xfs_rtblock_t bno; +xfs_rtxnum_t start;xfs_filblks_t len;xfs_extlen_t mod;
@@ -1037,13 +1037,13 @@ xfs_rtfree_blocks(return -EIO ; } - bno =div_u64_rem (rtbno, mp->m_sb.sb_rextsize, &mod); + start =div_u64_rem (rtbno, mp->m_sb.sb_rextsize, &mod);if (mod) {ASSERT (mod ==0 );return -EIO ; } -return xfs_rtfree_extent (tp, bno, len); +return xfs_rtfree_extent (tp, start, len); }/* Find all the free records within a given range. */
@@ -1057,9 +1057,9 @@ xfs_rtalloc_query_range( void *priv) {struct xfs_rtalloc_rec rec; -xfs_rtblock_t rtstart; -xfs_rtblock_t rtend; -xfs_rtblock_t high_key; +xfs_rtxnum_t rtstart; +xfs_rtxnum_t rtend; +xfs_rtxnum_t high_key;int is_free;int error =0 ;
@@ -1122,11 +1122,11 @@ intxfs_rtalloc_extent_is_free ( struct xfs_mount *mp, struct xfs_trans *tp, - xfs_rtblock_t start, + xfs_rtxnum_t start, xfs_rtxlen_t len, bool *is_free) { - xfs_rtblock_t end; + xfs_rtxnum_t end;int matches;int error;
fs/xfs/libxfs/xfs_rtbitmap.h +12 -14
@@ -7,12 +7,10 @@#define __XFS_RTBITMAP_H__/* -* XXX: Most of the realtime allocation functions deal in units of realtime -* extents, not realtime blocks. This looks funny when paired with the type -* name and screams for a larger cleanup. +* Functions for walking free space rtextents in the realtime bitmap. */ struct xfs_rtalloc_rec { -xfs_rtblock_t ar_startext; +xfs_rtxnum_t ar_startext;xfs_rtbxlen_t ar_extcount; };
@@ -26,16 +24,16 @@ typedef int (*xfs_rtalloc_query_range_fn)(int xfs_rtbuf_get (struct xfs_mount *mp,struct xfs_trans *tp,xfs_fileoff_t block,int issum,struct xfs_buf **bpp);int xfs_rtcheck_range (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_rtxlen_t len,int val, -xfs_rtblock_t *new,int *stat); +xfs_rtxnum_t start,xfs_rtxlen_t len,int val, +xfs_rtxnum_t *new,int *stat);int xfs_rtfind_back (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_rtblock_t limit, -xfs_rtblock_t *rtblock); +xfs_rtxnum_t start,xfs_rtxnum_t limit, +xfs_rtxnum_t *rtblock);int xfs_rtfind_forw (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_rtblock_t limit, -xfs_rtblock_t *rtblock); +xfs_rtxnum_t start,xfs_rtxnum_t limit, +xfs_rtxnum_t *rtblock);int xfs_rtmodify_range (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_rtxlen_t len,int val); +xfs_rtxnum_t start,xfs_rtxlen_t len,int val); int xfs_rtmodify_summary_int(struct xfs_mount *mp, struct xfs_trans *tp, int log, xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp, xfs_fileoff_t *rsb,
@@ -44,7 +42,7 @@ int xfs_rtmodify_summary(struct xfs_mount *mp, struct xfs_trans *tp, int log, xfs_fileoff_t bbno, int delta, struct xfs_buf **rbpp, xfs_fileoff_t *rsb);int xfs_rtfree_range (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_rtxlen_t len, +xfs_rtxnum_t start,xfs_rtxlen_t len,struct xfs_buf **rbpp,xfs_fileoff_t *rsb); int xfs_rtalloc_query_range(struct xfs_mount *mp, struct xfs_trans *tp, const struct xfs_rtalloc_rec *low_rec,
@@ -54,7 +52,7 @@ int xfs_rtalloc_query_all(struct xfs_mount *mp, struct xfs_trans *tp,xfs_rtalloc_query_range_fn fn, void *priv);int xfs_rtalloc_extent_is_free (struct xfs_mount *mp,struct xfs_trans *tp, -xfs_rtblock_t start,xfs_rtxlen_t len, +xfs_rtxnum_t start,xfs_rtxlen_t len,bool *is_free);/* * Free an extent in the realtime subvolume. Length is expressed in
@@ -63,7 +61,7 @@ int xfs_rtalloc_extent_is_free(struct xfs_mount *mp, struct xfs_trans *tp,int /* error */ xfs_rtfree_extent (struct xfs_trans *tp,/* transaction pointer */ -xfs_rtblock_t bno,/* starting block number to free */ +xfs_rtxnum_t start,/* starting rtext number to free */ xfs_rtxlen_t len);/* length of extent freed */ /* Same as above, but in units of rt blocks. */
fs/xfs/libxfs/xfs_types.h +2 -0
@@ -32,6 +32,7 @@ typedef uint64_t xfs_rfsblock_t; /* blockno in filesystem (raw) */typedef uint64_t xfs_rtblock_t ;/* extent (block) in realtime area */ typedef uint64_t xfs_fileoff_t ;/* block number in a file */ typedef uint64_t xfs_filblks_t ;/* number of blocks in a file */ +typedef uint64_t xfs_rtxnum_t ;/* rtextent number */ typedef uint64_t xfs_rtbxlen_t ;/* rtbitmap extent length in rtextents */ typedef int64_t xfs_srtblock_t ;/* signed version of xfs_rtblock_t */
@@ -49,6 +50,7 @@ typedef void * xfs_failaddr_t;#define NULLRFSBLOCK ((xfs_rfsblock_t)-1)#define NULLRTBLOCK ((xfs_rtblock_t)-1)#define NULLFILEOFF ((xfs_fileoff_t)-1) +#define NULLRTEXTNO ((xfs_rtxnum_t)-1)#define NULLAGBLOCK ((xfs_agblock_t)-1)#define NULLAGNUMBER ((xfs_agnumber_t)-1)
fs/xfs/scrub/rtbitmap.c +3 -3
@@ -59,7 +59,7 @@ xchk_rtbitmap_rec( void *priv) {struct xfs_scrub *sc = priv; -xfs_rtblock_t startblock; +xfs_rtxnum_t startblock;xfs_filblks_t blockcount; startblock = rec->ar_startext * mp->m_sb.sb_rextsize;
@@ -143,8 +143,8 @@ xchk_xref_is_used_rt_space( xfs_rtblock_t fsbno, xfs_extlen_t len) { -xfs_rtblock_t startext; -xfs_rtblock_t endext; +xfs_rtxnum_t startext; +xfs_rtxnum_t endext;xfs_rtxlen_t extcount;bool is_free;int error;
fs/xfs/scrub/rtsummary.c +1 -1
@@ -123,7 +123,7 @@ xchk_rtsum_record_free( {struct xfs_scrub *sc = priv;xfs_fileoff_t rbmoff; -xfs_rtblock_t rtbno; +xfs_rtxnum_t rtbno;xfs_filblks_t rtlen;xchk_rtsumoff_t offs;unsigned int lenlog;
fs/xfs/scrub/trace.h +2 -2
@@ -1081,14 +1081,14 @@ TRACE_EVENT(xfarray_sort_stats,#ifdef CONFIG_XFS_RT TRACE_EVENT(xchk_rtsum_record_free, - TP_PROTO(struct xfs_mount *mp, xfs_rtblock_t start, + TP_PROTO(struct xfs_mount *mp, xfs_rtxnum_t start, xfs_rtbxlen_t len, unsigned int log, loff_t pos, xfs_suminfo_t v), TP_ARGS(mp, start, len, log, pos, v), TP_STRUCT__entry( __field(dev_t, dev) __field(dev_t, rtdev) - __field(xfs_rtblock_t, start) + __field(xfs_rtxnum_t, start) __field(unsigned long long, len) __field(unsigned int, log) __field(loff_t, pos)
fs/xfs/xfs_bmap_util.c +5 -7
@@ -76,7 +76,7 @@ xfs_bmap_rtalloc( {struct xfs_mount *mp = ap->ip->i_mount;xfs_fileoff_t orig_offset = ap->offset; -xfs_rtblock_t rtb; +xfs_rtxnum_t rtx;xfs_rtxlen_t prod =0 ;/* product factor for allocators */ xfs_extlen_t mod =0 ;/* product factor for allocators */ xfs_rtxlen_t ralen =0 ;/* realtime allocation length */
@@ -145,8 +145,6 @@ xfs_bmap_rtalloc(* pick an extent that will space things out in the rt area. */ if (ap->eof && ap->offset ==0 ) { -xfs_rtblock_t rtx;/* realtime extent no */ - error =xfs_rtpick_extent (mp, ap->tp, ralen, &rtx);if (error)return error;
@@ -164,16 +162,16 @@ xfs_bmap_rtalloc( ap->blkno =0 ; else do_div(ap->blkno, mp->m_sb.sb_rextsize); - rtb = ap->blkno; + rtx = ap->blkno; ap->length = ralen; raminlen =max_t (xfs_extlen_t,1 , minlen / mp->m_sb.sb_rextsize); error =xfs_rtallocate_extent (ap->tp, ap->blkno, raminlen, ap->length, - &ralen, ap->wasdel, prod, &rtb); + &ralen, ap->wasdel, prod, &rtx);if (error)return error; -if (rtb !=NULLRTBLOCK ) { - ap->blkno = rtb * mp->m_sb.sb_rextsize; +if (rtx !=NULLRTEXTNO ) { + ap->blkno = rtx * mp->m_sb.sb_rextsize; ap->length = ralen * mp->m_sb.sb_rextsize; ap->ip->i_nblocks += ap->length;xfs_trans_log_inode (ap->tp, ap->ip,XFS_ILOG_CORE );
fs/xfs/xfs_rtalloc.c +67 -67
406 lines not on this page · raw message
fs/xfs/xfs_rtalloc.h +3 -3
@@ -24,13 +24,13 @@ struct xfs_trans;int /* error */ xfs_rtallocate_extent (struct xfs_trans *tp,/* transaction pointer */ -xfs_rtblock_t bno,/* starting block number to allocate */ +xfs_rtxnum_t start,/* starting rtext number to allocate */ xfs_rtxlen_t minlen,/* minimum length to allocate */ xfs_rtxlen_t maxlen,/* maximum length to allocate */ xfs_rtxlen_t *len,/* out: actual length allocated */ int wasdel,/* was a delayed allocation extent */ xfs_rtxlen_t prod,/* extent product factor */ -xfs_rtblock_t *rtblock);/* out: start block allocated */ +xfs_rtxnum_t *rtblock);/* out: start rtext allocated */ /*
@@ -63,7 +63,7 @@ xfs_rtpick_extent(struct xfs_mount *mp,/* file system mount point */ struct xfs_trans *tp, /* transaction pointer */ xfs_rtxlen_t len, /* allocation length (rtextents) */ - xfs_rtblock_t *pick); /* result rt extent */ + xfs_rtxnum_t *pick); /* result rt extent *//* * Grow the realtime area of the filesystem.
cover xfs: refactor rt extent unit conversions
In reply to Darrick J. WongHi all,
This series replaces all the open-coded integer division and multiplication conversions between rt blocks and rt extents with calls to static inline helpers. Having cleaned all that up, the helpers are augmented to skip the expensive operations in favor of bit shifts and masking if the rt extent size is a power of two.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. 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=refactor-rt-unit-conversions
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=refactor-rt-unit-conversions
--- fs/xfs/libxfs/xfs_bmap.c | 19 +++----- fs/xfs/libxfs/xfs_rtbitmap.c | 4 +- fs/xfs/libxfs/xfs_rtbitmap.h | 88 +++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_sb.c | 2 + fs/xfs/libxfs/xfs_swapext.c | 7 ++- fs/xfs/libxfs/xfs_trans_inode.c | 3 + fs/xfs/libxfs/xfs_trans_resv.c | 3 + fs/xfs/scrub/inode.c | 3 + fs/xfs/scrub/inode_repair.c | 3 + fs/xfs/scrub/rtbitmap.c | 18 +++----- fs/xfs/scrub/rtsummary.c | 4 +- fs/xfs/xfs_bmap_util.c | 38 +++++++---------- fs/xfs/xfs_fsmap.c | 12 +++-- fs/xfs/xfs_ioctl.c | 5 +- fs/xfs/xfs_linux.h | 12 +++++ fs/xfs/xfs_mount.h | 2 + fs/xfs/xfs_rtalloc.c | 16 ++++--- fs/xfs/xfs_super.c | 3 + fs/xfs/xfs_trans.c | 9 +++- fs/xfs/xfs_xchgrange.c | 4 +- 20 files changed, 178 insertions(+), 77 deletions(-)
PATCH 1/7 xfs: create a helper to convert rtextents to rtblocks
From: Darrick J. Wong <[email protected]>
Create a helper to convert a realtime extent to a realtime block. Later on we'll change the helper to use bit shifts when possible.
--- fs/xfs/libxfs/xfs_rtbitmap.h | 16 ++++++++++++++++ fs/xfs/scrub/rtbitmap.c | 4 ++-- fs/xfs/scrub/rtsummary.c | 4 ++-- fs/xfs/xfs_bmap_util.c | 9 +++++---- fs/xfs/xfs_fsmap.c | 4 ++-- fs/xfs/xfs_super.c | 3 ++- 6 files changed, 29 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_rtbitmap.h +16 -0
@@ -6,6 +6,22 @@#ifndef __XFS_RTBITMAP_H__#define __XFS_RTBITMAP_H__ +static inline xfs_rtblock_t +xfs_rtx_to_rtb ( +struct xfs_mount *mp, +xfs_rtxnum_t rtx) +{ +return rtx * mp->m_sb.sb_rextsize; +} + +static inline xfs_extlen_t +xfs_rtxlen_to_extlen ( +struct xfs_mount *mp, +xfs_rtxlen_t rtxlen) +{ +return rtxlen * mp->m_sb.sb_rextsize; +} +/* * Functions for walking free space rtextents in the realtime bitmap. */
fs/xfs/scrub/rtbitmap.c +2 -2
@@ -62,8 +62,8 @@ xchk_rtbitmap_rec(xfs_rtxnum_t startblock;xfs_filblks_t blockcount; - startblock = rec->ar_startext * mp->m_sb.sb_rextsize; - blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize; + startblock =xfs_rtx_to_rtb (mp, rec->ar_startext); + blockcount =xfs_rtx_to_rtb (mp, rec->ar_extcount);if (!xfs_verify_rtbext (mp, startblock, blockcount))xchk_fblock_set_corrupt (sc,XFS_DATA_FORK ,0 );
fs/xfs/scrub/rtsummary.c +2 -2
@@ -138,8 +138,8 @@ xchk_rtsum_record_free( lenlog =XFS_RTBLOCKLOG (rec->ar_extcount); offs =XFS_SUMOFFS (mp, lenlog, rbmoff); - rtbno = rec->ar_startext * mp->m_sb.sb_rextsize; - rtlen = rec->ar_extcount * mp->m_sb.sb_rextsize; + rtbno =xfs_rtx_to_rtb (mp, rec->ar_startext); + rtlen =xfs_rtx_to_rtb (mp, rec->ar_extcount);if (!xfs_verify_rtbext (mp, rtbno, rtlen)) {xchk_ino_xref_set_corrupt (sc, mp->m_rbmip->i_ino);
fs/xfs/xfs_bmap_util.c +5 -4
@@ -29,6 +29,7 @@#include "xfs_iomap.h" #include "xfs_reflink.h" #include "xfs_swapext.h" +#include "xfs_rtbitmap.h" /* Kernel only BMAP related definitions and functions */
@@ -126,7 +127,7 @@ xfs_bmap_rtalloc(* XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't * adjust the starting point to match it. */ -if (ralen * mp->m_sb.sb_rextsize >=XFS_MAX_BMBT_EXTLEN ) +if (xfs_rtxlen_to_extlen (mp, ralen) >=XFS_MAX_BMBT_EXTLEN ) ralen =XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize;/*
@@ -148,7 +149,7 @@ xfs_bmap_rtalloc( error =xfs_rtpick_extent (mp, ap->tp, ralen, &rtx);if (error)return error; - ap->blkno = rtx * mp->m_sb.sb_rextsize; + ap->blkno =xfs_rtx_to_rtb (mp, rtx); }else { ap->blkno =0 ; }
@@ -171,8 +172,8 @@ xfs_bmap_rtalloc(return error;if (rtx !=NULLRTEXTNO ) { - ap->blkno = rtx * mp->m_sb.sb_rextsize; - ap->length = ralen * mp->m_sb.sb_rextsize; + ap->blkno =xfs_rtx_to_rtb (mp, rtx); + ap->length =xfs_rtxlen_to_extlen (mp, ralen); ap->ip->i_nblocks += ap->length;xfs_trans_log_inode (ap->tp, ap->ip,XFS_ILOG_CORE );if (ap->wasdel)
fs/xfs/xfs_fsmap.c +2 -2
@@ -459,9 +459,9 @@ xfs_getfsmap_rtdev_rtbitmap_helper(struct xfs_rmap_irec irec;xfs_daddr_t rec_daddr; - irec.rm_startblock = rec->ar_startext * mp->m_sb.sb_rextsize; + irec.rm_startblock =xfs_rtx_to_rtb (mp, rec->ar_startext); rec_daddr =XFS_FSB_TO_BB (mp, irec.rm_startblock); - irec.rm_blockcount = rec->ar_extcount * mp->m_sb.sb_rextsize; + irec.rm_blockcount =xfs_rtx_to_rtb (mp, rec->ar_extcount); irec.rm_owner =XFS_RMAP_OWN_NULL ;/* "free" */ irec.rm_offset =0 ; irec.rm_flags =0 ;
fs/xfs/xfs_super.c +2 -1
@@ -43,6 +43,7 @@#include "xfs_iunlink_item.h" #include "scrub/rcbag_btree.h" #include "xfs_swapext_item.h" +#include "xfs_rtbitmap.h" #include <linux/magic.h> #include <linux/fs_context.h>
@@ -863,7 +864,7 @@ xfs_fs_statfs( statp->f_blocks = sbp->sb_rblocks; freertx =percpu_counter_sum_positive (&mp->m_frextents); - statp->f_bavail = statp->f_bfree = freertx * sbp->sb_rextsize; + statp->f_bavail = statp->f_bfree =xfs_rtx_to_rtb (mp, freertx); }return 0 ;
PATCH 2/7 xfs: create a helper to compute leftovers of realtime extents
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a helper to compute the misalignment between a file extent (xfs_extlen_t) and a realtime extent.
--- fs/xfs/libxfs/xfs_bmap.c | 4 ++-- fs/xfs/libxfs/xfs_rtbitmap.h | 9 +++++++++ fs/xfs/libxfs/xfs_trans_inode.c | 3 ++- fs/xfs/scrub/inode.c | 3 ++- fs/xfs/scrub/inode_repair.c | 3 ++- fs/xfs/xfs_bmap_util.c | 2 +- fs/xfs/xfs_ioctl.c | 5 +++-- 7 files changed, 21 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +2 -2
@@ -3058,7 +3058,7 @@ xfs_bmap_extsize_align(* If realtime, and the result isn't a multiple of the realtime * extent size we need to remove blocks until it is. */ -if (rt && (temp = (align_alen % mp->m_sb.sb_rextsize))) { +if (rt && (temp =xfs_extlen_to_rtxmod (mp, align_alen))) {/* * We're not covering the original request, or * we won't be able to once we fix the length.
@@ -3085,7 +3085,7 @@ xfs_bmap_extsize_align(else { align_alen -= orig_off - align_off; align_off = orig_off; - align_alen -= align_alen % mp->m_sb.sb_rextsize; + align_alen -=xfs_extlen_to_rtxmod (mp, align_alen); }/* * Result doesn't cover the request, fail it.
fs/xfs/libxfs/xfs_rtbitmap.h +9 -0
@@ -22,6 +22,15 @@ xfs_rtxlen_to_extlen(return rtxlen * mp->m_sb.sb_rextsize; } +/* Compute the misalignment between an extent length and a realtime extent .*/ +static inline unsigned int +xfs_extlen_to_rtxmod ( +struct xfs_mount *mp, +xfs_extlen_t len) +{ +return len % mp->m_sb.sb_rextsize; +} +/* * Functions for walking free space rtextents in the realtime bitmap. */
fs/xfs/libxfs/xfs_trans_inode.c +2 -1
@@ -14,6 +14,7 @@#include "xfs_trans.h" #include "xfs_trans_priv.h" #include "xfs_inode_item.h" +#include "xfs_rtbitmap.h" #include <linux/iversion.h>
@@ -152,7 +153,7 @@ xfs_trans_log_inode(*/ if ((ip->i_diflags &XFS_DIFLAG_RTINHERIT ) && (ip->i_diflags &XFS_DIFLAG_EXTSZINHERIT ) && - (ip->i_extsize % ip->i_mount->m_sb.sb_rextsize) >0 ) { +xfs_extlen_to_rtxmod (ip->i_mount, ip->i_extsize) >0 ) { ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE |XFS_DIFLAG_EXTSZINHERIT ); ip->i_extsize =0 ;
fs/xfs/scrub/inode.c +2 -1
@@ -19,6 +19,7 @@#include "xfs_reflink.h" #include "xfs_rmap.h" #include "xfs_bmap_util.h" +#include "xfs_rtbitmap.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/btree.h"
@@ -224,7 +225,7 @@ xchk_inode_extsize(*/ if ((flags &XFS_DIFLAG_RTINHERIT ) && (flags &XFS_DIFLAG_EXTSZINHERIT ) && - value % sc->mp->m_sb.sb_rextsize >0 ) +xfs_extlen_to_rtxmod (sc->mp, value) >0 )xchk_ino_set_warning (sc, ino); }
fs/xfs/scrub/inode_repair.c +2 -1
@@ -36,6 +36,7 @@#include "xfs_attr_leaf.h" #include "xfs_log_priv.h" #include "xfs_symlink_remote.h" +#include "xfs_rtbitmap.h" #include "scrub/xfs_scrub.h" #include "scrub/scrub.h" #include "scrub/common.h"
@@ -1506,7 +1507,7 @@ xrep_inode_extsize(/* Fix misaligned extent size hints on a directory. */ if ((sc->ip->i_diflags &XFS_DIFLAG_RTINHERIT ) && (sc->ip->i_diflags &XFS_DIFLAG_EXTSZINHERIT ) && - sc->ip->i_extsize % sc->mp->m_sb.sb_rextsize >0 ) { +xfs_extlen_to_rtxmod (sc->mp, sc->ip->i_extsize) >0 ) { sc->ip->i_extsize =0 ; sc->ip->i_diflags &= ~XFS_DIFLAG_EXTSZINHERIT ; }
fs/xfs/xfs_bmap_util.c +1 -1
@@ -98,7 +98,7 @@ xfs_bmap_rtalloc(if (error)return error;ASSERT (ap->length); -ASSERT (ap->length % mp->m_sb.sb_rextsize ==0 ); +ASSERT (xfs_extlen_to_rtxmod (mp, ap->length) ==0 );/* * If we shifted the file offset downward to satisfy an extent size
fs/xfs/xfs_ioctl.c +3 -2
@@ -38,6 +38,7 @@#include "xfs_reflink.h" #include "xfs_ioctl.h" #include "xfs_xattr.h" +#include "xfs_rtbitmap.h" #include <linux/mount.h> #include <linux/namei.h>
@@ -1013,7 +1014,7 @@ xfs_fill_fsxattr(* later. */ if ((ip->i_diflags &XFS_DIFLAG_RTINHERIT ) && - ip->i_extsize % mp->m_sb.sb_rextsize >0 ) { +xfs_extlen_to_rtxmod (mp, ip->i_extsize) >0 ) { fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |FS_XFLAG_EXTSZINHERIT ); fa->fsx_extsize =0 ;
@@ -1079,7 +1080,7 @@ xfs_ioctl_setattr_xflags(/* If realtime flag is set then must have realtime device */ if (fa->fsx_xflags &FS_XFLAG_REALTIME ) {if (mp->m_sb.sb_rblocks ==0 || mp->m_sb.sb_rextsize ==0 || - (ip->i_extsize % mp->m_sb.sb_rextsize)) +xfs_extlen_to_rtxmod (mp, ip->i_extsize))return -EINVAL ; }
PATCH 3/7 xfs: create a helper to compute leftovers of realtime extents
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a helper to compute the realtime extent (xfs_rtxlen_t) from an extent length (xfs_extlen_t) value.
--- fs/xfs/libxfs/xfs_rtbitmap.h | 8 ++++++++ fs/xfs/libxfs/xfs_trans_resv.c | 3 ++- fs/xfs/xfs_bmap_util.c | 11 ++++------- fs/xfs/xfs_trans.c | 5 +++-- 4 files changed, 17 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_rtbitmap.h +8 -0
@@ -31,6 +31,14 @@ xfs_extlen_to_rtxmod(return len % mp->m_sb.sb_rextsize; } +static inline xfs_rtxlen_t +xfs_extlen_to_rtxlen ( +struct xfs_mount *mp, +xfs_extlen_t len) +{ +return len / mp->m_sb.sb_rextsize; +} +/* * Functions for walking free space rtextents in the realtime bitmap. */
fs/xfs/libxfs/xfs_trans_resv.c +2 -1
@@ -19,6 +19,7 @@#include "xfs_trans.h" #include "xfs_qm.h" #include "xfs_trans_space.h" +#include "xfs_rtbitmap.h" #define _ALLOC true#define _FREE false
@@ -220,7 +221,7 @@ xfs_rtalloc_block_count(unsigned int blksz =XFS_FSB_TO_B (mp,1 );unsigned int rtbmp_bytes; - rtbmp_bytes = (XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize) /NBBY ; + rtbmp_bytes =xfs_extlen_to_rtxlen (mp,XFS_MAX_BMBT_EXTLEN ) /NBBY ;return (howmany (rtbmp_bytes, blksz) +1 ) * num_ops; }
fs/xfs/xfs_bmap_util.c +4 -7
@@ -91,7 +91,7 @@ xfs_bmap_rtalloc( align =xfs_get_extsz_hint (ap->ip); retry: - prod = align / mp->m_sb.sb_rextsize; + prod =xfs_extlen_to_rtxlen (mp, align); error =xfs_bmap_extsize_align (mp, &ap->got, &ap->prev, align,1 , ap->eof,0 , ap->conv, &ap->offset, &ap->length);
@@ -118,17 +118,14 @@ xfs_bmap_rtalloc( prod =1 ;/* * Set ralen to be the actual requested length in rtextents. -*/ - ralen = ap->length / mp->m_sb.sb_rextsize; -/* +* * If the old value was close enough to XFS_BMBT_MAX_EXTLEN that * we rounded up to it, cut it back so it's valid again. * Note that if it's a really large request (bigger than * XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't * adjust the starting point to match it. */ -if (xfs_rtxlen_to_extlen (mp, ralen) >=XFS_MAX_BMBT_EXTLEN ) - ralen =XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize; + ralen =xfs_extlen_to_rtxlen (mp,min (ap->length,XFS_MAX_BMBT_EXTLEN ));/* * Lock out modifications to both the RT bitmap and summary inodes
@@ -165,7 +162,7 @@ xfs_bmap_rtalloc(do_div (ap->blkno, mp->m_sb.sb_rextsize); rtx = ap->blkno; ap->length = ralen; - raminlen =max_t (xfs_extlen_t,1 , minlen / mp->m_sb.sb_rextsize); + raminlen =max_t (xfs_rtxlen_t,1 ,xfs_extlen_to_rtxlen (mp, minlen)); error =xfs_rtallocate_extent (ap->tp, ap->blkno, raminlen, ap->length, &ralen, ap->wasdel, prod, &rtx);if (error)
fs/xfs/xfs_trans.c +3 -2
@@ -24,6 +24,7 @@#include "xfs_dquot_item.h" #include "xfs_dquot.h" #include "xfs_icache.h" +#include "xfs_rtbitmap.h" struct kmem_cache *xfs_trans_cache;
@@ -1245,7 +1246,7 @@ xfs_trans_alloc_inode( retry: error =xfs_trans_alloc (mp, resv, dblocks, - rblocks / mp->m_sb.sb_rextsize, +xfs_extlen_to_rtxlen (mp, rblocks), force ?XFS_TRANS_RESERVE :0 , &tp);if (error)return error;
@@ -1291,7 +1292,7 @@ xfs_trans_reserve_more_inode( bool force_quota) {struct xfs_mount *mp = ip->i_mount; -unsigned int rtx = rblocks / mp->m_sb.sb_rextsize; +unsigned int rtx =xfs_extlen_to_rtxlen (mp, rblocks);int error;ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL ));
PATCH 4/7 xfs: create helpers to convert rt block numbers to rt extent numbers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create helpers to do unit conversions of rt block numbers to rt extent numbers. There are two variations -- the suffix "t" denotes the one that returns only the truncated extent number; the other one also returns the misalignment.
--- fs/xfs/libxfs/xfs_bmap.c | 7 +++---- fs/xfs/libxfs/xfs_rtbitmap.c | 4 ++-- fs/xfs/libxfs/xfs_rtbitmap.h | 17 +++++++++++++++++ fs/xfs/libxfs/xfs_swapext.c | 7 ++++--- fs/xfs/xfs_rtalloc.c | 8 ++++---- 5 files changed, 30 insertions(+), 13 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +3 -4
@@ -5371,7 +5371,6 @@ __xfs_bunmapi(int tmp_logflags;/* partial logging flags */ int wasdel;/* was a delayed alloc extent */ int whichfork;/* data or attribute fork */ -xfs_fsblock_t sum;xfs_filblks_t len = *rlen;/* length to unmap in file */ xfs_fileoff_t end;struct xfs_iext_cursor icur;
@@ -5468,8 +5467,7 @@ __xfs_bunmapi(if (!isrt || (flags &XFS_BMAPI_REMAP )) goto delete; - sum = del.br_startblock + del.br_blockcount; -div_u64_rem (sum, mp->m_sb.sb_rextsize, &mod); +xfs_rtb_to_rtx (mp, del.br_startblock + del.br_blockcount, &mod);if (mod) {/* * Realtime extent not lined up at the end.
@@ -5516,7 +5514,8 @@ __xfs_bunmapi( goto error0; goto nodelete; } -div_u64_rem (del.br_startblock, mp->m_sb.sb_rextsize, &mod); + +xfs_rtb_to_rtx (mp, del.br_startblock, &mod);if (mod) {xfs_extlen_t off = mp->m_sb.sb_rextsize - mod;
fs/xfs/libxfs/xfs_rtbitmap.c +2 -2
@@ -1031,13 +1031,13 @@ xfs_rtfree_blocks(ASSERT (rtlen <=XFS_MAX_BMBT_EXTLEN ); - len =div_u64_rem (rtlen, mp->m_sb.sb_rextsize, &mod); + len =xfs_rtb_to_rtx (mp, rtlen, &mod);if (mod) {ASSERT (mod ==0 );return -EIO ; } - start =div_u64_rem (rtbno, mp->m_sb.sb_rextsize, &mod); + start =xfs_rtb_to_rtx (mp, rtbno, &mod);if (mod) {ASSERT (mod ==0 );return -EIO ;
fs/xfs/libxfs/xfs_rtbitmap.h +17 -0
@@ -39,6 +39,23 @@ xfs_extlen_to_rtxlen(return len / mp->m_sb.sb_rextsize; } +static inline xfs_rtxnum_t +xfs_rtb_to_rtx ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno, +xfs_extlen_t *mod) +{ +return div_u64_rem (rtbno, mp->m_sb.sb_rextsize, mod); +} + +static inline xfs_rtxnum_t +xfs_rtb_to_rtxt ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno) +{ +return div_u64 (rtbno, mp->m_sb.sb_rextsize); +} +/* * Functions for walking free space rtextents in the realtime bitmap. */
fs/xfs/libxfs/xfs_swapext.c +4 -3
@@ -30,6 +30,7 @@#include "xfs_dir2_priv.h" #include "xfs_dir2.h" #include "xfs_symlink_remote.h" +#include "xfs_rtbitmap.h" struct kmem_cache *xfs_swapext_intent_cache;
@@ -215,19 +216,19 @@ xfs_swapext_check_rt_extents( irec2.br_blockcount);/* Both mappings must be aligned to the realtime extent size. */ -div_u64_rem (irec1.br_startoff, mp->m_sb.sb_rextsize, &mod); +xfs_rtb_to_rtx (mp, irec1.br_startoff, &mod);if (mod) {ASSERT (mod ==0 );return -EINVAL ; } -div_u64_rem (irec2.br_startoff, mp->m_sb.sb_rextsize, &mod); +xfs_rtb_to_rtx (mp, irec1.br_startoff, &mod);if (mod) {ASSERT (mod ==0 );return -EINVAL ; } -div_u64_rem (irec1.br_blockcount, mp->m_sb.sb_rextsize, &mod); +xfs_rtb_to_rtx (mp, irec1.br_blockcount, &mod);if (mod) {ASSERT (mod ==0 );return -EINVAL ;
fs/xfs/xfs_rtalloc.c +4 -4
@@ -1494,16 +1494,16 @@ xfs_rtfile_want_conversion( struct xfs_bmbt_irec *irec) {xfs_fileoff_t rext_next; -uint32_t modoff, modcnt; +xfs_extlen_t modoff, modcnt;if (irec->br_state !=XFS_EXT_UNWRITTEN )return false; -div_u64_rem (irec->br_startoff, mp->m_sb.sb_rextsize, &modoff); +xfs_rtb_to_rtx (mp, irec->br_startoff, &modoff);if (modoff ==0 ) { -uint64_t rexts =div_u64_rem (irec->br_blockcount, - mp->m_sb.sb_rextsize, &modcnt); +xfs_rtbxlen_t rexts; + rexts =xfs_rtb_to_rtx (mp, irec->br_blockcount, &modcnt);if (rexts >0 ) {/* * Unwritten mapping starts at an rt extent boundary
PATCH 5/7 xfs: convert do_div calls to xfs_rtb_to_rtx helper calls
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Convert these calls to use the helpers, and clean up all these places where the same variable can have different units depending on where it is in the function.
--- fs/xfs/libxfs/xfs_bmap.c | 8 ++------ fs/xfs/scrub/rtbitmap.c | 14 +++++--------- fs/xfs/xfs_bmap_util.c | 10 ++++------ fs/xfs/xfs_fsmap.c | 8 ++++---- fs/xfs/xfs_rtalloc.c | 3 +-- 5 files changed, 16 insertions(+), 27 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +2 -6
@@ -4921,12 +4921,8 @@ xfs_bmap_del_extent_delay(ASSERT (got->br_startoff <= del->br_startoff);ASSERT (got_endoff >= del_endoff); -if (isrt) { -uint64_t rtexts =XFS_FSB_TO_B (mp, del->br_blockcount); - -do_div (rtexts, mp->m_sb.sb_rextsize); -xfs_mod_frextents (mp, rtexts); - } +if (isrt) +xfs_mod_frextents (mp,xfs_rtb_to_rtxt (mp, del->br_blockcount));/* * Update the inode delalloc counter now and wait to update the
fs/xfs/scrub/rtbitmap.c +5 -9
@@ -140,25 +140,21 @@ xchk_rtbitmap(void xchk_xref_is_used_rt_space (struct xfs_scrub *sc, -xfs_rtblock_t fsbno, +xfs_rtblock_t rtbno,xfs_extlen_t len) {xfs_rtxnum_t startext;xfs_rtxnum_t endext; -xfs_rtxlen_t extcount;bool is_free;int error;if (xchk_skip_xref (sc->sm))return ; - startext = fsbno; - endext = fsbno + len -1 ; -do_div (startext, sc->mp->m_sb.sb_rextsize); -do_div (endext, sc->mp->m_sb.sb_rextsize); - extcount = endext - startext +1 ; - error =xfs_rtalloc_extent_is_free (sc->mp, sc->tp, startext, extcount, - &is_free); + startext =xfs_rtb_to_rtxt (sc->mp, rtbno); + endext =xfs_rtb_to_rtxt (sc->mp, rtbno + len -1 ); + error =xfs_rtalloc_extent_is_free (sc->mp, sc->tp, startext, + endext - startext +1 , &is_free);if (!xchk_should_check_xref (sc, &error,NULL ))return ;if (is_free)
fs/xfs/xfs_bmap_util.c +4 -6
@@ -157,14 +157,12 @@ xfs_bmap_rtalloc(* Realtime allocation, done through xfs_rtallocate_extent. */ if (ignore_locality) - ap->blkno =0 ; + rtx =0 ;else -do_div (ap->blkno, mp->m_sb.sb_rextsize); - rtx = ap->blkno; - ap->length = ralen; + rtx =xfs_rtb_to_rtxt (mp, ap->blkno); raminlen =max_t (xfs_rtxlen_t,1 ,xfs_extlen_to_rtxlen (mp, minlen)); - error =xfs_rtallocate_extent (ap->tp, ap->blkno, raminlen, ap->length, - &ralen, ap->wasdel, prod, &rtx); + error =xfs_rtallocate_extent (ap->tp, rtx, raminlen, ralen, &ralen, + ap->wasdel, prod, &rtx);if (error)return error;
fs/xfs/xfs_fsmap.c +4 -4
@@ -522,6 +522,7 @@ xfs_getfsmap_rtdev_rtbitmap_query(struct xfs_rtalloc_rec alow = {0 };struct xfs_rtalloc_rec ahigh = {0 };struct xfs_mount *mp = tp->t_mountp; +unsigned int mod;int error;xfs_ilock (mp->m_rbmip,XFS_ILOCK_SHARED |XFS_ILOCK_RTBITMAP );
@@ -530,10 +531,9 @@ xfs_getfsmap_rtdev_rtbitmap_query(* Set up query parameters to return free rtextents covering the range * we want. */ - alow.ar_startext = info->low.rm_startblock; - ahigh.ar_startext = info->high.rm_startblock; -do_div (alow.ar_startext, mp->m_sb.sb_rextsize); -if (do_div (ahigh.ar_startext, mp->m_sb.sb_rextsize)) + alow.ar_startext =xfs_rtb_to_rtxt (mp, info->low.rm_startblock); + ahigh.ar_startext =xfs_rtb_to_rtx (mp, info->high.rm_startblock, &mod); +if (mod) ahigh.ar_startext++; error =xfs_rtalloc_query_range (mp, tp, &alow, &ahigh, xfs_getfsmap_rtdev_rtbitmap_helper, info);
fs/xfs/xfs_rtalloc.c +1 -2
@@ -1056,8 +1056,7 @@ xfs_growfs_rt( nrblocks_step = (bmbno +1 ) *NBBY * nsbp->sb_blocksize * nsbp->sb_rextsize; nsbp->sb_rblocks =min (nrblocks, nrblocks_step); - nsbp->sb_rextents = nsbp->sb_rblocks; -do_div (nsbp->sb_rextents, nsbp->sb_rextsize); + nsbp->sb_rextents =xfs_rtb_to_rtxt (nmp, nsbp->sb_rblocks);ASSERT (nsbp->sb_rextents !=0 ); nsbp->sb_rextslog =xfs_highbit32 (nsbp->sb_rextents); nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog +1 ;
PATCH 6/7 xfs: create rt extent rounding helpers for realtime extent blocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a pair of functions to round rtblock numbers up or down to the nearest rt extent.
--- fs/xfs/libxfs/xfs_rtbitmap.h | 18 ++++++++++++++++++ fs/xfs/xfs_bmap_util.c | 8 +++----- fs/xfs/xfs_rtalloc.c | 4 ++-- fs/xfs/xfs_xchgrange.c | 4 ++-- 4 files changed, 25 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_rtbitmap.h +18 -0
@@ -56,6 +56,24 @@ xfs_rtb_to_rtxt(return div_u64 (rtbno, mp->m_sb.sb_rextsize); } +/* Round this rtblock up to the nearest rt extent size. */ +static inline xfs_rtblock_t +xfs_rtb_roundup_rtx ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno) +{ +return roundup_64 (rtbno, mp->m_sb.sb_rextsize); +} + +/* Round this rtblock down to the nearest rt extent size. */ +static inline xfs_rtblock_t +xfs_rtb_rounddown_rtx ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno) +{ +return rounddown_64 (rtbno, mp->m_sb.sb_rextsize); +} +/* * Functions for walking free space rtextents in the realtime bitmap. */
fs/xfs/xfs_bmap_util.c +3 -5
@@ -685,7 +685,7 @@ xfs_can_free_eofblocks(*/ end_fsb =XFS_B_TO_FSB (mp, (xfs_ufsize_t )XFS_ISIZE (ip));if (XFS_IS_REALTIME_INODE (ip) && mp->m_sb.sb_rextsize >1 ) - end_fsb =roundup_64 (end_fsb, mp->m_sb.sb_rextsize); + end_fsb =xfs_rtb_roundup_rtx (mp, end_fsb); last_fsb =XFS_B_TO_FSB (mp, mp->m_super->s_maxbytes);if (last_fsb <= end_fsb)return false;
@@ -984,10 +984,8 @@ xfs_free_file_space(/* We can only free complete realtime extents. */ if (xfs_inode_has_bigrtextents (ip)) { - startoffset_fsb =roundup_64 (startoffset_fsb, - mp->m_sb.sb_rextsize); - endoffset_fsb =rounddown_64 (endoffset_fsb, - mp->m_sb.sb_rextsize); + startoffset_fsb =xfs_rtb_roundup_rtx (mp, startoffset_fsb); + endoffset_fsb =xfs_rtb_rounddown_rtx (mp, endoffset_fsb); }/*
fs/xfs/xfs_rtalloc.c +2 -2
@@ -1552,8 +1552,8 @@ xfs_rtfile_convert_unwritten(if (mp->m_sb.sb_rextsize ==1 )return 0 ; - off =rounddown_64 (XFS_B_TO_FSBT (mp, pos), mp->m_sb.sb_rextsize); - endoff =roundup_64 (XFS_B_TO_FSB (mp, pos + len), mp->m_sb.sb_rextsize); + off =xfs_rtb_rounddown_rtx (mp,XFS_B_TO_FSBT (mp, pos)); + endoff =xfs_rtb_roundup_rtx (mp,XFS_B_TO_FSB (mp, pos + len));trace_xfs_rtfile_convert_unwritten (ip, pos, len);
fs/xfs/xfs_xchgrange.c +2 -2
@@ -29,6 +29,7 @@#include "xfs_icache.h" #include "xfs_log.h" #include "xfs_rtalloc.h" +#include "xfs_rtbitmap.h" /* Lock (and optionally join) two inodes for a file range exchange. */ void
@@ -802,8 +803,7 @@ xfs_xchg_range(* offsets and length in @fxr are safe to round up. */ if (XFS_IS_REALTIME_INODE (ip2)) - req.blockcount =roundup_64 (req.blockcount, - mp->m_sb.sb_rextsize); + req.blockcount =xfs_rtb_roundup_rtx (mp, req.blockcount); error =xfs_xchg_range_estimate (&req);if (error)
PATCH 7/7 xfs: use shifting and masking when converting rt extents, if possible
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Avoid the costs of integer division (32-bit and 64-bit) if the realtime extent size is a power of two.
--- fs/xfs/libxfs/xfs_rtbitmap.h | 20 ++++++++++++++++++++ fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/xfs_linux.h | 12 ++++++++++++ fs/xfs/xfs_mount.h | 2 ++ fs/xfs/xfs_rtalloc.c | 1 + fs/xfs/xfs_trans.c | 4 ++++ 6 files changed, 41 insertions(+)
fs/xfs/libxfs/xfs_rtbitmap.h +20 -0
@@ -11,6 +11,9 @@ xfs_rtx_to_rtb( struct xfs_mount *mp, xfs_rtxnum_t rtx) { +if (mp->m_rtxblklog >=0 ) +return rtx << mp->m_rtxblklog; +return rtx * mp->m_sb.sb_rextsize; }
@@ -19,6 +22,9 @@ xfs_rtxlen_to_extlen( struct xfs_mount *mp, xfs_rtxlen_t rtxlen) { +if (mp->m_rtxblklog >=0 ) +return rtxlen << mp->m_rtxblklog; +return rtxlen * mp->m_sb.sb_rextsize; }
@@ -28,6 +34,9 @@ xfs_extlen_to_rtxmod( struct xfs_mount *mp, xfs_extlen_t len) { +if (mp->m_rtxblklog >=0 ) +return len & mp->m_rtxblkmask; +return len % mp->m_sb.sb_rextsize; }
@@ -36,6 +45,9 @@ xfs_extlen_to_rtxlen( struct xfs_mount *mp, xfs_extlen_t len) { +if (mp->m_rtxblklog >=0 ) +return len >> mp->m_rtxblklog; +return len / mp->m_sb.sb_rextsize; }
@@ -45,6 +57,11 @@ xfs_rtb_to_rtx( xfs_rtblock_t rtbno, xfs_extlen_t *mod) { +if (mp->m_rtxblklog >=0 ) { + *mod = rtbno & mp->m_rtxblkmask; +return rtbno >> mp->m_rtxblklog; + } +return div_u64_rem (rtbno, mp->m_sb.sb_rextsize, mod); }
@@ -53,6 +70,9 @@ xfs_rtb_to_rtxt( struct xfs_mount *mp, xfs_rtblock_t rtbno) { +if (mp->m_rtxblklog >=0 ) +return rtbno >> mp->m_rtxblklog; +return div_u64 (rtbno, mp->m_sb.sb_rextsize); }
fs/xfs/libxfs/xfs_sb.c +2 -0
@@ -952,6 +952,8 @@ xfs_sb_mount_common( mp->m_blockmask = sbp->sb_blocksize -1 ; mp->m_blockwsize = sbp->sb_blocksize >>XFS_WORDLOG ; mp->m_blockwmask = mp->m_blockwsize -1 ; + mp->m_rtxblklog =log2_if_power2 (sbp->sb_rextsize); + mp->m_rtxblkmask =mask64_if_power2 (sbp->sb_rextsize); mp->m_alloc_mxr[0 ] =xfs_allocbt_maxrecs (mp, sbp->sb_blocksize,1 ); mp->m_alloc_mxr[1 ] =xfs_allocbt_maxrecs (mp, sbp->sb_blocksize,0 );
fs/xfs/xfs_linux.h +12 -0
@@ -200,6 +200,18 @@ static inline bool isaligned_64(uint64_t x, uint32_t y)return do_div (x, y) ==0 ; } +/* If @b is a power of 2, return log2(b). Else return -1. */ +static inline int8_t log2_if_power2 (unsigned long b) +{ +return is_power_of_2 (b) ?ilog2 (b) :-1 ; +} + +/* If @b is a power of 2, return a mask of the lower bits, else return zero. */ +static inline unsigned long long mask64_if_power2 (unsigned long b) +{ +return is_power_of_2 (b) ? b -1 :0 ; +} +int xfs_rw_bdev (struct block_device *bdev,sector_t sector,unsigned int count,char *data,enum req_op op);
fs/xfs/xfs_mount.h +2 -0
@@ -118,6 +118,7 @@ typedef struct xfs_mount {uint8_t m_blkbb_log;/* blocklog - BBSHIFT */ uint8_t m_agno_log;/* log #ag's */ uint8_t m_sectbb_log;/* sectlog - BBSHIFT */ +int8_t m_rtxblklog;/* log2 of rextsize, if possible */ uint m_blockmask;/* sb_blocksize-1 */ uint m_blockwsize;/* sb_blocksize in words */ uint m_blockwmask;/* blockwsize-1 */
@@ -151,6 +152,7 @@ typedef struct xfs_mount {uint64_t m_features;/* active filesystem features */ uint64_t m_low_space[XFS_LOWSP_MAX ];uint64_t m_low_rtexts[XFS_LOWSP_MAX ]; +uint64_t m_rtxblkmask;/* rt extent block mask */ struct xfs_ino_geometry m_ino_geo;/* inode geometry */ struct xfs_trans_resv m_resv;/* precomputed res values */ /* low free space thresholds */
fs/xfs/xfs_rtalloc.c +1 -0
@@ -1052,6 +1052,7 @@ xfs_growfs_rt(* Calculate new sb and mount fields for this round. */ nsbp->sb_rextsize = in->extsize; + nmp->m_rtxblklog =-1 ;/* don't use shift or masking */ nsbp->sb_rbmblocks = bmbno +1 ; nrblocks_step = (bmbno +1 ) *NBBY * nsbp->sb_blocksize * nsbp->sb_rextsize;
fs/xfs/xfs_trans.c +4 -0
@@ -710,6 +710,10 @@ xfs_trans_unreserve_and_mod_sb( mp->m_sb.sb_agcount += tp->t_agcount_delta; mp->m_sb.sb_imax_pct += tp->t_imaxpct_delta; mp->m_sb.sb_rextsize += tp->t_rextsize_delta; +if (tp->t_rextsize_delta) { + mp->m_rtxblklog =log2_if_power2 (mp->m_sb.sb_rextsize); + mp->m_rtxblkmask =mask64_if_power2 (mp->m_sb.sb_rextsize); + } mp->m_sb.sb_rbmblocks += tp->t_rbmblocks_delta; mp->m_sb.sb_rblocks += tp->t_rblocks_delta; mp->m_sb.sb_rextents += tp->t_rextents_delta;
cover xfs: refactor rtbitmap/summary macros
In reply to Darrick J. WongHi all,
In preparation for adding block headers and enforcing endian order in rtbitmap and rtsummary blocks, replace open-coded geometry computations and fugly macros with proper helper functions that can be typechecked. Soon we'll be needing to add more complex logic to the helpers.
If you're going to start using this mess, you probably ought to just pull from my git trees, which are linked below.
This is an extraordinary way to destroy everything. 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=refactor-rtbitmap-macros
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=refactor-rtbitmap-macros
--- fs/xfs/libxfs/xfs_format.h | 32 ++--- fs/xfs/libxfs/xfs_rtbitmap.c | 268 ++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_rtbitmap.h | 133 +++++++++++++++++++ fs/xfs/libxfs/xfs_trans_resv.c | 9 + fs/xfs/libxfs/xfs_types.h | 2 fs/xfs/scrub/rtsummary.c | 52 ++++---- fs/xfs/scrub/rtsummary.h | 6 - fs/xfs/scrub/rtsummary_repair.c | 7 + fs/xfs/scrub/trace.c | 1 fs/xfs/scrub/trace.h | 4 - fs/xfs/xfs_ondisk.h | 4 + fs/xfs/xfs_rtalloc.c | 39 +++--- 12 files changed, 409 insertions(+), 148 deletions(-)
PATCH 1/8 xfs: convert the rtbitmap block and bit macros to static inline functions
From: Darrick J. Wong <[email protected]>
Replace these macros with typechecked helper functions. Eventually we're going to add more logic to the helpers and it'll be easier if we don't have to macro it up.
--- fs/xfs/libxfs/xfs_format.h | 5 ----- fs/xfs/libxfs/xfs_rtbitmap.c | 22 +++++++++++----------- fs/xfs/libxfs/xfs_rtbitmap.h | 27 +++++++++++++++++++++++++++ fs/xfs/scrub/rtsummary.c | 2 +- fs/xfs/xfs_rtalloc.c | 20 ++++++++++---------- 5 files changed, 49 insertions(+), 27 deletions(-)
fs/xfs/libxfs/xfs_format.h +0 -5
@@ -1209,11 +1209,6 @@ static inline bool xfs_dinode_has_large_extent_counts( ((xfs_suminfo_t *)((bp)->b_addr + \ (((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp)))) -#define XFS_BITTOBLOCK (mp,bi) ((bi) >> (mp)->m_blkbit_log) -#define XFS_BLOCKTOBIT (mp,bb) ((bb) << (mp)->m_blkbit_log) -#define XFS_BITTOWORD (mp,bi) \ - ((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp))) -#define XFS_RTMIN (a,b) ((a) < (b) ? (a) : (b))#define XFS_RTMAX (a,b) ((a) > (b) ? (a) : (b))
fs/xfs/libxfs/xfs_rtbitmap.c +11 -11
@@ -123,7 +123,7 @@ xfs_rtfind_back(/* * Compute and read in starting bitmap block for starting block. */ - block =XFS_BITTOBLOCK (mp, start); + block =xfs_rtx_to_rbmblock (mp, start); error =xfs_rtbuf_get (mp, tp, block,0 , &bp);if (error) {return error;
@@ -132,7 +132,7 @@ xfs_rtfind_back(/* * Get the first word's index & point to it. */ - word =XFS_BITTOWORD (mp, start); + word =xfs_rtx_to_rbmword (mp, start); b = &bufp[word]; bit = (int )(start & (XFS_NBWORD -1 )); len = start - limit +1 ;
@@ -298,7 +298,7 @@ xfs_rtfind_forw(/* * Compute and read in starting bitmap block for starting block. */ - block =XFS_BITTOBLOCK (mp, start); + block =xfs_rtx_to_rbmblock (mp, start); error =xfs_rtbuf_get (mp, tp, block,0 , &bp);if (error) {return error;
@@ -307,7 +307,7 @@ xfs_rtfind_forw(/* * Get the first word's index & point to it. */ - word =XFS_BITTOWORD (mp, start); + word =xfs_rtx_to_rbmword (mp, start); b = &bufp[word]; bit = (int )(start & (XFS_NBWORD -1 )); len = limit - start +1 ;
@@ -559,7 +559,7 @@ xfs_rtmodify_range(/* * Compute starting bitmap block number. */ - block =XFS_BITTOBLOCK (mp, start); + block =xfs_rtx_to_rbmblock (mp, start);/* * Read the bitmap block, and point to its data. */
@@ -571,7 +571,7 @@ xfs_rtmodify_range(/* * Compute the starting word's address, and starting bit. */ - word =XFS_BITTOWORD (mp, start); + word =xfs_rtx_to_rbmword (mp, start); first = b = &bufp[word]; bit = (int )(start & (XFS_NBWORD -1 ));/*
@@ -737,7 +737,7 @@ xfs_rtfree_range(if (preblock < start) { error =xfs_rtmodify_summary (mp, tp,XFS_RTBLOCKLOG (start - preblock), -XFS_BITTOBLOCK (mp, preblock),-1 , rbpp, rsb); +xfs_rtx_to_rbmblock (mp, preblock),-1 , rbpp, rsb);if (error) {return error; }
@@ -749,7 +749,7 @@ xfs_rtfree_range(if (postblock > end) { error =xfs_rtmodify_summary (mp, tp,XFS_RTBLOCKLOG (postblock - end), -XFS_BITTOBLOCK (mp, end +1 ),-1 , rbpp, rsb); +xfs_rtx_to_rbmblock (mp, end +1 ),-1 , rbpp, rsb);if (error) {return error; }
@@ -760,7 +760,7 @@ xfs_rtfree_range(*/ error =xfs_rtmodify_summary (mp, tp,XFS_RTBLOCKLOG (postblock +1 - preblock), -XFS_BITTOBLOCK (mp, preblock),1 , rbpp, rsb); +xfs_rtx_to_rbmblock (mp, preblock),1 , rbpp, rsb);return error; }
@@ -793,7 +793,7 @@ xfs_rtcheck_range(/* * Compute starting bitmap block number */ - block =XFS_BITTOBLOCK (mp, start); + block =xfs_rtx_to_rbmblock (mp, start);/* * Read the bitmap block. */
@@ -805,7 +805,7 @@ xfs_rtcheck_range(/* * Compute the starting word's address, and starting bit. */ - word =XFS_BITTOWORD (mp, start); + word =xfs_rtx_to_rbmword (mp, start); b = &bufp[word]; bit = (int )(start & (XFS_NBWORD -1 ));/*
fs/xfs/libxfs/xfs_rtbitmap.h +27 -0
@@ -94,6 +94,33 @@ xfs_rtb_rounddown_rtx(return rounddown_64 (rtbno, mp->m_sb.sb_rextsize); } +/* Convert an rt extent number to a file block offset in the rt bitmap file. */ +static inline xfs_fileoff_t +xfs_rtx_to_rbmblock ( +struct xfs_mount *mp, +xfs_rtxnum_t rtx) +{ +return rtx >> mp->m_blkbit_log; +} + +/* Convert an rt extent number to a word offset within an rt bitmap block. */ +static inline unsigned int +xfs_rtx_to_rbmword ( +struct xfs_mount *mp, +xfs_rtxnum_t rtx) +{ +return (rtx >>XFS_NBWORDLOG ) &XFS_BLOCKWMASK (mp); +} + +/* Convert a file block offset in the rt bitmap file to an rt extent number. */ +static inline xfs_rtxnum_t +xfs_rbmblock_to_rtx ( +struct xfs_mount *mp, +xfs_fileoff_t rbmoff) +{ +return rbmoff << mp->m_blkbit_log; +} +/* * Functions for walking free space rtextents in the realtime bitmap. */
fs/xfs/scrub/rtsummary.c +1 -1
@@ -134,7 +134,7 @@ xchk_rtsum_record_free(return error;/* Compute the relevant location in the rtsum file. */ - rbmoff =XFS_BITTOBLOCK (mp, rec->ar_startext); + rbmoff =xfs_rtx_to_rbmblock (mp, rec->ar_startext); lenlog =XFS_RTBLOCKLOG (rec->ar_extcount); offs =XFS_SUMOFFS (mp, lenlog, rbmoff);
fs/xfs/xfs_rtalloc.c +10 -10
@@ -182,7 +182,7 @@ xfs_rtallocate_range(*/ error =xfs_rtmodify_summary (mp, tp,XFS_RTBLOCKLOG (postblock +1 - preblock), -XFS_BITTOBLOCK (mp, preblock),-1 , rbpp, rsb); +xfs_rtx_to_rbmblock (mp, preblock),-1 , rbpp, rsb);if (error) {return error; }
@@ -193,7 +193,7 @@ xfs_rtallocate_range(if (preblock < start) { error =xfs_rtmodify_summary (mp, tp,XFS_RTBLOCKLOG (start - preblock), -XFS_BITTOBLOCK (mp, preblock),1 , rbpp, rsb); +xfs_rtx_to_rbmblock (mp, preblock),1 , rbpp, rsb);if (error) {return error; }
@@ -205,7 +205,7 @@ xfs_rtallocate_range(if (postblock > end) { error =xfs_rtmodify_summary (mp, tp,XFS_RTBLOCKLOG (postblock - end), -XFS_BITTOBLOCK (mp, end +1 ),1 , rbpp, rsb); +xfs_rtx_to_rbmblock (mp, end +1 ),1 , rbpp, rsb);if (error) {return error; }
@@ -249,8 +249,8 @@ xfs_rtallocate_extent_block(* Loop over all the extents starting in this bitmap block, * looking for one that's long enough. */ -for (i =XFS_BLOCKTOBIT (mp, bbno), besti =-1 , bestlen =0 , - end =XFS_BLOCKTOBIT (mp, bbno +1 ) -1 ; +for (i =xfs_rbmblock_to_rtx (mp, bbno), besti =-1 , bestlen =0 , + end =xfs_rbmblock_to_rtx (mp, bbno +1 ) -1 ; i <= end; i++) {/*
@@ -487,7 +487,7 @@ xfs_rtallocate_extent_near( *rtx = r;return 0 ; } - bbno =XFS_BITTOBLOCK (mp, start); + bbno =xfs_rtx_to_rbmblock (mp, start); i =0 ;ASSERT (minlen !=0 ); log2len =xfs_highbit32 (minlen);
@@ -706,8 +706,8 @@ xfs_rtallocate_extent_size(* allocator is beyond the next bitmap block, * skip to that bitmap block. */ -if (XFS_BITTOBLOCK (mp, n) > i +1 ) - i =XFS_BITTOBLOCK (mp, n) -1 ; +if (xfs_rtx_to_rbmblock (mp, n) > i +1 ) + i =xfs_rtx_to_rbmblock (mp, n) -1 ; } }/*
@@ -769,8 +769,8 @@ xfs_rtallocate_extent_size(* allocator is beyond the next bitmap block, * skip to that bitmap block. */ -if (XFS_BITTOBLOCK (mp, n) > i +1 ) - i =XFS_BITTOBLOCK (mp, n) -1 ; +if (xfs_rtx_to_rbmblock (mp, n) > i +1 ) + i =xfs_rtx_to_rbmblock (mp, n) -1 ; } }/*
PATCH 2/8 xfs: remove XFS_BLOCKWSIZE and XFS_BLOCKWMASK macros
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Remove these trivial macros since they're not even part of the ondisk format.
--- fs/xfs/libxfs/xfs_format.h | 2 -- fs/xfs/libxfs/xfs_rtbitmap.c | 16 ++++++++-------- fs/xfs/libxfs/xfs_rtbitmap.h | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_format.h +0 -2
@@ -1196,8 +1196,6 @@ static inline bool xfs_dinode_has_large_extent_counts(#define XFS_BLOCKSIZE (mp) ((mp)->m_sb.sb_blocksize)#define XFS_BLOCKMASK (mp) ((mp)->m_blockmask) -#define XFS_BLOCKWSIZE (mp) ((mp)->m_blockwsize) -#define XFS_BLOCKWMASK (mp) ((mp)->m_blockwmask)/* * RT Summary and bit manipulation macros.
fs/xfs/libxfs/xfs_rtbitmap.c +8 -8
@@ -181,7 +181,7 @@ xfs_rtfind_back(return error; } bufp = bp->b_addr; - word =XFS_BLOCKWMASK (mp); + word = mp->m_blockwsize -1 ; b = &bufp[word]; }else {/*
@@ -227,7 +227,7 @@ xfs_rtfind_back(return error; } bufp = bp->b_addr; - word =XFS_BLOCKWMASK (mp); + word = mp->m_blockwsize -1 ; b = &bufp[word]; }else {/*
@@ -345,7 +345,7 @@ xfs_rtfind_forw(* Go on to next block if that's where the next word is * and we need the next word. */ -if (++word ==XFS_BLOCKWSIZE (mp) && i < len) { +if (++word == mp->m_blockwsize && i < len) {/* * If done with this block, get the previous one. */
@@ -390,7 +390,7 @@ xfs_rtfind_forw(* Go on to next block if that's where the next word is * and we need the next word. */ -if (++word ==XFS_BLOCKWSIZE (mp) && i < len) { +if (++word == mp->m_blockwsize && i < len) {/* * If done with this block, get the next one. */
@@ -600,7 +600,7 @@ xfs_rtmodify_range(* Go on to the next block if that's where the next word is * and we need the next word. */ -if (++word ==XFS_BLOCKWSIZE (mp) && i < len) { +if (++word == mp->m_blockwsize && i < len) {/* * Log the changed part of this block. * Get the next one.
@@ -640,7 +640,7 @@ xfs_rtmodify_range(* Go on to the next block if that's where the next word is * and we need the next word. */ -if (++word ==XFS_BLOCKWSIZE (mp) && i < len) { +if (++word == mp->m_blockwsize && i < len) {/* * Log the changed part of this block. * Get the next one.
@@ -843,7 +843,7 @@ xfs_rtcheck_range(* Go on to next block if that's where the next word is * and we need the next word. */ -if (++word ==XFS_BLOCKWSIZE (mp) && i < len) { +if (++word == mp->m_blockwsize && i < len) {/* * If done with this block, get the next one. */
@@ -889,7 +889,7 @@ xfs_rtcheck_range(* Go on to next block if that's where the next word is * and we need the next word. */ -if (++word ==XFS_BLOCKWSIZE (mp) && i < len) { +if (++word == mp->m_blockwsize && i < len) {/* * If done with this block, get the next one. */
fs/xfs/libxfs/xfs_rtbitmap.h +1 -1
@@ -109,7 +109,7 @@ xfs_rtx_to_rbmword( struct xfs_mount *mp, xfs_rtxnum_t rtx) { -return (rtx >>XFS_NBWORDLOG ) &XFS_BLOCKWMASK (mp); +return (rtx >>XFS_NBWORDLOG ) & (mp->m_blockwsize -1 ); }/* Convert a file block offset in the rt bitmap file to an rt extent number. */