Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

GFS2: move function foreach_leaf to gfs2_dir_exhash_dealloc

The previous patches made function gfs2_dir_exhash_dealloc do nothing
but call function foreach_leaf. This patch simplifies the code by
moving the entire function foreach_leaf into gfs2_dir_exhash_dealloc.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

authored by

Bob Peterson and committed by
Steven Whitehouse
556bb179 ec038c82

+65 -81
+65 -81
fs/gfs2/dir.c
··· 85 85 typedef int (*gfs2_dscan_t)(const struct gfs2_dirent *dent, 86 86 const struct qstr *name, void *opaque); 87 87 88 - static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len, 89 - u64 leaf_no, struct buffer_head *leaf_bh, 90 - int last_dealloc); 91 - 92 88 int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block, 93 89 struct buffer_head **bhp) 94 90 { ··· 1765 1769 } 1766 1770 1767 1771 /** 1768 - * foreach_leaf - call a function for each leaf in a directory 1769 - * @dip: the directory 1770 - * 1771 - * Returns: errno 1772 - */ 1773 - 1774 - static int foreach_leaf(struct gfs2_inode *dip) 1775 - { 1776 - struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 1777 - struct buffer_head *bh; 1778 - struct gfs2_leaf *leaf; 1779 - u32 hsize, len; 1780 - u32 ht_offset, lp_offset, ht_offset_cur = -1; 1781 - u32 index = 0, next_index; 1782 - __be64 *lp; 1783 - u64 leaf_no; 1784 - int error = 0, last; 1785 - 1786 - hsize = 1 << dip->i_depth; 1787 - if (hsize * sizeof(u64) != i_size_read(&dip->i_inode)) { 1788 - gfs2_consist_inode(dip); 1789 - return -EIO; 1790 - } 1791 - 1792 - lp = kmalloc(sdp->sd_hash_bsize, GFP_NOFS); 1793 - if (!lp) 1794 - return -ENOMEM; 1795 - 1796 - while (index < hsize) { 1797 - lp_offset = index & (sdp->sd_hash_ptrs - 1); 1798 - ht_offset = index - lp_offset; 1799 - 1800 - if (ht_offset_cur != ht_offset) { 1801 - error = gfs2_dir_read_data(dip, (char *)lp, 1802 - ht_offset * sizeof(__be64), 1803 - sdp->sd_hash_bsize, 1); 1804 - if (error != sdp->sd_hash_bsize) { 1805 - if (error >= 0) 1806 - error = -EIO; 1807 - goto out; 1808 - } 1809 - ht_offset_cur = ht_offset; 1810 - } 1811 - 1812 - leaf_no = be64_to_cpu(lp[lp_offset]); 1813 - if (leaf_no) { 1814 - error = get_leaf(dip, leaf_no, &bh); 1815 - if (error) 1816 - goto out; 1817 - leaf = (struct gfs2_leaf *)bh->b_data; 1818 - len = 1 << (dip->i_depth - be16_to_cpu(leaf->lf_depth)); 1819 - next_index = (index & ~(len - 1)) + len; 1820 - last = ((next_index >= hsize) ? 1 : 0); 1821 - error = leaf_dealloc(dip, index, len, leaf_no, bh, 1822 - last); 1823 - brelse(bh); 1824 - if (error) 1825 - goto out; 1826 - index = next_index; 1827 - } else 1828 - index++; 1829 - } 1830 - 1831 - if (index != hsize) { 1832 - gfs2_consist_inode(dip); 1833 - error = -EIO; 1834 - } 1835 - 1836 - out: 1837 - kfree(lp); 1838 - 1839 - return error; 1840 - } 1841 - 1842 - /** 1843 1772 * leaf_dealloc - Deallocate a directory leaf 1844 1773 * @dip: the directory 1845 1774 * @index: the hash table offset in the directory ··· 1909 1988 1910 1989 int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip) 1911 1990 { 1912 - /* Dealloc on-disk leaves to FREEMETA state */ 1913 - return foreach_leaf(dip); 1991 + struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 1992 + struct buffer_head *bh; 1993 + struct gfs2_leaf *leaf; 1994 + u32 hsize, len; 1995 + u32 ht_offset, lp_offset, ht_offset_cur = -1; 1996 + u32 index = 0, next_index; 1997 + __be64 *lp; 1998 + u64 leaf_no; 1999 + int error = 0, last; 2000 + 2001 + hsize = 1 << dip->i_depth; 2002 + if (hsize * sizeof(u64) != i_size_read(&dip->i_inode)) { 2003 + gfs2_consist_inode(dip); 2004 + return -EIO; 2005 + } 2006 + 2007 + lp = kmalloc(sdp->sd_hash_bsize, GFP_NOFS); 2008 + if (!lp) 2009 + return -ENOMEM; 2010 + 2011 + while (index < hsize) { 2012 + lp_offset = index & (sdp->sd_hash_ptrs - 1); 2013 + ht_offset = index - lp_offset; 2014 + 2015 + if (ht_offset_cur != ht_offset) { 2016 + error = gfs2_dir_read_data(dip, (char *)lp, 2017 + ht_offset * sizeof(__be64), 2018 + sdp->sd_hash_bsize, 1); 2019 + if (error != sdp->sd_hash_bsize) { 2020 + if (error >= 0) 2021 + error = -EIO; 2022 + goto out; 2023 + } 2024 + ht_offset_cur = ht_offset; 2025 + } 2026 + 2027 + leaf_no = be64_to_cpu(lp[lp_offset]); 2028 + if (leaf_no) { 2029 + error = get_leaf(dip, leaf_no, &bh); 2030 + if (error) 2031 + goto out; 2032 + leaf = (struct gfs2_leaf *)bh->b_data; 2033 + len = 1 << (dip->i_depth - be16_to_cpu(leaf->lf_depth)); 2034 + 2035 + next_index = (index & ~(len - 1)) + len; 2036 + last = ((next_index >= hsize) ? 1 : 0); 2037 + error = leaf_dealloc(dip, index, len, leaf_no, bh, 2038 + last); 2039 + brelse(bh); 2040 + if (error) 2041 + goto out; 2042 + index = next_index; 2043 + } else 2044 + index++; 2045 + } 2046 + 2047 + if (index != hsize) { 2048 + gfs2_consist_inode(dip); 2049 + error = -EIO; 2050 + } 2051 + 2052 + out: 2053 + kfree(lp); 2054 + 2055 + return error; 1914 2056 } 1915 2057 1916 2058 /**