aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/dir.c
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2014-01-06 07:49:43 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2014-01-06 07:49:43 -0500
commit2b47dad866d04f14c328f888ba5406057b8c7d33 (patch)
tree9eb66c086c2e49080234e0a9a1014624354ebea3 /fs/gfs2/dir.c
parent534cf9ca553953e4c12fa5f0d23e543f9a6ccbaf (diff)
GFS2: Remember directory insert point
When we look to see if there is enough space to add a dir entry without allocation, we have then been repeating the same search later when we do the actual insertion. This patch caches the details of the location in the gfs2_diradd structure, so that we do not have to repeat the search. This will provide a performance improvement which will be greater as the size of the directory increases. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs/gfs2/dir.c')
-rw-r--r--fs/gfs2/dir.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 0b6be202a82c..d5988aafaa74 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -1659,26 +1659,34 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1659 1659
1660/** 1660/**
1661 * gfs2_dir_add - Add new filename into directory 1661 * gfs2_dir_add - Add new filename into directory
1662 * @dip: The GFS2 inode 1662 * @inode: The directory inode
1663 * @filename: The new name 1663 * @name: The new name
1664 * @inode: The inode number of the entry 1664 * @nip: The GFS2 inode to be linked in to the directory
1665 * @type: The type of the entry 1665 * @da: The directory addition info
1666 *
1667 * If the call to gfs2_diradd_alloc_required resulted in there being
1668 * no need to allocate any new directory blocks, then it will contain
1669 * a pointer to the directory entry and the bh in which it resides. We
1670 * can use that without having to repeat the search. If there was no
1671 * free space, then we must now create more space.
1666 * 1672 *
1667 * Returns: 0 on success, error code on failure 1673 * Returns: 0 on success, error code on failure
1668 */ 1674 */
1669 1675
1670int gfs2_dir_add(struct inode *inode, const struct qstr *name, 1676int gfs2_dir_add(struct inode *inode, const struct qstr *name,
1671 const struct gfs2_inode *nip) 1677 const struct gfs2_inode *nip, struct gfs2_diradd *da)
1672{ 1678{
1673 struct gfs2_inode *ip = GFS2_I(inode); 1679 struct gfs2_inode *ip = GFS2_I(inode);
1674 struct buffer_head *bh; 1680 struct buffer_head *bh = da->bh;
1675 struct gfs2_dirent *dent; 1681 struct gfs2_dirent *dent = da->dent;
1676 struct gfs2_leaf *leaf; 1682 struct gfs2_leaf *leaf;
1677 int error; 1683 int error;
1678 1684
1679 while(1) { 1685 while(1) {
1680 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, 1686 if (da->bh == NULL) {
1681 &bh); 1687 dent = gfs2_dirent_search(inode, name,
1688 gfs2_dirent_find_space, &bh);
1689 }
1682 if (dent) { 1690 if (dent) {
1683 if (IS_ERR(dent)) 1691 if (IS_ERR(dent))
1684 return PTR_ERR(dent); 1692 return PTR_ERR(dent);
@@ -1689,6 +1697,8 @@ int gfs2_dir_add(struct inode *inode, const struct qstr *name,
1689 leaf = (struct gfs2_leaf *)bh->b_data; 1697 leaf = (struct gfs2_leaf *)bh->b_data;
1690 be16_add_cpu(&leaf->lf_entries, 1); 1698 be16_add_cpu(&leaf->lf_entries, 1);
1691 } 1699 }
1700 da->dent = NULL;
1701 da->bh = NULL;
1692 brelse(bh); 1702 brelse(bh);
1693 ip->i_entries++; 1703 ip->i_entries++;
1694 ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME; 1704 ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
@@ -2030,6 +2040,8 @@ int gfs2_diradd_alloc_required(struct inode *inode, const struct qstr *name,
2030 struct buffer_head *bh; 2040 struct buffer_head *bh;
2031 2041
2032 da->nr_blocks = 0; 2042 da->nr_blocks = 0;
2043 da->bh = NULL;
2044 da->dent = NULL;
2033 2045
2034 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh); 2046 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh);
2035 if (!dent) { 2047 if (!dent) {
@@ -2038,7 +2050,8 @@ int gfs2_diradd_alloc_required(struct inode *inode, const struct qstr *name,
2038 } 2050 }
2039 if (IS_ERR(dent)) 2051 if (IS_ERR(dent))
2040 return PTR_ERR(dent); 2052 return PTR_ERR(dent);
2041 brelse(bh); 2053 da->bh = bh;
2054 da->dent = dent;
2042 return 0; 2055 return 0;
2043} 2056}
2044 2057