XFS: sanitise VFS inode extraction V2
cover XFS: sanitise VFS inode extraction V2
Getting the VFS inode from the XFS inode is done in a variety of ways right now - direct deference or one of two XFS_ITOV macros. This should be consistent throughout the code - this patch series does that in a way that is consistent with the opposite XFS_I() conversion. We now use VFS_I() to extract the VFS inode from the XFS inode.
Version 2:
o don't use vn_to_inode() and inode_to_vn() functions as they are not needed
o rediff patches 2 and 3 against the change patch.
PATCH 2/3 XFS: kill shouty XFS_ITOV_NULL macro
Replace XFS_ITOV_NULL() with the new VFS_I() inline.
--- fs/xfs/linux-2.6/xfs_vnode.c | 2 +- fs/xfs/quota/xfs_qm_syscalls.c | 2 +- fs/xfs/xfs_inode.h | 1 - fs/xfs/xfs_vfsops.c | 2 +- fs/xfs/xfs_vnodeops.c | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-)
fs/xfs/linux-2.6/xfs_vnode.c +1 -1
@@ -158,7 +158,7 @@ vn_hold(*/ static inline int xfs_icount (struct xfs_inode *ip) { -bhv_vnode_t *vp =XFS_ITOV_NULL (ip); +bhv_vnode_t *vp =VFS_I (ip);if (vp)return vn_count (vp);
fs/xfs/quota/xfs_qm_syscalls.c +1 -1
@@ -1054,7 +1054,7 @@ xfs_qm_dqrele_inodes_ag( first_index =XFS_INO_TO_AGINO (mp, ip->i_ino +1 );/* Root inode, rbmip and rsumip have associated blocks */ - vp =XFS_ITOV_NULL (ip); + vp =VFS_I (ip);if (!vp || ip ==XFS_QI_UQIP (mp) || ip ==XFS_QI_GQIP (mp)) {ASSERT (ip->i_udquot ==NULL );ASSERT (ip->i_gdquot ==NULL );
fs/xfs/xfs_inode.h +0 -1
@@ -272,7 +272,6 @@ static inline struct inode *VFS_I(struct xfs_inode *ip)return (struct inode *)ip->i_vnode; }#define XFS_ITOV (ip) VFS_I(ip) -#define XFS_ITOV_NULL (ip) VFS_I(ip)/* * i_flags helper functions
fs/xfs/xfs_vfsops.c +1 -1
@@ -325,7 +325,7 @@ xfs_sync_inodes_ag(* skip inodes in reclaim. Let xfs_syncsub do that for * us so we don't need to worry. */ - vp =XFS_ITOV_NULL (ip); + vp =VFS_I (ip);if (!vp) {read_unlock (&pag->pag_ici_lock);continue ;
fs/xfs/xfs_vnodeops.c +1 -1
@@ -2924,7 +2924,7 @@ xfs_finish_reclaim( int sync_mode) {xfs_perag_t *pag =xfs_get_perag (ip->i_mount, ip->i_ino); -bhv_vnode_t *vp =XFS_ITOV_NULL (ip); +bhv_vnode_t *vp =VFS_I (ip);if (vp &&VN_BAD (vp)) goto reclaim;
Signature · 1 line
1.5.6
PATCH 1/3 XFS: Avoid directly referencing the VFS inode V2
In reply to Dave ChinnerIn several places we directly convert from the XFS inode to the linux (VFS) inode by a simple deference of ip->i_vnode. We should not do this - a helper function should be used to extract the VFS inode from the XFS inode.
Introduce the function VFS_I() to extract the VFS inode from the XFS inode. The name was chosen to match XFS_I() which is used to extract the XFS inode from the VFS inode.
Version 2:
o don't use vn_to_inode() and inode_to_vn() functions as they are not needed
--- fs/xfs/linux-2.6/xfs_export.c | 6 +++--- fs/xfs/linux-2.6/xfs_fs_subr.c | 6 +++--- fs/xfs/linux-2.6/xfs_iops.c | 14 +++++++------- fs/xfs/linux-2.6/xfs_iops.h | 6 ------ fs/xfs/linux-2.6/xfs_lrw.c | 2 +- fs/xfs/linux-2.6/xfs_super.c | 4 ++-- fs/xfs/xfs_iget.c | 7 ++++--- fs/xfs/xfs_inode.h | 22 +++++++++++++++++++--- fs/xfs/xfs_utils.c | 4 ++-- 9 files changed, 41 insertions(+), 30 deletions(-)
fs/xfs/linux-2.6/xfs_export.c +3 -3
@@ -139,7 +139,7 @@ xfs_nfs_get_inode( }xfs_iunlock (ip,XFS_ILOCK_SHARED ); -return ip->i_vnode; +return VFS_I (ip); } STATIC struct dentry *
@@ -219,9 +219,9 @@ xfs_fs_get_parent(if (unlikely (error))return ERR_PTR (-error); - parent =d_alloc_anon (cip->i_vnode); + parent =d_alloc_anon (VFS_I (cip));if (unlikely (!parent)) { -iput (cip->i_vnode); +iput (VFS_I (cip));return ERR_PTR (-ENOMEM ); }return parent;
fs/xfs/linux-2.6/xfs_fs_subr.c +3 -3
@@ -31,7 +31,7 @@ xfs_tosspages( xfs_off_t last, int fiopt) { -struct address_space *mapping = ip->i_vnode->i_mapping; +struct address_space *mapping =VFS_I (ip)->i_mapping;if (mapping->nrpages)truncate_inode_pages (mapping, first);
@@ -44,7 +44,7 @@ xfs_flushinval_pages( xfs_off_t last, int fiopt) { -struct address_space *mapping = ip->i_vnode->i_mapping; +struct address_space *mapping =VFS_I (ip)->i_mapping;int ret =0 ;if (mapping->nrpages) {
@@ -64,7 +64,7 @@ xfs_flush_pages( uint64_t flags, int fiopt) { -struct address_space *mapping = ip->i_vnode->i_mapping; +struct address_space *mapping =VFS_I (ip)->i_mapping;int ret =0 ;int ret2;
fs/xfs/linux-2.6/xfs_iops.c +7 -7
@@ -62,7 +62,7 @@ voidxfs_synchronize_atime ( xfs_inode_t *ip) { -struct inode *inode = ip->i_vnode; +struct inode *inode =VFS_I (ip);if (inode) { ip->i_d.di_atime.t_sec = (__int32_t )inode->i_atime.tv_sec;
@@ -79,7 +79,7 @@ voidxfs_mark_inode_dirty_sync ( xfs_inode_t *ip) { -struct inode *inode = ip->i_vnode; +struct inode *inode =VFS_I (ip);if (inode)mark_inode_dirty_sync (inode);
@@ -299,7 +299,7 @@ xfs_vn_mknod(if (unlikely (error)) goto out_free_acl; - inode = ip->i_vnode; + inode =VFS_I (ip); error =xfs_init_security (inode, dir);if (unlikely (error))
@@ -366,7 +366,7 @@ xfs_vn_lookup(return NULL ; } -return d_splice_alias (cip->i_vnode, dentry); +return d_splice_alias (VFS_I (cip), dentry); } STATIC struct dentry *
@@ -399,12 +399,12 @@ xfs_vn_ci_lookup(/* if exact match, just splice and exit */ if (!ci_name.name) -return d_splice_alias (ip->i_vnode, dentry); +return d_splice_alias (VFS_I (ip), dentry);/* else case-insensitive match... */ dname.name = ci_name.name; dname.len = ci_name.len; - dentry =d_add_ci (ip->i_vnode, dentry, &dname); + dentry =d_add_ci (VFS_I (ip), dentry, &dname);kmem_free (ci_name.name);return dentry; }
@@ -478,7 +478,7 @@ xfs_vn_symlink(if (unlikely (error)) goto out; - inode = cip->i_vnode; + inode =VFS_I (cip); error =xfs_init_security (inode, dir);if (unlikely (error))
fs/xfs/linux-2.6/xfs_iops.h +0 -6
@@ -33,10 +33,4 @@ struct xfs_inode;extern void xfs_ichgtime (struct xfs_inode *,int );extern void xfs_ichgtime_fast (struct xfs_inode *,struct inode *,int ); -#define xfs_vtoi (vp) \ - ((struct xfs_inode *)vn_to_inode(vp)->i_private) - -#define XFS_I (inode) \ - ((struct xfs_inode *)(inode)->i_private) -#endif /* __XFS_IOPS_H__ */
fs/xfs/linux-2.6/xfs_lrw.c +1 -1
@@ -137,7 +137,7 @@ xfs_iozero(struct address_space *mapping;int status; - mapping = ip->i_vnode->i_mapping; + mapping =VFS_I (ip)->i_mapping; do { unsigned offset, bytes; void *fsdata;
fs/xfs/linux-2.6/xfs_super.c +2 -2
@@ -1107,7 +1107,7 @@ voidxfs_flush_inode ( xfs_inode_t *ip) { -struct inode *inode = ip->i_vnode; +struct inode *inode =VFS_I (ip);igrab (inode);xfs_syncd_queue_work (ip->i_mount, inode, xfs_flush_inode_work);
@@ -1826,7 +1826,7 @@ xfs_fs_fill_super( sb->s_time_gran =1 ;set_posix_acl_flag (sb); - root =igrab (mp->m_rootip->i_vnode); + root =igrab (VFS_I (mp->m_rootip));if (!root) { error =ENOENT ; goto fail_unmount;
fs/xfs/xfs_iget.c +4 -3
@@ -392,10 +392,11 @@ xfs_iput(xfs_inode_t *ip,* Special iput for brand-new inodes that are still locked */ void -xfs_iput_new (xfs_inode_t *ip, -uint lock_flags) +xfs_iput_new ( +xfs_inode_t *ip, +uint lock_flags) { -struct inode *inode = ip->i_vnode; +struct inode *inode =VFS_I (ip);xfs_itrace_entry (ip);
fs/xfs/xfs_inode.h +19 -3
@@ -255,6 +255,25 @@ typedef struct xfs_inode {#define XFS_ISIZE (ip) (((ip)->i_d.di_mode & S_IFMT) == S_IFREG) ? \ (ip)->i_size : (ip)->i_d.di_size; +/* Convert from vfs inode to xfs inode */ +static inline struct xfs_inode *XFS_I (struct inode *inode) +{ +return (struct xfs_inode *)inode->i_private; +} + +static inline struct xfs_inode *xfs_vtoi (bhv_vnode_t *vp) +{ +return XFS_I ((struct inode *)vp); +} + +/* convert from xfs inode to vfs inode */ +static inline struct inode *VFS_I (struct xfs_inode *ip) +{ +return (struct inode *)ip->i_vnode; +} +#define XFS_ITOV (ip) VFS_I(ip) +#define XFS_ITOV_NULL (ip) VFS_I(ip) +/* * i_flags helper functions */
@@ -431,9 +450,6 @@ xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)#define XFS_ITRUNC_DEFINITE 0x1#define XFS_ITRUNC_MAYBE 0x2 -#define XFS_ITOV (ip) ((ip)->i_vnode) -#define XFS_ITOV_NULL (ip) ((ip)->i_vnode) -/* * For multiple groups support: if S_ISGID bit is set in the parent * directory, group of new file is set to that of the parent, and
fs/xfs/xfs_utils.c +2 -2
@@ -237,7 +237,7 @@ xfs_droplink(ASSERT (ip->i_d.di_nlink >0 ); ip->i_d.di_nlink--; -drop_nlink (ip->i_vnode); +drop_nlink (VFS_I (ip));xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); error =0 ;
@@ -301,7 +301,7 @@ xfs_bumplink(ASSERT (ip->i_d.di_nlink >0 ); ip->i_d.di_nlink++; -inc_nlink (ip->i_vnode); +inc_nlink (VFS_I (ip));if ((ip->i_d.di_version ==XFS_DINODE_VERSION_1 ) && (ip->i_d.di_nlink >XFS_MAXLINK_1 )) {/*
Signature · 1 line
1.5.6
PATCH 3/3 XFS: Kill shouty XFS_ITOV() macro
In reply to Dave ChinnerReplace XFS_ITOV() with the new VFS_I() inline.
--- fs/xfs/linux-2.6/xfs_ioctl.c | 4 ++-- fs/xfs/linux-2.6/xfs_iops.c | 2 +- fs/xfs/linux-2.6/xfs_linux.h | 2 +- fs/xfs/linux-2.6/xfs_super.c | 2 +- fs/xfs/quota/xfs_dquot.c | 2 +- fs/xfs/xfs_bmap.c | 2 +- fs/xfs/xfs_dfrag.c | 4 ++-- fs/xfs/xfs_inode.c | 4 ++-- fs/xfs/xfs_inode.h | 1 - fs/xfs/xfs_itable.c | 2 +- fs/xfs/xfs_utils.h | 4 ++-- fs/xfs/xfs_vfsops.c | 8 ++++---- fs/xfs/xfs_vnodeops.c | 10 +++++----- 13 files changed, 23 insertions(+), 24 deletions(-)
fs/xfs/linux-2.6/xfs_ioctl.c +2 -2
@@ -247,7 +247,7 @@ xfs_vget_fsop_handlereq(xfs_iunlock (ip,XFS_ILOCK_SHARED ); - *inode =XFS_ITOV (ip); + *inode =VFS_I (ip);return 0 ; }
@@ -1162,7 +1162,7 @@ xfs_ioctl_setattr( (mask & FSX_NONBLOCK) ? DM_FLAGS_NDELAY : 0); } -vn_revalidate (XFS_ITOV (ip));/* update flags */ +vn_revalidate (VFS_I (ip));/* update flags */ return 0 ; error_return:
fs/xfs/linux-2.6/xfs_iops.c +1 -1
@@ -101,7 +101,7 @@ xfs_ichgtime( xfs_inode_t *ip, int flags) { -struct inode *inode =vn_to_inode (XFS_ITOV (ip)); +struct inode *inode =VFS_I (ip);timespec_t tv;nanotime (&tv);
fs/xfs/linux-2.6/xfs_linux.h +1 -1
@@ -180,7 +180,7 @@#define xfs_sort (a,n,s,fn) sort(a,n,s,fn,NULL)#define xfs_stack_trace () dump_stack()#define xfs_itruncate_data (ip, off) \ - (-vmtruncate(vn_to_inode(XFS_ITOV(ip)), (off))) + (-vmtruncate(vn_to_inode(VFS_I(ip)), (off)))/* Move the kernel do_div definition off to one side */
fs/xfs/linux-2.6/xfs_super.c +1 -1
@@ -1132,7 +1132,7 @@ voidxfs_flush_device ( xfs_inode_t *ip) { -struct inode *inode =vn_to_inode (XFS_ITOV (ip)); +struct inode *inode =VFS_I (ip);igrab (inode);xfs_syncd_queue_work (ip->i_mount, inode, xfs_flush_device_work);
fs/xfs/quota/xfs_dquot.c +1 -1
@@ -431,7 +431,7 @@ xfs_qm_dqalloc(* when it unlocks the inode. Since we want to keep the quota * inode around, we bump the vnode ref count now. */ -VN_HOLD (XFS_ITOV (quotip)); +VN_HOLD (VFS_I (quotip));xfs_trans_ijoin (tp, quotip,XFS_ILOCK_EXCL ); nmaps =1 ;
fs/xfs/xfs_bmap.c +1 -1
@@ -4000,7 +4000,7 @@ xfs_bmap_add_attrfork( ip->i_d.di_aformat =XFS_DINODE_FMT_EXTENTS ; }ASSERT (ip->i_d.di_anextents ==0 ); -VN_HOLD (XFS_ITOV (ip)); +VN_HOLD (VFS_I (ip));xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE );switch (ip->i_d.di_format) {
fs/xfs/xfs_dfrag.c +2 -2
@@ -150,8 +150,8 @@ xfs_swap_extents( } sbp = &sxp->sx_stat; - vp =XFS_ITOV (ip); - tvp =XFS_ITOV (tip); + vp =VFS_I (ip); + tvp =VFS_I (tip);/* Lock in i_ino order */ if (ip->i_ino < tip->i_ino) {
fs/xfs/xfs_inode.c +2 -2
@@ -1077,7 +1077,7 @@ xfs_ialloc( }ASSERT (ip !=NULL ); - vp =XFS_ITOV (ip); + vp =VFS_I (ip); ip->i_d.di_mode = (__uint16_t )mode; ip->i_d.di_onlink =0 ; ip->i_d.di_nlink = nlink;
@@ -1408,7 +1408,7 @@ xfs_itruncate_start( (flags == XFS_ITRUNC_MAYBE)); mp = ip->i_mount; - vp =XFS_ITOV (ip); + vp =VFS_I (ip);/* wait for the completion of any pending DIOs */ if (new_size < ip->i_size)
fs/xfs/xfs_inode.h +0 -1
@@ -271,7 +271,6 @@ static inline struct inode *VFS_I(struct xfs_inode *ip) {return (struct inode *)ip->i_vnode; } -#define XFS_ITOV (ip) VFS_I(ip)/* * i_flags helper functions
fs/xfs/xfs_itable.c +1 -1
@@ -72,7 +72,7 @@ xfs_bulkstat_one_iget(ASSERT (ip !=NULL );ASSERT (ip->i_blkno != (xfs_daddr_t )0 ); - vp =XFS_ITOV (ip); + vp =VFS_I (ip); dic = &ip->i_d;/* xfs_iget returns the following without needing
fs/xfs/xfs_utils.h +2 -2
@@ -18,8 +18,8 @@#ifndef __XFS_UTILS_H__#define __XFS_UTILS_H__ -#define IRELE (ip) VN_RELE(XFS_ITOV(ip)) -#define IHOLD (ip) VN_HOLD(XFS_ITOV(ip)) +#define IRELE (ip) VN_RELE(VFS_I(ip)) +#define IHOLD (ip) VN_HOLD(VFS_I(ip))extern int xfs_truncate_file (xfs_mount_t *,xfs_inode_t *); extern int xfs_dir_ialloc(xfs_trans_t **, xfs_inode_t *, mode_t, xfs_nlink_t,
fs/xfs/xfs_vfsops.c +4 -4
@@ -128,7 +128,7 @@ xfs_unmount_flush(xfs_inode_t *rip = mp->m_rootip;xfs_inode_t *rbmip;xfs_inode_t *rsumip =NULL ; -bhv_vnode_t *rvp =XFS_ITOV (rip); +bhv_vnode_t *rvp =VFS_I (rip);int error;xfs_ilock (rip,XFS_ILOCK_EXCL |XFS_ILOCK_PARENT );
@@ -146,7 +146,7 @@ xfs_unmount_flush(if (error ==EFSCORRUPTED ) goto fscorrupt_out; -ASSERT (vn_count (XFS_ITOV (rbmip)) ==1 ); +ASSERT (vn_count (VFS_I (rbmip)) ==1 ); rsumip = mp->m_rsumip;xfs_ilock (rsumip,XFS_ILOCK_EXCL );
@@ -157,7 +157,7 @@ xfs_unmount_flush(if (error ==EFSCORRUPTED ) goto fscorrupt_out; -ASSERT (vn_count (XFS_ITOV (rsumip)) ==1 ); +ASSERT (vn_count (VFS_I (rsumip)) ==1 ); }/*
@@ -360,7 +360,7 @@ xfs_sync_inodes_ag(continue ;xfs_ilock (ip, lock_flags); -ASSERT (vp ==XFS_ITOV (ip)); +ASSERT (vp ==VFS_I (ip));ASSERT (ip->i_mount == mp); vnode_refed =B_TRUE ;
fs/xfs/xfs_vnodeops.c +5 -5
@@ -705,7 +705,7 @@ xfs_fsync(return XFS_ERROR (EIO );/* capture size updates in I/O completion before writing the inode. */ - error =filemap_fdatawait (vn_to_inode (XFS_ITOV (ip))->i_mapping); + error =filemap_fdatawait (vn_to_inode (VFS_I (ip))->i_mapping);if (error)return XFS_ERROR (error);
@@ -1151,7 +1151,7 @@ intxfs_release ( xfs_inode_t *ip) { -bhv_vnode_t *vp =XFS_ITOV (ip); +bhv_vnode_t *vp =VFS_I (ip);xfs_mount_t *mp = ip->i_mount;int error;
@@ -1218,7 +1218,7 @@ intxfs_inactive ( xfs_inode_t *ip) { -bhv_vnode_t *vp =XFS_ITOV (ip); +bhv_vnode_t *vp =VFS_I (ip);xfs_bmap_free_t free_list;xfs_fsblock_t first_block;int committed;
@@ -2864,7 +2864,7 @@ intxfs_reclaim ( xfs_inode_t *ip) { -bhv_vnode_t *vp =XFS_ITOV (ip); +bhv_vnode_t *vp =VFS_I (ip);xfs_itrace_entry (ip);
@@ -3326,7 +3326,7 @@ xfs_free_file_space(xfs_trans_t *tp;int need_iolock =1 ; - vp =XFS_ITOV (ip); + vp =VFS_I (ip); mp = ip->i_mount;xfs_itrace_entry (ip);
Signature · 1 line
1.5.6
Quoted 11 lines · Dave Chinner
Getting the VFS inode from the XFS inode is done in a variety of ways right now - direct deference or one of two
XFS_ITOVmacros. This should be consistent throughout the code - this patch series does that in a way that is consistent with the oppositeXFS_I()conversion. We now useVFS_I()to extract the VFS inode from the XFS inode.Version 2:
o don't usevn_to_inode()andinode_to_vn()functions as they are not needed
o rediff patches 2 and 3 against the change patch.
ACK for all three patches.
Ok, Pushed that in, put them into idbg and dmapi too.
Cheers,
Signature · 1 line
Niv Sardi