use filldir internally
PATCH 1/1 use filldir internally
Currently xfs has a rather complicated internal scheme to allow for different directory formats in IRIX. This patch rips all code related to this out and pushes useage of the Linux filldir callback into the lowlevel directory code. This does not make the code any less portable because filldir can be used to create dirents of all possible variations (including the IRIX ones as proved by the IRIX binary emulation code under arch/mips/).
This patch get rid of an unessecary copy in the readdir path, about 400 lines of code and one of the last two users of the uio structure.
This version is updated to deal with dmapi aswell which greatly simplifies the get_dirattrs code. The dmapi part has been tested using the get_dirattrs tools from the xfstest dmapi suite1 with various small and large directories.
fs/xfs/linux-2.6/xfs_file.c +22 -67
@@ -258,74 +258,29 @@ xfs_file_readdir( void *dirent, filldir_t filldir) { - int error = 0; -bhv_vnode_t *vp =vn_from_inode (filp->f_path.dentry->d_inode); -uio_t uio; -iovec_t iov; -int eof =0 ; -caddr_t read_buf; -int namelen, size =0 ; -size_t rlen =PAGE_CACHE_SIZE ; -xfs_off_t start_offset, curr_offset; -xfs_dirent_t *dbp =NULL ; - -/* Try fairly hard to get memory */ -do { -if ((read_buf =kmalloc (rlen,GFP_KERNEL ))) -break ; - rlen >>=1 ; - }while (rlen >=1024 ); - -if (read_buf ==NULL ) -return -ENOMEM ; - - uio.uio_iov = &iov; - uio.uio_segflg =UIO_SYSSPACE ; - curr_offset = filp->f_pos; -if (filp->f_pos !=0x7fffffff ) - uio.uio_offset = filp->f_pos; -else - uio.uio_offset =0xffffffff ; - -while (!eof) { - uio.uio_resid = iov.iov_len = rlen; - iov.iov_base = read_buf; - uio.uio_iovcnt =1 ; - - start_offset = uio.uio_offset; - - error =bhv_vop_readdir (vp, &uio,NULL , &eof); -if ((uio.uio_offset == start_offset) || error) { - size =0 ; -break ; - } - - size = rlen - uio.uio_resid; - dbp = (xfs_dirent_t *)read_buf; -while (size >0 ) { - namelen =strlen (dbp->d_name); - -if (filldir (dirent, dbp->d_name, namelen, - (loff_t ) curr_offset &0x7fffffff , - (ino_t ) dbp->d_ino, -DT_UNKNOWN )) { - goto done; - } - size -= dbp->d_reclen; - curr_offset = (loff_t )dbp->d_off/* & 0x7fffffff */ ; - dbp = (xfs_dirent_t *)((char *)dbp + dbp->d_reclen); - } - } -done: -if (!error) { -if (size ==0 ) - filp->f_pos = uio.uio_offset &0x7fffffff ; -else if (dbp) - filp->f_pos = curr_offset; - } +struct inode *inode = filp->f_path.dentry->d_inode; +bhv_vnode_t *vp =vn_from_inode (inode); +int error; +size_t bufsize; + +/* +* The Linux API doesn't pass down the total size of the buffer +* we read into down to the filesystem. With the filldir concept +* it's not needed for correct information, but the XFS dir2 leaf +* code wants an estimate of the buffer size to calculate it's +* readahead window and size the buffers used for mapping to +* physical blocks. +* +* Try to give it an estimate that's good enough, maybe at some +* point we can change the ->readdir prototype to include the +* buffer size. +*/ + bufsize = (size_t )min_t (loff_t,PAGE_SIZE , inode->i_size); -kfree (read_buf); -return -error; + error =bhv_vop_readdir (vp, dirent, bufsize, &filp->f_pos, filldir); +if (error) +return -error; +return 0 ; }STATIC int
fs/xfs/linux-2.6/xfs_vnode.h +4 -4
@@ -164,8 +164,8 @@ typedef int (*vop_rename_t)(bhv_desc_t *typedef int (*vop_mkdir_t )(bhv_desc_t *,bhv_vname_t *,struct bhv_vattr *,bhv_vnode_t **,struct cred *);typedef int (*vop_rmdir_t )(bhv_desc_t *,bhv_vname_t *,struct cred *); -typedef int (*vop_readdir_t )(bhv_desc_t *,struct uio *,struct cred *, -int *); +typedef int (*vop_readdir_t )(bhv_desc_t *,void *dirent,size_t bufsize, +xfs_off_t *offset,filldir_t filldir);typedef int (*vop_symlink_t )(bhv_desc_t *,bhv_vname_t *,struct bhv_vattr *,char *,bhv_vnode_t **,struct cred *); typedef int (*vop_readlink_t)(bhv_desc_t *, struct uio *, int,
@@ -276,8 +276,8 @@ typedef struct bhv_vnodeops {#define bhv_vop_mkdir (dp,d,vap,vpp,cr) \ VOP(vop_mkdir, dp)(VNHEAD(dp),d,vap,vpp,cr)#define bhv_vop_rmdir (dp,d,cr) VOP(vop_rmdir, dp)(VNHEAD(dp),d,cr) -#define bhv_vop_readdir (vp,uiop,cr,eofp) \ - VOP(vop_readdir, vp)(VNHEAD(vp),uiop,cr,eofp) +#define bhv_vop_readdir (vp,dirent,bufsize,offset,filldir) \ + VOP(vop_readdir, vp)(VNHEAD(vp),dirent,bufsize,offset,filldir)#define bhv_vop_symlink (dvp,d,vap,tnm,vpp,cr) \ VOP(vop_symlink, dvp)(VNHEAD(dvp),d,vap,tnm,vpp,cr)#define bhv_vop_readlink (vp,uiop,fl,cr) \
fs/xfs/xfs_vnodeops.c +0 -31
@@ -3286,37 +3286,6 @@ xfs_rmdir( goto std_return; } - -/* -* Read dp's entries starting at uiop->uio_offset and translate them into -* bufsize bytes worth of struct dirents starting at bufbase. -*/ -STATIC int -xfs_readdir ( -bhv_desc_t *dir_bdp, -uio_t *uiop, -cred_t *credp, -int *eofp) -{ -xfs_inode_t *dp; -xfs_trans_t *tp =NULL ; -int error =0 ; -uint lock_mode; - -vn_trace_entry (BHV_TO_VNODE (dir_bdp), __FUNCTION__, - (inst_t *)__return_address); - dp =XFS_BHVTOI (dir_bdp); - -if (XFS_FORCED_SHUTDOWN (dp->i_mount)) -return XFS_ERROR (EIO ); - - lock_mode =xfs_ilock_map_shared (dp); - error =xfs_dir_getdents (tp, dp, uiop, eofp); -xfs_iunlock_map_shared (dp, lock_mode); -return error; -} - - STATIC int xfs_symlink( bhv_desc_t *dir_bdp,
fs/xfs/xfs_dir2.c +18 -103
150 lines not on this page · raw message
fs/xfs/xfs_dir2.h +2 -17
@@ -60,21 +60,6 @@ typedef __uint32_t xfs_dir2_db_t;typedef xfs_off_t xfs_dir2_off_t ;/* -* For getdents, argument struct for put routines. -*/ -typedef int (*xfs_dir2_put_t )(struct xfs_dir2_put_args *pa); -typedef struct xfs_dir2_put_args { -xfs_off_t cook;/* cookie of (next) entry */ -xfs_intino_t ino;/* inode number */ -xfs_dirent_t *dbp;/* buffer pointer */ -char *name;/* directory entry name */ -int namelen;/* length of name */ -int done;/* output: set if value was stored */ -xfs_dir2_put_t put;/* put function ptr (i/o) */ -struct uio *uio;/* uio control structure */ -}xfs_dir2_put_args_t ; - -/* * Generic directory interface routines */ extern void xfs_dir_startup (void );
@@ -92,8 +77,6 @@ extern int xfs_dir_removename(struct xfs char *name, int namelen, xfs_ino_t ino, xfs_fsblock_t *first, struct xfs_bmap_free *flist, xfs_extlen_t tot); -extern int xfs_dir_getdents (struct xfs_trans *tp,struct xfs_inode *dp, -uio_t *uio,int *eofp); extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, char *name, int namelen, xfs_ino_t inum, xfs_fsblock_t *first,
@@ -101,6 +84,8 @@ extern int xfs_dir_replace(struct xfs_trextern int xfs_dir_canenter (struct xfs_trans *tp,struct xfs_inode *dp,char *name,int namelen);extern int xfs_dir_ino_validate (struct xfs_mount *mp,xfs_ino_t ino); +extern int xfs_readdir (bhv_desc_t *dir_bdp,void *dirent,size_t bufsize, +xfs_off_t *offset,filldir_t filldir);/* * Utility routines for v2 directories.
fs/xfs/xfs_dir2_block.c +23 -40
121 lines not on this page · raw message
fs/xfs/xfs_dir2_block.h +2 -3
@@ -80,9 +80,8 @@ xfs_dir2_block_leaf_p(xfs_dir2_block_tai* Function declarations. */ extern int xfs_dir2_block_addname (struct xfs_da_args *args); -extern int xfs_dir2_block_getdents (struct xfs_trans *tp,struct xfs_inode *dp, -struct uio *uio,int *eofp, -struct xfs_dirent *dbp,xfs_dir2_put_t put); +extern int xfs_dir2_block_getdents (struct xfs_inode *dp,void *dirent, +xfs_off_t *offset,filldir_t filldir);extern int xfs_dir2_block_lookup (struct xfs_da_args *args);extern int xfs_dir2_block_removename (struct xfs_da_args *args);extern int xfs_dir2_block_replace (struct xfs_da_args *args);
fs/xfs/xfs_dir2_leaf.c +30 -46
177 lines not on this page · raw message
fs/xfs/xfs_dir2_leaf.h +3 -3
@@ -232,9 +232,9 @@ extern void xfs_dir2_leaf_compact(structextern void xfs_dir2_leaf_compact_x1 (struct xfs_dabuf *bp,int *indexp,int *lowstalep,int *highstalep,int *lowlogp,int *highlogp); -extern int xfs_dir2_leaf_getdents (struct xfs_trans *tp,struct xfs_inode *dp, -struct uio *uio,int *eofp, -struct xfs_dirent *dbp,xfs_dir2_put_t put); +extern int xfs_dir2_leaf_getdents (struct xfs_inode *dp,void *dirent, +size_t bufsize,xfs_off_t *offset, +filldir_t filldir);extern int xfs_dir2_leaf_init (struct xfs_da_args *args,xfs_dir2_db_t bno,struct xfs_dabuf **bpp,int magic); extern void xfs_dir2_leaf_log_ents(struct xfs_trans *tp, struct xfs_dabuf *bp,
fs/xfs/xfs_dir2_sf.c +45 -78
180 lines not on this page · raw message
fs/xfs/xfs_dir2_sf.h +2 -3
@@ -169,9 +169,8 @@ extern int xfs_dir2_block_to_sf(struct x int size, xfs_dir2_sf_hdr_t *sfhp);extern int xfs_dir2_sf_addname (struct xfs_da_args *args);extern int xfs_dir2_sf_create (struct xfs_da_args *args,xfs_ino_t pino); -extern int xfs_dir2_sf_getdents (struct xfs_inode *dp,struct uio *uio, -int *eofp,struct xfs_dirent *dbp, -xfs_dir2_put_t put); +extern int xfs_dir2_sf_getdents (struct xfs_inode *dp,void *dirent, +xfs_off_t *offset,filldir_t filldir);extern int xfs_dir2_sf_lookup (struct xfs_da_args *args);extern int xfs_dir2_sf_removename (struct xfs_da_args *args);extern int xfs_dir2_sf_replace (struct xfs_da_args *args);
fs/xfs/dmapi/xfs_dm.c +138 -285
474 lines not on this page · raw message
fs/xfs/linux-2.6/xfs_ksyms.c +0 -1
@@ -239,7 +239,6 @@ EXPORT_SYMBOL(xfs_bwrite);EXPORT_SYMBOL (xfs_change_file_space);EXPORT_SYMBOL (xfs_chashlist_zone);EXPORT_SYMBOL (xfs_dev_is_read_only); -EXPORT_SYMBOL (xfs_dir_getdents);EXPORT_SYMBOL (xfs_dir_ialloc);EXPORT_SYMBOL (xfs_error_report);#ifdef DEBUG
fs/xfs/xfs_types.h +0 -12
@@ -151,18 +151,6 @@ typedef __uint8_t xfs_arch_t; /* archite*/ #define MAXNAMELEN 256 -typedef struct xfs_dirent {/* data from readdir() */ -xfs_ino_t d_ino;/* inode number of entry */ -xfs_off_t d_off;/* offset of disk directory entry */ -unsigned short d_reclen;/* length of this record */ -char d_name[1 ];/* name of file */ -}xfs_dirent_t ; - -#define DIRENTBASESIZE (((xfs_dirent_t *)0)->d_name - (char *)0) -#define DIRENTSIZE (namelen) \ - ((DIRENTBASESIZE + (namelen) + \ - sizeof(xfs_off_t)) & ~(sizeof(xfs_off_t) - 1)) -typedef enum { XFS_LOOKUP_EQi, XFS_LOOKUP_LEi, XFS_LOOKUP_GEi }xfs_lookup_t ;