optimize inline symlink handling
Subsystems (2)
This series allows XFS to return a pointer to the inline symlink inside to the VFS instead of needing a kmalloc'ed copy.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 2/5 xfs: factor out a helper to initialize a local format inode fork
--- fs/xfs/libxfs/xfs_dir2_sf.c | 9 +++----- fs/xfs/libxfs/xfs_inode_fork.c | 48 ++++++++++++++++++++++++++---------------- fs/xfs/libxfs/xfs_inode_fork.h | 1 + fs/xfs/xfs_symlink.c | 12 ++--------- 4 files changed, 36 insertions(+), 34 deletions(-)
fs/xfs/libxfs/xfs_dir2_sf.c +3 -6
@@ -257,15 +257,12 @@ xfs_dir2_block_to_sf(* * Convert the inode to local format and copy the data in. */ - dp->i_df.if_flags &= ~XFS_IFEXTENTS ; - dp->i_df.if_flags |=XFS_IFINLINE ; - dp->i_d.di_format =XFS_DINODE_FMT_LOCAL ;ASSERT (dp->i_df.if_bytes ==0 ); -xfs_idata_realloc (dp, size,XFS_DATA_FORK ); +xfs_init_local_fork (dp,XFS_DATA_FORK , dst, size); + dp->i_d.di_format =XFS_DINODE_FMT_LOCAL ; + dp->i_d.di_size = size; logflags |=XFS_ILOG_DDATA ; -memcpy (dp->i_df.if_u1.if_data, dst, size); - dp->i_d.di_size = size;xfs_dir2_sf_check (args); out:xfs_trans_log_inode (args->trans, dp, logflags);
fs/xfs/libxfs/xfs_inode_fork.c +30 -18
66 lines not on this page · raw message
fs/xfs/libxfs/xfs_inode_fork.h +1 -0
@@ -135,6 +135,7 @@ 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 ); +void xfs_init_local_fork (struct xfs_inode *,int ,const void *,int );struct xfs_bmbt_rec_host *xfs_iext_get_ext (struct xfs_ifork *,xfs_extnum_t );
fs/xfs/xfs_symlink.c +2 -10
@@ -306,19 +306,11 @@ xfs_symlink(* If the symlink will fit into the inode, write it inline. */ if (pathlen <=XFS_IFORK_DSIZE (ip)) { -xfs_idata_realloc (ip, pathlen,XFS_DATA_FORK ); -memcpy (ip->i_df.if_u1.if_data, target_path, pathlen); - ip->i_d.di_size = pathlen; - -/* -* The inode was initially created in extent format. -*/ - ip->i_df.if_flags &= ~(XFS_IFEXTENTS |XFS_IFBROOT ); - ip->i_df.if_flags |=XFS_IFINLINE ; +xfs_init_local_fork (ip,XFS_DATA_FORK , target_path, pathlen); + ip->i_d.di_size = pathlen; ip->i_d.di_format =XFS_DINODE_FMT_LOCAL ;xfs_trans_log_inode (tp, ip,XFS_ILOG_DDATA |XFS_ILOG_CORE ); - }else {int offset;
Signature · 6 lines
1.9.1 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 3/5 xfs: set up inode operation vectors later
In reply to Christoph HellwigIn the next patch we'll set up different inode operations for inline vs out of line symlinks, for that we need to make sure the flags are already set up properly.
--- fs/xfs/xfs_inode.h | 5 ++++- fs/xfs/xfs_iops.c | 59 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 23 deletions(-)
fs/xfs/xfs_inode.h +4 -1
@@ -407,6 +407,9 @@ int xfs_iozero(struct xfs_inode *ip, loff_t pos, size_t count);/* from xfs_iops.c */ +extern void xfs_setup_inode (struct xfs_inode *ip); +extern void xfs_setup_iops (struct xfs_inode *ip); +/* * When setting up a newly allocated inode, we need to call * xfs_finish_inode_setup() once the inode is fully instantiated at
@@ -414,7 +417,6 @@ int xfs_iozero(struct xfs_inode *ip, loff_t pos, size_t count);* before we've completed instantiation. Otherwise we can do it * the moment the inode lookup is complete. */ -extern void xfs_setup_inode (struct xfs_inode *ip);static inline void xfs_finish_inode_setup (struct xfs_inode *ip) {xfs_iflags_clear (ip,XFS_INEW );
@@ -425,6 +427,7 @@ static inline void xfs_finish_inode_setup(struct xfs_inode *ip)static inline void xfs_setup_existing_inode (struct xfs_inode *ip) {xfs_setup_inode (ip); +xfs_setup_iops (ip);xfs_finish_inode_setup (ip); }
fs/xfs/xfs_iops.c +37 -22
98 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 4/5 xfs: use ->readlink to implement the readlink_by_handle ioctl
In reply to Christoph HellwigAlso drop the now unused readlink_copy export.
--- fs/namei.c | 1 - fs/xfs/xfs_ioctl.c | 19 ++----------------- 2 files changed, 2 insertions(+), 18 deletions(-)
fs/namei.c +0 -1
@@ -4420,7 +4420,6 @@ int readlink_copy(char __user *buffer, int buflen, const char *link) out:return len; } -EXPORT_SYMBOL (readlink_copy);/* * A helper for ->readlink(). This should be used *ONLY* for symlinks that
fs/xfs/xfs_ioctl.c +2 -17
@@ -276,7 +276,6 @@ xfs_readlink_by_handle( {struct dentry *dentry;__u32 olen; -void *link;int error;if (!capable (CAP_SYS_ADMIN ))
@@ -287,7 +286,7 @@ xfs_readlink_by_handle(return PTR_ERR (dentry);/* Restrict this handle operation to symlinks only. */ -if (!d_is_symlink (dentry)) { +if (!dentry->d_inode->i_op->readlink) { error = -EINVAL ; goto out_dput; }
@@ -297,21 +296,7 @@ xfs_readlink_by_handle( goto out_dput; } - link =kmalloc (MAXPATHLEN +1 ,GFP_KERNEL ); -if (!link) { - error = -ENOMEM ; - goto out_dput; - } - - error =xfs_readlink (XFS_I (dentry->d_inode), link); -if (error) - goto out_kfree; - error =readlink_copy (hreq->ohandle, olen, link); -if (error) - goto out_kfree; - - out_kfree: -kfree (link); + error = dentry->d_inode->i_op->readlink (dentry, hreq->ohandle, olen); out_dput:dput (dentry);return error;
Signature · 6 lines
1.9.1 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 5/5 xfs: optimize inline symlinks
In reply to Christoph HellwigBy overallocating the in-core inode fork data buffer and zero terminating the link target in xfs_init_local_fork we can avoid the memory allocation in ->follow_link.
--- fs/xfs/libxfs/xfs_dir2_sf.c | 2 +- fs/xfs/libxfs/xfs_inode_fork.c | 29 +++++++++++++++++++---------- fs/xfs/libxfs/xfs_inode_fork.h | 3 ++- fs/xfs/xfs_inode_item.c | 4 ++-- fs/xfs/xfs_iops.c | 28 +++++++++++++++++++++++++--- fs/xfs/xfs_symlink.c | 14 ++++++-------- 6 files changed, 55 insertions(+), 25 deletions(-)
fs/xfs/libxfs/xfs_dir2_sf.c +1 -1
@@ -258,7 +258,7 @@ xfs_dir2_block_to_sf(* Convert the inode to local format and copy the data in. */ ASSERT (dp->i_df.if_bytes ==0 ); -xfs_init_local_fork (dp,XFS_DATA_FORK , dst, size); +xfs_init_local_fork (dp,XFS_DATA_FORK , dst, size, false); dp->i_d.di_format =XFS_DINODE_FMT_LOCAL ; dp->i_d.di_size = size;
fs/xfs/libxfs/xfs_inode_fork.c +19 -10
@@ -235,22 +235,29 @@ xfs_init_local_fork(struct xfs_inode *ip, int whichfork, const void *data, - int size) + int size, + bool zero_terminate) { struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); -int real_size =0 ; +int mem_size = size, real_size =0 ; + +if (zero_terminate) + mem_size = size +1 ;if (size ==0 ) ifp->if_u1.if_data =NULL ; -else if (size <=sizeof (ifp->if_u2.if_inline_data)) +else if (mem_size <=sizeof (ifp->if_u2.if_inline_data)) ifp->if_u1.if_data = ifp->if_u2.if_inline_data;else { - real_size =roundup (size,4 ); + real_size =roundup (mem_size,4 ); ifp->if_u1.if_data =kmem_alloc (real_size,KM_SLEEP |KM_NOFS ); } -if (size) +if (size) {memcpy (ifp->if_u1.if_data, data, size); +if (zero_terminate) + ifp->if_u1.if_data[size] ='\0' ; + } ifp->if_bytes = size; ifp->if_real_bytes = real_size;
@@ -270,11 +277,12 @@ xfs_init_local_fork(*/ STATIC intxfs_iformat_local ( -xfs_inode_t *ip, -xfs_dinode_t *dip, -int whichfork, -int size) +struct xfs_inode *ip, +struct xfs_dinode *dip, +int whichfork, +int size) { +bool zero_terminate =S_ISDIR (dip->di_mode);/* * If the size is unreasonable, then something
@@ -291,7 +299,8 @@ xfs_iformat_local(return -EFSCORRUPTED ; } -xfs_init_local_fork (ip, whichfork,XFS_DFORK_PTR (dip, whichfork), size); +xfs_init_local_fork (ip, whichfork,XFS_DFORK_PTR (dip, whichfork), size, + zero_terminate);return 0 ; }
fs/xfs/libxfs/xfs_inode_fork.h +2 -1
@@ -135,7 +135,8 @@ 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 ); -void xfs_init_local_fork (struct xfs_inode *,int ,const void *,int ); +void xfs_init_local_fork (struct xfs_inode *,int ,const void *,int , +bool );struct xfs_bmbt_rec_host *xfs_iext_get_ext (struct xfs_ifork *,xfs_extnum_t );
fs/xfs/xfs_inode_item.c +2 -2
@@ -210,7 +210,7 @@ xfs_inode_item_format_data_fork(*/ data_bytes =roundup (ip->i_df.if_bytes,4 );ASSERT (ip->i_df.if_real_bytes ==0 || - ip->i_df.if_real_bytes == data_bytes); + ip->i_df.if_real_bytes >= data_bytes);ASSERT (ip->i_df.if_u1.if_data !=NULL );ASSERT (ip->i_d.di_size >0 ); xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_ILOCAL,
@@ -305,7 +305,7 @@ xfs_inode_item_format_attr_fork(*/ data_bytes =roundup (ip->i_afp->if_bytes,4 );ASSERT (ip->i_afp->if_real_bytes ==0 || - ip->i_afp->if_real_bytes == data_bytes); + ip->i_afp->if_real_bytes >= data_bytes);ASSERT (ip->i_afp->if_u1.if_data !=NULL ); xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_LOCAL, ip->i_afp->if_u1.if_data,
fs/xfs/xfs_iops.c +25 -3
@@ -444,6 +444,15 @@ xfs_vn_follow_link(return NULL ; } +STATIC void * +xfs_vn_follow_link_inline ( +struct dentry *dentry, +struct nameidata *nd) +{ +nd_set_link (nd,XFS_I (dentry->d_inode)->i_df.if_u1.if_data); +return NULL ; +} + STATIC int xfs_vn_getattr( struct vfsmount *mnt,
@@ -1190,6 +1199,18 @@ static const struct inode_operations xfs_symlink_inode_operations = { .update_time = xfs_vn_update_time, }; +static const struct inode_operations xfs_inline_symlink_inode_operations = { + .readlink = generic_readlink, + .follow_link = xfs_vn_follow_link_inline, + .getattr = xfs_vn_getattr, + .setattr = xfs_vn_setattr, + .setxattr = generic_setxattr, + .getxattr = generic_getxattr, + .removexattr = generic_removexattr, + .listxattr = xfs_vn_listxattr, + .update_time = xfs_vn_update_time, +}; + STATIC void xfs_diflags_to_iflags( struct inode *inode,
@@ -1308,9 +1329,10 @@ xfs_setup_iops( inode->i_fop = &xfs_dir_file_operations;break ;case S_IFLNK : - inode->i_op = &xfs_symlink_inode_operations; -if (!(ip->i_df.if_flags &XFS_IFINLINE )) - inode->i_mapping->a_ops = &xfs_address_space_operations; +if (ip->i_df.if_flags &XFS_IFINLINE ) + inode->i_op = &xfs_inline_symlink_inode_operations; +else + inode->i_op = &xfs_symlink_inode_operations;break ;default : inode->i_op = &xfs_inode_operations;
fs/xfs/xfs_symlink.c +6 -8
@@ -131,6 +131,8 @@ xfs_readlink(trace_xfs_readlink (ip); +ASSERT (!(ip->i_df.if_flags &XFS_IFINLINE )); +if (XFS_FORCED_SHUTDOWN (mp))return -EIO ;
@@ -150,12 +152,7 @@ xfs_readlink( } -if (ip->i_df.if_flags &XFS_IFINLINE ) { -memcpy (link, ip->i_df.if_u1.if_data, pathlen); - link[pathlen] ='\0' ; - }else { - error =xfs_readlink_bmap (ip, link); - } + error =xfs_readlink_bmap (ip, link); out:xfs_iunlock (ip,XFS_ILOCK_SHARED );
@@ -302,12 +299,13 @@ xfs_symlink(if (resblks) resblks -=XFS_IALLOC_SPACE_RES (mp); +/* * If the symlink will fit into the inode, write it inline. */ if (pathlen <=XFS_IFORK_DSIZE (ip)) { -xfs_init_local_fork (ip,XFS_DATA_FORK , target_path, pathlen); - +xfs_init_local_fork (ip,XFS_DATA_FORK , target_path, pathlen, + true); ip->i_d.di_size = pathlen; ip->i_d.di_format =XFS_DINODE_FMT_LOCAL ;xfs_trans_log_inode (tp, ip,XFS_ILOG_DDATA |XFS_ILOG_CORE );
Signature · 6 lines
1.9.1 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Al Viro
maintainerQuoted 2 lines · Christoph Hellwig
This series allows XFS to return a pointer to the inline symlink inside to the VFS instead of needing a kmalloc'ed copy.
Take a look at vfs.git#link_path_walk...
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs