aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-01-21 20:42:00 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-21 20:42:00 -0500
commit2182c815f3d430598e172c1c3ac88df775ea120e (patch)
tree95c55693e2ca1b71ba5365f3e7d24c324f3b07c5
parent03d11a0e458d7008192585124e4c3313c2829046 (diff)
parentd57b9c9a999a8f4475fe73fba629c964245800ca (diff)
Merge tag 'gfs2-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw
Pull GFS2 updates from Steven Whitehouse: "The main topics this time are allocation, in the form of Bob's improvements when searching resource groups and several updates to quotas which should increase scalability. The quota changes follow on from those in the last merge window, and there will likely be further work to come in this area in due course. There are also a few patches which help to improve efficiency of adding entries into directories, and clean up some of that code. One on-disk change is included this time, which is to write some additional information which should be useful to fsck and also potentially for debugging. Other than that, its just a few small random bug fixes and clean ups" * tag 'gfs2-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw: (24 commits) GFS2: revert "GFS2: d_splice_alias() can't return error" GFS2: Small cleanup GFS2: Don't use ENOBUFS when ENOMEM is the correct error code GFS2: Fix kbuild test robot reported warning GFS2: Move quota bitmap operations under their own lock GFS2: Clean up quota slot allocation GFS2: Only run logd and quota when mounted read/write GFS2: Use RCU/hlist_bl based hash for quotas GFS2: No need to invalidate pages for a dio read GFS2: Add initialization for address space in super block GFS2: Add hints to directory leaf blocks GFS2: For exhash conversion, only one block is needed GFS2: Increase i_writecount during gfs2_setattr_chown GFS2: Remember directory insert point GFS2: Consolidate transaction blocks calculation for dir add GFS2: Add directory addition info structure GFS2: Use only a single address space for rgrps GFS2: Use range based functions for rgrp sync/invalidation GFS2: Remove test which is always true GFS2: Remove gfs2_quota_change_host structure ...
-rw-r--r--fs/gfs2/aops.c23
-rw-r--r--fs/gfs2/dir.c90
-rw-r--r--fs/gfs2/dir.h19
-rw-r--r--fs/gfs2/glock.c29
-rw-r--r--fs/gfs2/glock.h2
-rw-r--r--fs/gfs2/glops.c26
-rw-r--r--fs/gfs2/incore.h23
-rw-r--r--fs/gfs2/inode.c118
-rw-r--r--fs/gfs2/lops.c5
-rw-r--r--fs/gfs2/main.c1
-rw-r--r--fs/gfs2/meta_io.c3
-rw-r--r--fs/gfs2/ops_fstype.c58
-rw-r--r--fs/gfs2/quota.c342
-rw-r--r--fs/gfs2/quota.h1
-rw-r--r--fs/gfs2/rgrp.c113
-rw-r--r--fs/gfs2/rgrp.h2
-rw-r--r--fs/gfs2/super.c43
-rw-r--r--include/uapi/linux/gfs2_ondisk.h11
18 files changed, 550 insertions, 359 deletions
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c
index 73f3e4ee4037..49436fa7cd4f 100644
--- a/fs/gfs2/aops.c
+++ b/fs/gfs2/aops.c
@@ -1032,8 +1032,9 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb,
1032 unmap_shared_mapping_range(ip->i_inode.i_mapping, offset, len); 1032 unmap_shared_mapping_range(ip->i_inode.i_mapping, offset, len);
1033 rv = filemap_write_and_wait_range(mapping, lstart, end); 1033 rv = filemap_write_and_wait_range(mapping, lstart, end);
1034 if (rv) 1034 if (rv)
1035 return rv; 1035 goto out;
1036 truncate_inode_pages_range(mapping, lstart, end); 1036 if (rw == WRITE)
1037 truncate_inode_pages_range(mapping, lstart, end);
1037 } 1038 }
1038 1039
1039 rv = __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, 1040 rv = __blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
@@ -1080,30 +1081,22 @@ int gfs2_releasepage(struct page *page, gfp_t gfp_mask)
1080 bh = bh->b_this_page; 1081 bh = bh->b_this_page;
1081 } while(bh != head); 1082 } while(bh != head);
1082 spin_unlock(&sdp->sd_ail_lock); 1083 spin_unlock(&sdp->sd_ail_lock);
1083 gfs2_log_unlock(sdp);
1084 1084
1085 head = bh = page_buffers(page); 1085 head = bh = page_buffers(page);
1086 do { 1086 do {
1087 gfs2_log_lock(sdp);
1088 bd = bh->b_private; 1087 bd = bh->b_private;
1089 if (bd) { 1088 if (bd) {
1090 gfs2_assert_warn(sdp, bd->bd_bh == bh); 1089 gfs2_assert_warn(sdp, bd->bd_bh == bh);
1091 if (!list_empty(&bd->bd_list)) { 1090 if (!list_empty(&bd->bd_list))
1092 if (!buffer_pinned(bh)) 1091 list_del_init(&bd->bd_list);
1093 list_del_init(&bd->bd_list); 1092 bd->bd_bh = NULL;
1094 else
1095 bd = NULL;
1096 }
1097 if (bd)
1098 bd->bd_bh = NULL;
1099 bh->b_private = NULL; 1093 bh->b_private = NULL;
1100 }
1101 gfs2_log_unlock(sdp);
1102 if (bd)
1103 kmem_cache_free(gfs2_bufdata_cachep, bd); 1094 kmem_cache_free(gfs2_bufdata_cachep, bd);
1095 }
1104 1096
1105 bh = bh->b_this_page; 1097 bh = bh->b_this_page;
1106 } while (bh != head); 1098 } while (bh != head);
1099 gfs2_log_unlock(sdp);
1107 1100
1108 return try_to_free_buffers(page); 1101 return try_to_free_buffers(page);
1109 1102
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 2e5fc268d324..fa32655449c8 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -834,6 +834,7 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
834 struct gfs2_leaf *leaf; 834 struct gfs2_leaf *leaf;
835 struct gfs2_dirent *dent; 835 struct gfs2_dirent *dent;
836 struct qstr name = { .name = "" }; 836 struct qstr name = { .name = "" };
837 struct timespec tv = CURRENT_TIME;
837 838
838 error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL); 839 error = gfs2_alloc_blocks(ip, &bn, &n, 0, NULL);
839 if (error) 840 if (error)
@@ -850,7 +851,11 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
850 leaf->lf_entries = 0; 851 leaf->lf_entries = 0;
851 leaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE); 852 leaf->lf_dirent_format = cpu_to_be32(GFS2_FORMAT_DE);
852 leaf->lf_next = 0; 853 leaf->lf_next = 0;
853 memset(leaf->lf_reserved, 0, sizeof(leaf->lf_reserved)); 854 leaf->lf_inode = cpu_to_be64(ip->i_no_addr);
855 leaf->lf_dist = cpu_to_be32(1);
856 leaf->lf_nsec = cpu_to_be32(tv.tv_nsec);
857 leaf->lf_sec = cpu_to_be64(tv.tv_sec);
858 memset(leaf->lf_reserved2, 0, sizeof(leaf->lf_reserved2));
854 dent = (struct gfs2_dirent *)(leaf+1); 859 dent = (struct gfs2_dirent *)(leaf+1);
855 gfs2_qstr2dirent(&name, bh->b_size - sizeof(struct gfs2_leaf), dent); 860 gfs2_qstr2dirent(&name, bh->b_size - sizeof(struct gfs2_leaf), dent);
856 *pbh = bh; 861 *pbh = bh;
@@ -1612,11 +1617,31 @@ out:
1612 return ret; 1617 return ret;
1613} 1618}
1614 1619
1620/**
1621 * dir_new_leaf - Add a new leaf onto hash chain
1622 * @inode: The directory
1623 * @name: The name we are adding
1624 *
1625 * This adds a new dir leaf onto an existing leaf when there is not
1626 * enough space to add a new dir entry. This is a last resort after
1627 * we've expanded the hash table to max size and also split existing
1628 * leaf blocks, so it will only occur for very large directories.
1629 *
1630 * The dist parameter is set to 1 for leaf blocks directly attached
1631 * to the hash table, 2 for one layer of indirection, 3 for two layers
1632 * etc. We are thus able to tell the difference between an old leaf
1633 * with dist set to zero (i.e. "don't know") and a new one where we
1634 * set this information for debug/fsck purposes.
1635 *
1636 * Returns: 0 on success, or -ve on error
1637 */
1638
1615static int dir_new_leaf(struct inode *inode, const struct qstr *name) 1639static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1616{ 1640{
1617 struct buffer_head *bh, *obh; 1641 struct buffer_head *bh, *obh;
1618 struct gfs2_inode *ip = GFS2_I(inode); 1642 struct gfs2_inode *ip = GFS2_I(inode);
1619 struct gfs2_leaf *leaf, *oleaf; 1643 struct gfs2_leaf *leaf, *oleaf;
1644 u32 dist = 1;
1620 int error; 1645 int error;
1621 u32 index; 1646 u32 index;
1622 u64 bn; 1647 u64 bn;
@@ -1626,6 +1651,7 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1626 if (error) 1651 if (error)
1627 return error; 1652 return error;
1628 do { 1653 do {
1654 dist++;
1629 oleaf = (struct gfs2_leaf *)obh->b_data; 1655 oleaf = (struct gfs2_leaf *)obh->b_data;
1630 bn = be64_to_cpu(oleaf->lf_next); 1656 bn = be64_to_cpu(oleaf->lf_next);
1631 if (!bn) 1657 if (!bn)
@@ -1643,6 +1669,7 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1643 brelse(obh); 1669 brelse(obh);
1644 return -ENOSPC; 1670 return -ENOSPC;
1645 } 1671 }
1672 leaf->lf_dist = cpu_to_be32(dist);
1646 oleaf->lf_next = cpu_to_be64(bh->b_blocknr); 1673 oleaf->lf_next = cpu_to_be64(bh->b_blocknr);
1647 brelse(bh); 1674 brelse(bh);
1648 brelse(obh); 1675 brelse(obh);
@@ -1659,39 +1686,53 @@ static int dir_new_leaf(struct inode *inode, const struct qstr *name)
1659 1686
1660/** 1687/**
1661 * gfs2_dir_add - Add new filename into directory 1688 * gfs2_dir_add - Add new filename into directory
1662 * @dip: The GFS2 inode 1689 * @inode: The directory inode
1663 * @filename: The new name 1690 * @name: The new name
1664 * @inode: The inode number of the entry 1691 * @nip: The GFS2 inode to be linked in to the directory
1665 * @type: The type of the entry 1692 * @da: The directory addition info
1693 *
1694 * If the call to gfs2_diradd_alloc_required resulted in there being
1695 * no need to allocate any new directory blocks, then it will contain
1696 * a pointer to the directory entry and the bh in which it resides. We
1697 * can use that without having to repeat the search. If there was no
1698 * free space, then we must now create more space.
1666 * 1699 *
1667 * Returns: 0 on success, error code on failure 1700 * Returns: 0 on success, error code on failure
1668 */ 1701 */
1669 1702
1670int gfs2_dir_add(struct inode *inode, const struct qstr *name, 1703int gfs2_dir_add(struct inode *inode, const struct qstr *name,
1671 const struct gfs2_inode *nip) 1704 const struct gfs2_inode *nip, struct gfs2_diradd *da)
1672{ 1705{
1673 struct gfs2_inode *ip = GFS2_I(inode); 1706 struct gfs2_inode *ip = GFS2_I(inode);
1674 struct buffer_head *bh; 1707 struct buffer_head *bh = da->bh;
1675 struct gfs2_dirent *dent; 1708 struct gfs2_dirent *dent = da->dent;
1709 struct timespec tv;
1676 struct gfs2_leaf *leaf; 1710 struct gfs2_leaf *leaf;
1677 int error; 1711 int error;
1678 1712
1679 while(1) { 1713 while(1) {
1680 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, 1714 if (da->bh == NULL) {
1681 &bh); 1715 dent = gfs2_dirent_search(inode, name,
1716 gfs2_dirent_find_space, &bh);
1717 }
1682 if (dent) { 1718 if (dent) {
1683 if (IS_ERR(dent)) 1719 if (IS_ERR(dent))
1684 return PTR_ERR(dent); 1720 return PTR_ERR(dent);
1685 dent = gfs2_init_dirent(inode, dent, name, bh); 1721 dent = gfs2_init_dirent(inode, dent, name, bh);
1686 gfs2_inum_out(nip, dent); 1722 gfs2_inum_out(nip, dent);
1687 dent->de_type = cpu_to_be16(IF2DT(nip->i_inode.i_mode)); 1723 dent->de_type = cpu_to_be16(IF2DT(nip->i_inode.i_mode));
1724 tv = CURRENT_TIME;
1688 if (ip->i_diskflags & GFS2_DIF_EXHASH) { 1725 if (ip->i_diskflags & GFS2_DIF_EXHASH) {
1689 leaf = (struct gfs2_leaf *)bh->b_data; 1726 leaf = (struct gfs2_leaf *)bh->b_data;
1690 be16_add_cpu(&leaf->lf_entries, 1); 1727 be16_add_cpu(&leaf->lf_entries, 1);
1728 leaf->lf_nsec = cpu_to_be32(tv.tv_nsec);
1729 leaf->lf_sec = cpu_to_be64(tv.tv_sec);
1691 } 1730 }
1731 da->dent = NULL;
1732 da->bh = NULL;
1692 brelse(bh); 1733 brelse(bh);
1693 ip->i_entries++; 1734 ip->i_entries++;
1694 ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME; 1735 ip->i_inode.i_mtime = ip->i_inode.i_ctime = tv;
1695 if (S_ISDIR(nip->i_inode.i_mode)) 1736 if (S_ISDIR(nip->i_inode.i_mode))
1696 inc_nlink(&ip->i_inode); 1737 inc_nlink(&ip->i_inode);
1697 mark_inode_dirty(inode); 1738 mark_inode_dirty(inode);
@@ -1742,6 +1783,7 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry)
1742 const struct qstr *name = &dentry->d_name; 1783 const struct qstr *name = &dentry->d_name;
1743 struct gfs2_dirent *dent, *prev = NULL; 1784 struct gfs2_dirent *dent, *prev = NULL;
1744 struct buffer_head *bh; 1785 struct buffer_head *bh;
1786 struct timespec tv = CURRENT_TIME;
1745 1787
1746 /* Returns _either_ the entry (if its first in block) or the 1788 /* Returns _either_ the entry (if its first in block) or the
1747 previous entry otherwise */ 1789 previous entry otherwise */
@@ -1767,13 +1809,15 @@ int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry)
1767 if (!entries) 1809 if (!entries)
1768 gfs2_consist_inode(dip); 1810 gfs2_consist_inode(dip);
1769 leaf->lf_entries = cpu_to_be16(--entries); 1811 leaf->lf_entries = cpu_to_be16(--entries);
1812 leaf->lf_nsec = cpu_to_be32(tv.tv_nsec);
1813 leaf->lf_sec = cpu_to_be64(tv.tv_sec);
1770 } 1814 }
1771 brelse(bh); 1815 brelse(bh);
1772 1816
1773 if (!dip->i_entries) 1817 if (!dip->i_entries)
1774 gfs2_consist_inode(dip); 1818 gfs2_consist_inode(dip);
1775 dip->i_entries--; 1819 dip->i_entries--;
1776 dip->i_inode.i_mtime = dip->i_inode.i_ctime = CURRENT_TIME; 1820 dip->i_inode.i_mtime = dip->i_inode.i_ctime = tv;
1777 if (S_ISDIR(dentry->d_inode->i_mode)) 1821 if (S_ISDIR(dentry->d_inode->i_mode))
1778 drop_nlink(&dip->i_inode); 1822 drop_nlink(&dip->i_inode);
1779 mark_inode_dirty(&dip->i_inode); 1823 mark_inode_dirty(&dip->i_inode);
@@ -2017,22 +2061,36 @@ out:
2017 * gfs2_diradd_alloc_required - find if adding entry will require an allocation 2061 * gfs2_diradd_alloc_required - find if adding entry will require an allocation
2018 * @ip: the file being written to 2062 * @ip: the file being written to
2019 * @filname: the filename that's going to be added 2063 * @filname: the filename that's going to be added
2064 * @da: The structure to return dir alloc info
2020 * 2065 *
2021 * Returns: 1 if alloc required, 0 if not, -ve on error 2066 * Returns: 0 if ok, -ve on error
2022 */ 2067 */
2023 2068
2024int gfs2_diradd_alloc_required(struct inode *inode, const struct qstr *name) 2069int gfs2_diradd_alloc_required(struct inode *inode, const struct qstr *name,
2070 struct gfs2_diradd *da)
2025{ 2071{
2072 struct gfs2_inode *ip = GFS2_I(inode);
2073 struct gfs2_sbd *sdp = GFS2_SB(inode);
2074 const unsigned int extra = sizeof(struct gfs2_dinode) - sizeof(struct gfs2_leaf);
2026 struct gfs2_dirent *dent; 2075 struct gfs2_dirent *dent;
2027 struct buffer_head *bh; 2076 struct buffer_head *bh;
2028 2077
2078 da->nr_blocks = 0;
2079 da->bh = NULL;
2080 da->dent = NULL;
2081
2029 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh); 2082 dent = gfs2_dirent_search(inode, name, gfs2_dirent_find_space, &bh);
2030 if (!dent) { 2083 if (!dent) {
2031 return 1; 2084 da->nr_blocks = sdp->sd_max_dirres;
2085 if (!(ip->i_diskflags & GFS2_DIF_EXHASH) &&
2086 (GFS2_DIRENT_SIZE(name->len) < extra))
2087 da->nr_blocks = 1;
2088 return 0;
2032 } 2089 }
2033 if (IS_ERR(dent)) 2090 if (IS_ERR(dent))
2034 return PTR_ERR(dent); 2091 return PTR_ERR(dent);
2035 brelse(bh); 2092 da->bh = bh;
2093 da->dent = dent;
2036 return 0; 2094 return 0;
2037} 2095}
2038 2096
diff --git a/fs/gfs2/dir.h b/fs/gfs2/dir.h
index 4f03bbd1873f..126c65dda028 100644
--- a/fs/gfs2/dir.h
+++ b/fs/gfs2/dir.h
@@ -16,6 +16,14 @@
16struct inode; 16struct inode;
17struct gfs2_inode; 17struct gfs2_inode;
18struct gfs2_inum; 18struct gfs2_inum;
19struct buffer_head;
20struct gfs2_dirent;
21
22struct gfs2_diradd {
23 unsigned nr_blocks;
24 struct gfs2_dirent *dent;
25 struct buffer_head *bh;
26};
19 27
20extern struct inode *gfs2_dir_search(struct inode *dir, 28extern struct inode *gfs2_dir_search(struct inode *dir,
21 const struct qstr *filename, 29 const struct qstr *filename,
@@ -23,7 +31,13 @@ extern struct inode *gfs2_dir_search(struct inode *dir,
23extern int gfs2_dir_check(struct inode *dir, const struct qstr *filename, 31extern int gfs2_dir_check(struct inode *dir, const struct qstr *filename,
24 const struct gfs2_inode *ip); 32 const struct gfs2_inode *ip);
25extern int gfs2_dir_add(struct inode *inode, const struct qstr *filename, 33extern int gfs2_dir_add(struct inode *inode, const struct qstr *filename,
26 const struct gfs2_inode *ip); 34 const struct gfs2_inode *ip, struct gfs2_diradd *da);
35static inline void gfs2_dir_no_add(struct gfs2_diradd *da)
36{
37 if (da->bh)
38 brelse(da->bh);
39 da->bh = NULL;
40}
27extern int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry); 41extern int gfs2_dir_del(struct gfs2_inode *dip, const struct dentry *dentry);
28extern int gfs2_dir_read(struct inode *inode, struct dir_context *ctx, 42extern int gfs2_dir_read(struct inode *inode, struct dir_context *ctx,
29 struct file_ra_state *f_ra); 43 struct file_ra_state *f_ra);
@@ -33,7 +47,8 @@ extern int gfs2_dir_mvino(struct gfs2_inode *dip, const struct qstr *filename,
33extern int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip); 47extern int gfs2_dir_exhash_dealloc(struct gfs2_inode *dip);
34 48
35extern int gfs2_diradd_alloc_required(struct inode *dir, 49extern int gfs2_diradd_alloc_required(struct inode *dir,
36 const struct qstr *filename); 50 const struct qstr *filename,
51 struct gfs2_diradd *da);
37extern int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block, 52extern int gfs2_dir_get_new_buffer(struct gfs2_inode *ip, u64 block,
38 struct buffer_head **bhp); 53 struct buffer_head **bhp);
39extern void gfs2_dir_hash_inval(struct gfs2_inode *ip); 54extern void gfs2_dir_hash_inval(struct gfs2_inode *ip);
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 6f7a47c05259..ca0be6c69a26 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1552,13 +1552,11 @@ void gfs2_glock_thaw(struct gfs2_sbd *sdp)
1552 glock_hash_walk(thaw_glock, sdp); 1552 glock_hash_walk(thaw_glock, sdp);
1553} 1553}
1554 1554
1555static int dump_glock(struct seq_file *seq, struct gfs2_glock *gl) 1555static void dump_glock(struct seq_file *seq, struct gfs2_glock *gl)
1556{ 1556{
1557 int ret;
1558 spin_lock(&gl->gl_spin); 1557 spin_lock(&gl->gl_spin);
1559 ret = gfs2_dump_glock(seq, gl); 1558 gfs2_dump_glock(seq, gl);
1560 spin_unlock(&gl->gl_spin); 1559 spin_unlock(&gl->gl_spin);
1561 return ret;
1562} 1560}
1563 1561
1564static void dump_glock_func(struct gfs2_glock *gl) 1562static void dump_glock_func(struct gfs2_glock *gl)
@@ -1647,10 +1645,9 @@ static const char *hflags2str(char *buf, unsigned flags, unsigned long iflags)
1647 * @seq: the seq_file struct 1645 * @seq: the seq_file struct
1648 * @gh: the glock holder 1646 * @gh: the glock holder
1649 * 1647 *
1650 * Returns: 0 on success, -ENOBUFS when we run out of space
1651 */ 1648 */
1652 1649
1653static int dump_holder(struct seq_file *seq, const struct gfs2_holder *gh) 1650static void dump_holder(struct seq_file *seq, const struct gfs2_holder *gh)
1654{ 1651{
1655 struct task_struct *gh_owner = NULL; 1652 struct task_struct *gh_owner = NULL;
1656 char flags_buf[32]; 1653 char flags_buf[32];
@@ -1666,7 +1663,6 @@ static int dump_holder(struct seq_file *seq, const struct gfs2_holder *gh)
1666 gh_owner ? gh_owner->comm : "(ended)", 1663 gh_owner ? gh_owner->comm : "(ended)",
1667 (void *)gh->gh_ip); 1664 (void *)gh->gh_ip);
1668 rcu_read_unlock(); 1665 rcu_read_unlock();
1669 return 0;
1670} 1666}
1671 1667
1672static const char *gflags2str(char *buf, const struct gfs2_glock *gl) 1668static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
@@ -1721,16 +1717,14 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
1721 * example. The field's are n = number (id of the object), f = flags, 1717 * example. The field's are n = number (id of the object), f = flags,
1722 * t = type, s = state, r = refcount, e = error, p = pid. 1718 * t = type, s = state, r = refcount, e = error, p = pid.
1723 * 1719 *
1724 * Returns: 0 on success, -ENOBUFS when we run out of space
1725 */ 1720 */
1726 1721
1727int gfs2_dump_glock(struct seq_file *seq, const struct gfs2_glock *gl) 1722void gfs2_dump_glock(struct seq_file *seq, const struct gfs2_glock *gl)
1728{ 1723{
1729 const struct gfs2_glock_operations *glops = gl->gl_ops; 1724 const struct gfs2_glock_operations *glops = gl->gl_ops;
1730 unsigned long long dtime; 1725 unsigned long long dtime;
1731 const struct gfs2_holder *gh; 1726 const struct gfs2_holder *gh;
1732 char gflags_buf[32]; 1727 char gflags_buf[32];
1733 int error = 0;
1734 1728
1735 dtime = jiffies - gl->gl_demote_time; 1729 dtime = jiffies - gl->gl_demote_time;
1736 dtime *= 1000000/HZ; /* demote time in uSec */ 1730 dtime *= 1000000/HZ; /* demote time in uSec */
@@ -1747,15 +1741,11 @@ int gfs2_dump_glock(struct seq_file *seq, const struct gfs2_glock *gl)
1747 atomic_read(&gl->gl_revokes), 1741 atomic_read(&gl->gl_revokes),
1748 (int)gl->gl_lockref.count, gl->gl_hold_time); 1742 (int)gl->gl_lockref.count, gl->gl_hold_time);
1749 1743
1750 list_for_each_entry(gh, &gl->gl_holders, gh_list) { 1744 list_for_each_entry(gh, &gl->gl_holders, gh_list)
1751 error = dump_holder(seq, gh); 1745 dump_holder(seq, gh);
1752 if (error) 1746
1753 goto out;
1754 }
1755 if (gl->gl_state != LM_ST_UNLOCKED && glops->go_dump) 1747 if (gl->gl_state != LM_ST_UNLOCKED && glops->go_dump)
1756 error = glops->go_dump(seq, gl); 1748 glops->go_dump(seq, gl);
1757out:
1758 return error;
1759} 1749}
1760 1750
1761static int gfs2_glstats_seq_show(struct seq_file *seq, void *iter_ptr) 1751static int gfs2_glstats_seq_show(struct seq_file *seq, void *iter_ptr)
@@ -1953,7 +1943,8 @@ static void gfs2_glock_seq_stop(struct seq_file *seq, void *iter_ptr)
1953 1943
1954static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr) 1944static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr)
1955{ 1945{
1956 return dump_glock(seq, iter_ptr); 1946 dump_glock(seq, iter_ptr);
1947 return 0;
1957} 1948}
1958 1949
1959static void *gfs2_sbstats_seq_start(struct seq_file *seq, loff_t *pos) 1950static void *gfs2_sbstats_seq_start(struct seq_file *seq, loff_t *pos)
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 6647d77366ba..32572f71f027 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -199,7 +199,7 @@ extern int gfs2_glock_nq_num(struct gfs2_sbd *sdp, u64 number,
199 struct gfs2_holder *gh); 199 struct gfs2_holder *gh);
200extern int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs); 200extern int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs);
201extern void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs); 201extern void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs);
202extern int gfs2_dump_glock(struct seq_file *seq, const struct gfs2_glock *gl); 202extern void gfs2_dump_glock(struct seq_file *seq, const struct gfs2_glock *gl);
203#define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { gfs2_dump_glock(NULL, gl); BUG(); } } while(0) 203#define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { gfs2_dump_glock(NULL, gl); BUG(); } } while(0)
204extern __printf(2, 3) 204extern __printf(2, 3)
205void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...); 205void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...);
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index f88dcd925010..3bf0631b5d56 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -133,7 +133,8 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
133 133
134static void rgrp_go_sync(struct gfs2_glock *gl) 134static void rgrp_go_sync(struct gfs2_glock *gl)
135{ 135{
136 struct address_space *metamapping = gfs2_glock2aspace(gl); 136 struct gfs2_sbd *sdp = gl->gl_sbd;
137 struct address_space *mapping = &sdp->sd_aspace;
137 struct gfs2_rgrpd *rgd; 138 struct gfs2_rgrpd *rgd;
138 int error; 139 int error;
139 140
@@ -141,10 +142,10 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
141 return; 142 return;
142 GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE); 143 GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
143 144
144 gfs2_log_flush(gl->gl_sbd, gl); 145 gfs2_log_flush(sdp, gl);
145 filemap_fdatawrite(metamapping); 146 filemap_fdatawrite_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
146 error = filemap_fdatawait(metamapping); 147 error = filemap_fdatawait_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
147 mapping_set_error(metamapping, error); 148 mapping_set_error(mapping, error);
148 gfs2_ail_empty_gl(gl); 149 gfs2_ail_empty_gl(gl);
149 150
150 spin_lock(&gl->gl_spin); 151 spin_lock(&gl->gl_spin);
@@ -166,11 +167,12 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
166 167
167static void rgrp_go_inval(struct gfs2_glock *gl, int flags) 168static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
168{ 169{
169 struct address_space *mapping = gfs2_glock2aspace(gl); 170 struct gfs2_sbd *sdp = gl->gl_sbd;
171 struct address_space *mapping = &sdp->sd_aspace;
170 172
171 WARN_ON_ONCE(!(flags & DIO_METADATA)); 173 WARN_ON_ONCE(!(flags & DIO_METADATA));
172 gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count)); 174 gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
173 truncate_inode_pages(mapping, 0); 175 truncate_inode_pages_range(mapping, gl->gl_vm.start, gl->gl_vm.end);
174 176
175 if (gl->gl_object) { 177 if (gl->gl_object) {
176 struct gfs2_rgrpd *rgd = (struct gfs2_rgrpd *)gl->gl_object; 178 struct gfs2_rgrpd *rgd = (struct gfs2_rgrpd *)gl->gl_object;
@@ -435,21 +437,19 @@ static int inode_go_lock(struct gfs2_holder *gh)
435 * @seq: The iterator 437 * @seq: The iterator
436 * @ip: the inode 438 * @ip: the inode
437 * 439 *
438 * Returns: 0 on success, -ENOBUFS when we run out of space
439 */ 440 */
440 441
441static int inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl) 442static void inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl)
442{ 443{
443 const struct gfs2_inode *ip = gl->gl_object; 444 const struct gfs2_inode *ip = gl->gl_object;
444 if (ip == NULL) 445 if (ip == NULL)
445 return 0; 446 return;
446 gfs2_print_dbg(seq, " I: n:%llu/%llu t:%u f:0x%02lx d:0x%08x s:%llu\n", 447 gfs2_print_dbg(seq, " I: n:%llu/%llu t:%u f:0x%02lx d:0x%08x s:%llu\n",
447 (unsigned long long)ip->i_no_formal_ino, 448 (unsigned long long)ip->i_no_formal_ino,
448 (unsigned long long)ip->i_no_addr, 449 (unsigned long long)ip->i_no_addr,
449 IF2DT(ip->i_inode.i_mode), ip->i_flags, 450 IF2DT(ip->i_inode.i_mode), ip->i_flags,
450 (unsigned int)ip->i_diskflags, 451 (unsigned int)ip->i_diskflags,
451 (unsigned long long)i_size_read(&ip->i_inode)); 452 (unsigned long long)i_size_read(&ip->i_inode));
452 return 0;
453} 453}
454 454
455/** 455/**
@@ -558,7 +558,7 @@ const struct gfs2_glock_operations gfs2_rgrp_glops = {
558 .go_unlock = gfs2_rgrp_go_unlock, 558 .go_unlock = gfs2_rgrp_go_unlock,
559 .go_dump = gfs2_rgrp_dump, 559 .go_dump = gfs2_rgrp_dump,
560 .go_type = LM_TYPE_RGRP, 560 .go_type = LM_TYPE_RGRP,
561 .go_flags = GLOF_ASPACE | GLOF_LVB, 561 .go_flags = GLOF_LVB,
562}; 562};
563 563
564const struct gfs2_glock_operations gfs2_trans_glops = { 564const struct gfs2_glock_operations gfs2_trans_glops = {
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index ba1ea67f4eeb..cf0e34400f71 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -93,6 +93,7 @@ struct gfs2_rgrpd {
93 struct gfs2_rgrp_lvb *rd_rgl; 93 struct gfs2_rgrp_lvb *rd_rgl;
94 u32 rd_last_alloc; 94 u32 rd_last_alloc;
95 u32 rd_flags; 95 u32 rd_flags;
96 u32 rd_extfail_pt; /* extent failure point */
96#define GFS2_RDF_CHECK 0x10000000 /* check for unlinked inodes */ 97#define GFS2_RDF_CHECK 0x10000000 /* check for unlinked inodes */
97#define GFS2_RDF_UPTODATE 0x20000000 /* rg is up to date */ 98#define GFS2_RDF_UPTODATE 0x20000000 /* rg is up to date */
98#define GFS2_RDF_ERROR 0x40000000 /* error in rg */ 99#define GFS2_RDF_ERROR 0x40000000 /* error in rg */
@@ -217,7 +218,7 @@ struct gfs2_glock_operations {
217 int (*go_demote_ok) (const struct gfs2_glock *gl); 218 int (*go_demote_ok) (const struct gfs2_glock *gl);
218 int (*go_lock) (struct gfs2_holder *gh); 219 int (*go_lock) (struct gfs2_holder *gh);
219 void (*go_unlock) (struct gfs2_holder *gh); 220 void (*go_unlock) (struct gfs2_holder *gh);
220 int (*go_dump)(struct seq_file *seq, const struct gfs2_glock *gl); 221 void (*go_dump)(struct seq_file *seq, const struct gfs2_glock *gl);
221 void (*go_callback)(struct gfs2_glock *gl, bool remote); 222 void (*go_callback)(struct gfs2_glock *gl, bool remote);
222 const int go_type; 223 const int go_type;
223 const unsigned long go_flags; 224 const unsigned long go_flags;
@@ -350,7 +351,15 @@ struct gfs2_glock {
350 atomic_t gl_ail_count; 351 atomic_t gl_ail_count;
351 atomic_t gl_revokes; 352 atomic_t gl_revokes;
352 struct delayed_work gl_work; 353 struct delayed_work gl_work;
353 struct work_struct gl_delete; 354 union {
355 /* For inode and iopen glocks only */
356 struct work_struct gl_delete;
357 /* For rgrp glocks only */
358 struct {
359 loff_t start;
360 loff_t end;
361 } gl_vm;
362 };
354 struct rcu_head gl_rcu; 363 struct rcu_head gl_rcu;
355}; 364};
356 365
@@ -419,10 +428,13 @@ enum {
419}; 428};
420 429
421struct gfs2_quota_data { 430struct gfs2_quota_data {
431 struct hlist_bl_node qd_hlist;
422 struct list_head qd_list; 432 struct list_head qd_list;
423 struct kqid qd_id; 433 struct kqid qd_id;
434 struct gfs2_sbd *qd_sbd;
424 struct lockref qd_lockref; 435 struct lockref qd_lockref;
425 struct list_head qd_lru; 436 struct list_head qd_lru;
437 unsigned qd_hash;
426 438
427 unsigned long qd_flags; /* QDF_... */ 439 unsigned long qd_flags; /* QDF_... */
428 440
@@ -441,6 +453,7 @@ struct gfs2_quota_data {
441 453
442 u64 qd_sync_gen; 454 u64 qd_sync_gen;
443 unsigned long qd_last_warn; 455 unsigned long qd_last_warn;
456 struct rcu_head qd_rcu;
444}; 457};
445 458
446struct gfs2_trans { 459struct gfs2_trans {
@@ -720,13 +733,15 @@ struct gfs2_sbd {
720 spinlock_t sd_trunc_lock; 733 spinlock_t sd_trunc_lock;
721 734
722 unsigned int sd_quota_slots; 735 unsigned int sd_quota_slots;
723 unsigned int sd_quota_chunks; 736 unsigned long *sd_quota_bitmap;
724 unsigned char **sd_quota_bitmap; 737 spinlock_t sd_bitmap_lock;
725 738
726 u64 sd_quota_sync_gen; 739 u64 sd_quota_sync_gen;
727 740
728 /* Log stuff */ 741 /* Log stuff */
729 742
743 struct address_space sd_aspace;
744
730 spinlock_t sd_log_lock; 745 spinlock_t sd_log_lock;
731 746
732 struct gfs2_trans *sd_log_tr; 747 struct gfs2_trans *sd_log_tr;
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 7119504159f1..890588c7fb33 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -149,7 +149,7 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
149 ip = GFS2_I(inode); 149 ip = GFS2_I(inode);
150 150
151 if (!inode) 151 if (!inode)
152 return ERR_PTR(-ENOBUFS); 152 return ERR_PTR(-ENOMEM);
153 153
154 if (inode->i_state & I_NEW) { 154 if (inode->i_state & I_NEW) {
155 struct gfs2_sbd *sdp = GFS2_SB(inode); 155 struct gfs2_sbd *sdp = GFS2_SB(inode);
@@ -469,14 +469,36 @@ static void init_dinode(struct gfs2_inode *dip, struct gfs2_inode *ip,
469 brelse(dibh); 469 brelse(dibh);
470} 470}
471 471
472/**
473 * gfs2_trans_da_blocks - Calculate number of blocks to link inode
474 * @dip: The directory we are linking into
475 * @da: The dir add information
476 * @nr_inodes: The number of inodes involved
477 *
478 * This calculate the number of blocks we need to reserve in a
479 * transaction to link @nr_inodes into a directory. In most cases
480 * @nr_inodes will be 2 (the directory plus the inode being linked in)
481 * but in case of rename, 4 may be required.
482 *
483 * Returns: Number of blocks
484 */
485
486static unsigned gfs2_trans_da_blks(const struct gfs2_inode *dip,
487 const struct gfs2_diradd *da,
488 unsigned nr_inodes)
489{
490 return da->nr_blocks + gfs2_rg_blocks(dip, da->nr_blocks) +
491 (nr_inodes * RES_DINODE) + RES_QUOTA + RES_STATFS;
492}
493
472static int link_dinode(struct gfs2_inode *dip, const struct qstr *name, 494static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
473 struct gfs2_inode *ip, int arq) 495 struct gfs2_inode *ip, struct gfs2_diradd *da)
474{ 496{
475 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 497 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
476 struct gfs2_alloc_parms ap = { .target = sdp->sd_max_dirres, }; 498 struct gfs2_alloc_parms ap = { .target = da->nr_blocks, };
477 int error; 499 int error;
478 500
479 if (arq) { 501 if (da->nr_blocks) {
480 error = gfs2_quota_lock_check(dip); 502 error = gfs2_quota_lock_check(dip);
481 if (error) 503 if (error)
482 goto fail_quota_locks; 504 goto fail_quota_locks;
@@ -485,10 +507,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
485 if (error) 507 if (error)
486 goto fail_quota_locks; 508 goto fail_quota_locks;
487 509
488 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + 510 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, da, 2), 0);
489 dip->i_rgd->rd_length +
490 2 * RES_DINODE +
491 RES_STATFS + RES_QUOTA, 0);
492 if (error) 511 if (error)
493 goto fail_ipreserv; 512 goto fail_ipreserv;
494 } else { 513 } else {
@@ -497,7 +516,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
497 goto fail_quota_locks; 516 goto fail_quota_locks;
498 } 517 }
499 518
500 error = gfs2_dir_add(&dip->i_inode, name, ip); 519 error = gfs2_dir_add(&dip->i_inode, name, ip, da);
501 if (error) 520 if (error)
502 goto fail_end_trans; 521 goto fail_end_trans;
503 522
@@ -560,7 +579,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
560 struct dentry *d; 579 struct dentry *d;
561 int error; 580 int error;
562 u32 aflags = 0; 581 u32 aflags = 0;
563 int arq; 582 struct gfs2_diradd da = { .bh = NULL, };
564 583
565 if (!name->len || name->len > GFS2_FNAMESIZE) 584 if (!name->len || name->len > GFS2_FNAMESIZE)
566 return -ENAMETOOLONG; 585 return -ENAMETOOLONG;
@@ -585,6 +604,9 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
585 error = PTR_ERR(inode); 604 error = PTR_ERR(inode);
586 if (!IS_ERR(inode)) { 605 if (!IS_ERR(inode)) {
587 d = d_splice_alias(inode, dentry); 606 d = d_splice_alias(inode, dentry);
607 error = PTR_ERR(d);
608 if (IS_ERR(d))
609 goto fail_gunlock;
588 error = 0; 610 error = 0;
589 if (file) { 611 if (file) {
590 if (S_ISREG(inode->i_mode)) { 612 if (S_ISREG(inode->i_mode)) {
@@ -602,7 +624,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
602 goto fail_gunlock; 624 goto fail_gunlock;
603 } 625 }
604 626
605 arq = error = gfs2_diradd_alloc_required(dir, name); 627 error = gfs2_diradd_alloc_required(dir, name, &da);
606 if (error < 0) 628 if (error < 0)
607 goto fail_gunlock; 629 goto fail_gunlock;
608 630
@@ -690,7 +712,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
690 if (error) 712 if (error)
691 goto fail_gunlock3; 713 goto fail_gunlock3;
692 714
693 error = link_dinode(dip, name, ip, arq); 715 error = link_dinode(dip, name, ip, &da);
694 if (error) 716 if (error)
695 goto fail_gunlock3; 717 goto fail_gunlock3;
696 718
@@ -719,6 +741,7 @@ fail_free_inode:
719 free_inode_nonrcu(inode); 741 free_inode_nonrcu(inode);
720 inode = NULL; 742 inode = NULL;
721fail_gunlock: 743fail_gunlock:
744 gfs2_dir_no_add(&da);
722 gfs2_glock_dq_uninit(ghs); 745 gfs2_glock_dq_uninit(ghs);
723 if (inode && !IS_ERR(inode)) { 746 if (inode && !IS_ERR(inode)) {
724 clear_nlink(inode); 747 clear_nlink(inode);
@@ -779,6 +802,11 @@ static struct dentry *__gfs2_lookup(struct inode *dir, struct dentry *dentry,
779 } 802 }
780 803
781 d = d_splice_alias(inode, dentry); 804 d = d_splice_alias(inode, dentry);
805 if (IS_ERR(d)) {
806 iput(inode);
807 gfs2_glock_dq_uninit(&gh);
808 return d;
809 }
782 if (file && S_ISREG(inode->i_mode)) 810 if (file && S_ISREG(inode->i_mode))
783 error = finish_open(file, dentry, gfs2_open_common, opened); 811 error = finish_open(file, dentry, gfs2_open_common, opened);
784 812
@@ -817,7 +845,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
817 struct gfs2_inode *ip = GFS2_I(inode); 845 struct gfs2_inode *ip = GFS2_I(inode);
818 struct gfs2_holder ghs[2]; 846 struct gfs2_holder ghs[2];
819 struct buffer_head *dibh; 847 struct buffer_head *dibh;
820 int alloc_required; 848 struct gfs2_diradd da = { .bh = NULL, };
821 int error; 849 int error;
822 850
823 if (S_ISDIR(inode->i_mode)) 851 if (S_ISDIR(inode->i_mode))
@@ -872,13 +900,12 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
872 if (ip->i_inode.i_nlink == (u32)-1) 900 if (ip->i_inode.i_nlink == (u32)-1)
873 goto out_gunlock; 901 goto out_gunlock;
874 902
875 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); 903 error = gfs2_diradd_alloc_required(dir, &dentry->d_name, &da);
876 if (error < 0) 904 if (error < 0)
877 goto out_gunlock; 905 goto out_gunlock;
878 error = 0;
879 906
880 if (alloc_required) { 907 if (da.nr_blocks) {
881 struct gfs2_alloc_parms ap = { .target = sdp->sd_max_dirres, }; 908 struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
882 error = gfs2_quota_lock_check(dip); 909 error = gfs2_quota_lock_check(dip);
883 if (error) 910 if (error)
884 goto out_gunlock; 911 goto out_gunlock;
@@ -887,10 +914,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
887 if (error) 914 if (error)
888 goto out_gunlock_q; 915 goto out_gunlock_q;
889 916
890 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + 917 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(dip, &da, 2), 0);
891 gfs2_rg_blocks(dip, sdp->sd_max_dirres) +
892 2 * RES_DINODE + RES_STATFS +
893 RES_QUOTA, 0);
894 if (error) 918 if (error)
895 goto out_ipres; 919 goto out_ipres;
896 } else { 920 } else {
@@ -903,7 +927,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
903 if (error) 927 if (error)
904 goto out_end_trans; 928 goto out_end_trans;
905 929
906 error = gfs2_dir_add(dir, &dentry->d_name, ip); 930 error = gfs2_dir_add(dir, &dentry->d_name, ip, &da);
907 if (error) 931 if (error)
908 goto out_brelse; 932 goto out_brelse;
909 933
@@ -919,12 +943,13 @@ out_brelse:
919out_end_trans: 943out_end_trans:
920 gfs2_trans_end(sdp); 944 gfs2_trans_end(sdp);
921out_ipres: 945out_ipres:
922 if (alloc_required) 946 if (da.nr_blocks)
923 gfs2_inplace_release(dip); 947 gfs2_inplace_release(dip);
924out_gunlock_q: 948out_gunlock_q:
925 if (alloc_required) 949 if (da.nr_blocks)
926 gfs2_quota_unlock(dip); 950 gfs2_quota_unlock(dip);
927out_gunlock: 951out_gunlock:
952 gfs2_dir_no_add(&da);
928 gfs2_glock_dq(ghs + 1); 953 gfs2_glock_dq(ghs + 1);
929out_child: 954out_child:
930 gfs2_glock_dq(ghs); 955 gfs2_glock_dq(ghs);
@@ -1254,7 +1279,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1254 struct gfs2_rgrpd *nrgd; 1279 struct gfs2_rgrpd *nrgd;
1255 unsigned int num_gh; 1280 unsigned int num_gh;
1256 int dir_rename = 0; 1281 int dir_rename = 0;
1257 int alloc_required = 0; 1282 struct gfs2_diradd da = { .nr_blocks = 0, };
1258 unsigned int x; 1283 unsigned int x;
1259 int error; 1284 int error;
1260 1285
@@ -1388,14 +1413,14 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1388 goto out_gunlock; 1413 goto out_gunlock;
1389 } 1414 }
1390 1415
1391 if (nip == NULL) 1416 if (nip == NULL) {
1392 alloc_required = gfs2_diradd_alloc_required(ndir, &ndentry->d_name); 1417 error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name, &da);
1393 error = alloc_required; 1418 if (error)
1394 if (error < 0) 1419 goto out_gunlock;
1395 goto out_gunlock; 1420 }
1396 1421
1397 if (alloc_required) { 1422 if (da.nr_blocks) {
1398 struct gfs2_alloc_parms ap = { .target = sdp->sd_max_dirres, }; 1423 struct gfs2_alloc_parms ap = { .target = da.nr_blocks, };
1399 error = gfs2_quota_lock_check(ndip); 1424 error = gfs2_quota_lock_check(ndip);
1400 if (error) 1425 if (error)
1401 goto out_gunlock; 1426 goto out_gunlock;
@@ -1404,10 +1429,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1404 if (error) 1429 if (error)
1405 goto out_gunlock_q; 1430 goto out_gunlock_q;
1406 1431
1407 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + 1432 error = gfs2_trans_begin(sdp, gfs2_trans_da_blks(ndip, &da, 4) +
1408 gfs2_rg_blocks(ndip, sdp->sd_max_dirres) + 1433 4 * RES_LEAF + 4, 0);
1409 4 * RES_DINODE + 4 * RES_LEAF +
1410 RES_STATFS + RES_QUOTA + 4, 0);
1411 if (error) 1434 if (error)
1412 goto out_ipreserv; 1435 goto out_ipreserv;
1413 } else { 1436 } else {
@@ -1441,19 +1464,20 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1441 if (error) 1464 if (error)
1442 goto out_end_trans; 1465 goto out_end_trans;
1443 1466
1444 error = gfs2_dir_add(ndir, &ndentry->d_name, ip); 1467 error = gfs2_dir_add(ndir, &ndentry->d_name, ip, &da);
1445 if (error) 1468 if (error)
1446 goto out_end_trans; 1469 goto out_end_trans;
1447 1470
1448out_end_trans: 1471out_end_trans:
1449 gfs2_trans_end(sdp); 1472 gfs2_trans_end(sdp);
1450out_ipreserv: 1473out_ipreserv:
1451 if (alloc_required) 1474 if (da.nr_blocks)
1452 gfs2_inplace_release(ndip); 1475 gfs2_inplace_release(ndip);
1453out_gunlock_q: 1476out_gunlock_q:
1454 if (alloc_required) 1477 if (da.nr_blocks)
1455 gfs2_quota_unlock(ndip); 1478 gfs2_quota_unlock(ndip);
1456out_gunlock: 1479out_gunlock:
1480 gfs2_dir_no_add(&da);
1457 while (x--) { 1481 while (x--) {
1458 gfs2_glock_dq(ghs + x); 1482 gfs2_glock_dq(ghs + x);
1459 gfs2_holder_uninit(ghs + x); 1483 gfs2_holder_uninit(ghs + x);
@@ -1607,10 +1631,22 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
1607 if (!(attr->ia_valid & ATTR_GID) || gid_eq(ogid, ngid)) 1631 if (!(attr->ia_valid & ATTR_GID) || gid_eq(ogid, ngid))
1608 ogid = ngid = NO_GID_QUOTA_CHANGE; 1632 ogid = ngid = NO_GID_QUOTA_CHANGE;
1609 1633
1610 error = gfs2_quota_lock(ip, nuid, ngid); 1634 error = get_write_access(inode);
1611 if (error) 1635 if (error)
1612 return error; 1636 return error;
1613 1637
1638 error = gfs2_rs_alloc(ip);
1639 if (error)
1640 goto out;
1641
1642 error = gfs2_rindex_update(sdp);
1643 if (error)
1644 goto out;
1645
1646 error = gfs2_quota_lock(ip, nuid, ngid);
1647 if (error)
1648 goto out;
1649
1614 if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) || 1650 if (!uid_eq(ouid, NO_UID_QUOTA_CHANGE) ||
1615 !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) { 1651 !gid_eq(ogid, NO_GID_QUOTA_CHANGE)) {
1616 error = gfs2_quota_check(ip, nuid, ngid); 1652 error = gfs2_quota_check(ip, nuid, ngid);
@@ -1637,6 +1673,8 @@ out_end_trans:
1637 gfs2_trans_end(sdp); 1673 gfs2_trans_end(sdp);
1638out_gunlock_q: 1674out_gunlock_q:
1639 gfs2_quota_unlock(ip); 1675 gfs2_quota_unlock(ip);
1676out:
1677 put_write_access(inode);
1640 return error; 1678 return error;
1641} 1679}
1642 1680
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 010b9fb9fec6..58f06400b7b8 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -83,6 +83,7 @@ static void maybe_release_space(struct gfs2_bufdata *bd)
83 bd->bd_bh->b_data + bi->bi_offset, bi->bi_len); 83 bd->bd_bh->b_data + bi->bi_offset, bi->bi_len);
84 clear_bit(GBF_FULL, &bi->bi_flags); 84 clear_bit(GBF_FULL, &bi->bi_flags);
85 rgd->rd_free_clone = rgd->rd_free; 85 rgd->rd_free_clone = rgd->rd_free;
86 rgd->rd_extfail_pt = rgd->rd_free;
86} 87}
87 88
88/** 89/**
@@ -588,8 +589,12 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
588static void gfs2_meta_sync(struct gfs2_glock *gl) 589static void gfs2_meta_sync(struct gfs2_glock *gl)
589{ 590{
590 struct address_space *mapping = gfs2_glock2aspace(gl); 591 struct address_space *mapping = gfs2_glock2aspace(gl);
592 struct gfs2_sbd *sdp = gl->gl_sbd;
591 int error; 593 int error;
592 594
595 if (mapping == NULL)
596 mapping = &sdp->sd_aspace;
597
593 filemap_fdatawrite(mapping); 598 filemap_fdatawrite(mapping);
594 error = filemap_fdatawait(mapping); 599 error = filemap_fdatawait(mapping);
595 600
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 0650db2541ef..c272e73063de 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -76,6 +76,7 @@ static int __init init_gfs2_fs(void)
76 76
77 gfs2_str2qstr(&gfs2_qdot, "."); 77 gfs2_str2qstr(&gfs2_qdot, ".");
78 gfs2_str2qstr(&gfs2_qdotdot, ".."); 78 gfs2_str2qstr(&gfs2_qdotdot, "..");
79 gfs2_quota_hash_init();
79 80
80 error = gfs2_sys_init(); 81 error = gfs2_sys_init();
81 if (error) 82 if (error)
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 52f177be3bf8..c7f24690ed05 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -116,6 +116,9 @@ struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create)
116 unsigned long index; 116 unsigned long index;
117 unsigned int bufnum; 117 unsigned int bufnum;
118 118
119 if (mapping == NULL)
120 mapping = &sdp->sd_aspace;
121
119 shift = PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift; 122 shift = PAGE_CACHE_SHIFT - sdp->sd_sb.sb_bsize_shift;
120 index = blkno >> shift; /* convert block to page */ 123 index = blkno >> shift; /* convert block to page */
121 bufnum = blkno - (index << shift); /* block buf index within page */ 124 bufnum = blkno - (index << shift); /* block buf index within page */
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 52fa88314f5c..1e712b566d76 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -36,6 +36,7 @@
36#include "log.h" 36#include "log.h"
37#include "quota.h" 37#include "quota.h"
38#include "dir.h" 38#include "dir.h"
39#include "meta_io.h"
39#include "trace_gfs2.h" 40#include "trace_gfs2.h"
40 41
41#define DO 0 42#define DO 0
@@ -62,6 +63,7 @@ static void gfs2_tune_init(struct gfs2_tune *gt)
62static struct gfs2_sbd *init_sbd(struct super_block *sb) 63static struct gfs2_sbd *init_sbd(struct super_block *sb)
63{ 64{
64 struct gfs2_sbd *sdp; 65 struct gfs2_sbd *sdp;
66 struct address_space *mapping;
65 67
66 sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL); 68 sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
67 if (!sdp) 69 if (!sdp)
@@ -97,6 +99,18 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
97 init_waitqueue_head(&sdp->sd_quota_wait); 99 init_waitqueue_head(&sdp->sd_quota_wait);
98 INIT_LIST_HEAD(&sdp->sd_trunc_list); 100 INIT_LIST_HEAD(&sdp->sd_trunc_list);
99 spin_lock_init(&sdp->sd_trunc_lock); 101 spin_lock_init(&sdp->sd_trunc_lock);
102 spin_lock_init(&sdp->sd_bitmap_lock);
103
104 mapping = &sdp->sd_aspace;
105
106 address_space_init_once(mapping);
107 mapping->a_ops = &gfs2_meta_aops;
108 mapping->host = sb->s_bdev->bd_inode;
109 mapping->flags = 0;
110 mapping_set_gfp_mask(mapping, GFP_NOFS);
111 mapping->private_data = NULL;
112 mapping->backing_dev_info = sb->s_bdi;
113 mapping->writeback_index = 0;
100 114
101 spin_lock_init(&sdp->sd_log_lock); 115 spin_lock_init(&sdp->sd_log_lock);
102 atomic_set(&sdp->sd_log_pinned, 0); 116 atomic_set(&sdp->sd_log_pinned, 0);
@@ -217,7 +231,7 @@ static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector, int silent)
217 231
218 page = alloc_page(GFP_NOFS); 232 page = alloc_page(GFP_NOFS);
219 if (unlikely(!page)) 233 if (unlikely(!page))
220 return -ENOBUFS; 234 return -ENOMEM;
221 235
222 ClearPageUptodate(page); 236 ClearPageUptodate(page);
223 ClearPageDirty(page); 237 ClearPageDirty(page);
@@ -956,40 +970,6 @@ fail:
956 return error; 970 return error;
957} 971}
958 972
959static int init_threads(struct gfs2_sbd *sdp, int undo)
960{
961 struct task_struct *p;
962 int error = 0;
963
964 if (undo)
965 goto fail_quotad;
966
967 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
968 if (IS_ERR(p)) {
969 error = PTR_ERR(p);
970 fs_err(sdp, "can't start logd thread: %d\n", error);
971 return error;
972 }
973 sdp->sd_logd_process = p;
974
975 p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
976 if (IS_ERR(p)) {
977 error = PTR_ERR(p);
978 fs_err(sdp, "can't start quotad thread: %d\n", error);
979 goto fail;
980 }
981 sdp->sd_quotad_process = p;
982
983 return 0;
984
985
986fail_quotad:
987 kthread_stop(sdp->sd_quotad_process);
988fail:
989 kthread_stop(sdp->sd_logd_process);
990 return error;
991}
992
993static const match_table_t nolock_tokens = { 973static const match_table_t nolock_tokens = {
994 { Opt_jid, "jid=%d\n", }, 974 { Opt_jid, "jid=%d\n", },
995 { Opt_err, NULL }, 975 { Opt_err, NULL },
@@ -1254,15 +1234,11 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
1254 goto fail_per_node; 1234 goto fail_per_node;
1255 } 1235 }
1256 1236
1257 error = init_threads(sdp, DO);
1258 if (error)
1259 goto fail_per_node;
1260
1261 if (!(sb->s_flags & MS_RDONLY)) { 1237 if (!(sb->s_flags & MS_RDONLY)) {
1262 error = gfs2_make_fs_rw(sdp); 1238 error = gfs2_make_fs_rw(sdp);
1263 if (error) { 1239 if (error) {
1264 fs_err(sdp, "can't make FS RW: %d\n", error); 1240 fs_err(sdp, "can't make FS RW: %d\n", error);
1265 goto fail_threads; 1241 goto fail_per_node;
1266 } 1242 }
1267 } 1243 }
1268 1244
@@ -1270,8 +1246,6 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
1270 gfs2_online_uevent(sdp); 1246 gfs2_online_uevent(sdp);
1271 return 0; 1247 return 0;
1272 1248
1273fail_threads:
1274 init_threads(sdp, UNDO);
1275fail_per_node: 1249fail_per_node:
1276 init_per_node(sdp, UNDO); 1250 init_per_node(sdp, UNDO);
1277fail_inodes: 1251fail_inodes:
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 98236d0df3ca..8bec0e3192dd 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -52,6 +52,11 @@
52#include <linux/dqblk_xfs.h> 52#include <linux/dqblk_xfs.h>
53#include <linux/lockref.h> 53#include <linux/lockref.h>
54#include <linux/list_lru.h> 54#include <linux/list_lru.h>
55#include <linux/rcupdate.h>
56#include <linux/rculist_bl.h>
57#include <linux/bit_spinlock.h>
58#include <linux/jhash.h>
59#include <linux/vmalloc.h>
55 60
56#include "gfs2.h" 61#include "gfs2.h"
57#include "incore.h" 62#include "incore.h"
@@ -67,16 +72,44 @@
67#include "inode.h" 72#include "inode.h"
68#include "util.h" 73#include "util.h"
69 74
70struct gfs2_quota_change_host { 75#define GFS2_QD_HASH_SHIFT 12
71 u64 qc_change; 76#define GFS2_QD_HASH_SIZE (1 << GFS2_QD_HASH_SHIFT)
72 u32 qc_flags; /* GFS2_QCF_... */ 77#define GFS2_QD_HASH_MASK (GFS2_QD_HASH_SIZE - 1)
73 struct kqid qc_id;
74};
75 78
76/* Lock order: qd_lock -> qd->lockref.lock -> lru lock */ 79/* Lock order: qd_lock -> bucket lock -> qd->lockref.lock -> lru lock */
80/* -> sd_bitmap_lock */
77static DEFINE_SPINLOCK(qd_lock); 81static DEFINE_SPINLOCK(qd_lock);
78struct list_lru gfs2_qd_lru; 82struct list_lru gfs2_qd_lru;
79 83
84static struct hlist_bl_head qd_hash_table[GFS2_QD_HASH_SIZE];
85
86static unsigned int gfs2_qd_hash(const struct gfs2_sbd *sdp,
87 const struct kqid qid)
88{
89 unsigned int h;
90
91 h = jhash(&sdp, sizeof(struct gfs2_sbd *), 0);
92 h = jhash(&qid, sizeof(struct kqid), h);
93
94 return h & GFS2_QD_HASH_MASK;
95}
96
97static inline void spin_lock_bucket(unsigned int hash)
98{
99 hlist_bl_lock(&qd_hash_table[hash]);
100}
101
102static inline void spin_unlock_bucket(unsigned int hash)
103{
104 hlist_bl_unlock(&qd_hash_table[hash]);
105}
106
107static void gfs2_qd_dealloc(struct rcu_head *rcu)
108{
109 struct gfs2_quota_data *qd = container_of(rcu, struct gfs2_quota_data, qd_rcu);
110 kmem_cache_free(gfs2_quotad_cachep, qd);
111}
112
80static void gfs2_qd_dispose(struct list_head *list) 113static void gfs2_qd_dispose(struct list_head *list)
81{ 114{
82 struct gfs2_quota_data *qd; 115 struct gfs2_quota_data *qd;
@@ -93,6 +126,10 @@ static void gfs2_qd_dispose(struct list_head *list)
93 list_del(&qd->qd_list); 126 list_del(&qd->qd_list);
94 spin_unlock(&qd_lock); 127 spin_unlock(&qd_lock);
95 128
129 spin_lock_bucket(qd->qd_hash);
130 hlist_bl_del_rcu(&qd->qd_hlist);
131 spin_unlock_bucket(qd->qd_hash);
132
96 gfs2_assert_warn(sdp, !qd->qd_change); 133 gfs2_assert_warn(sdp, !qd->qd_change);
97 gfs2_assert_warn(sdp, !qd->qd_slot_count); 134 gfs2_assert_warn(sdp, !qd->qd_slot_count);
98 gfs2_assert_warn(sdp, !qd->qd_bh_count); 135 gfs2_assert_warn(sdp, !qd->qd_bh_count);
@@ -101,7 +138,7 @@ static void gfs2_qd_dispose(struct list_head *list)
101 atomic_dec(&sdp->sd_quota_count); 138 atomic_dec(&sdp->sd_quota_count);
102 139
103 /* Delete it from the common reclaim list */ 140 /* Delete it from the common reclaim list */
104 kmem_cache_free(gfs2_quotad_cachep, qd); 141 call_rcu(&qd->qd_rcu, gfs2_qd_dealloc);
105 } 142 }
106} 143}
107 144
@@ -171,83 +208,95 @@ static u64 qd2offset(struct gfs2_quota_data *qd)
171 return offset; 208 return offset;
172} 209}
173 210
174static int qd_alloc(struct gfs2_sbd *sdp, struct kqid qid, 211static struct gfs2_quota_data *qd_alloc(unsigned hash, struct gfs2_sbd *sdp, struct kqid qid)
175 struct gfs2_quota_data **qdp)
176{ 212{
177 struct gfs2_quota_data *qd; 213 struct gfs2_quota_data *qd;
178 int error; 214 int error;
179 215
180 qd = kmem_cache_zalloc(gfs2_quotad_cachep, GFP_NOFS); 216 qd = kmem_cache_zalloc(gfs2_quotad_cachep, GFP_NOFS);
181 if (!qd) 217 if (!qd)
182 return -ENOMEM; 218 return NULL;
183 219
220 qd->qd_sbd = sdp;
184 qd->qd_lockref.count = 1; 221 qd->qd_lockref.count = 1;
185 spin_lock_init(&qd->qd_lockref.lock); 222 spin_lock_init(&qd->qd_lockref.lock);
186 qd->qd_id = qid; 223 qd->qd_id = qid;
187 qd->qd_slot = -1; 224 qd->qd_slot = -1;
188 INIT_LIST_HEAD(&qd->qd_lru); 225 INIT_LIST_HEAD(&qd->qd_lru);
226 qd->qd_hash = hash;
189 227
190 error = gfs2_glock_get(sdp, qd2index(qd), 228 error = gfs2_glock_get(sdp, qd2index(qd),
191 &gfs2_quota_glops, CREATE, &qd->qd_gl); 229 &gfs2_quota_glops, CREATE, &qd->qd_gl);
192 if (error) 230 if (error)
193 goto fail; 231 goto fail;
194 232
195 *qdp = qd; 233 return qd;
196
197 return 0;
198 234
199fail: 235fail:
200 kmem_cache_free(gfs2_quotad_cachep, qd); 236 kmem_cache_free(gfs2_quotad_cachep, qd);
201 return error; 237 return NULL;
202} 238}
203 239
204static int qd_get(struct gfs2_sbd *sdp, struct kqid qid, 240static struct gfs2_quota_data *gfs2_qd_search_bucket(unsigned int hash,
205 struct gfs2_quota_data **qdp) 241 const struct gfs2_sbd *sdp,
242 struct kqid qid)
206{ 243{
207 struct gfs2_quota_data *qd = NULL, *new_qd = NULL; 244 struct gfs2_quota_data *qd;
208 int error, found; 245 struct hlist_bl_node *h;
209
210 *qdp = NULL;
211 246
212 for (;;) { 247 hlist_bl_for_each_entry_rcu(qd, h, &qd_hash_table[hash], qd_hlist) {
213 found = 0; 248 if (!qid_eq(qd->qd_id, qid))
214 spin_lock(&qd_lock); 249 continue;
215 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { 250 if (qd->qd_sbd != sdp)
216 if (qid_eq(qd->qd_id, qid) && 251 continue;
217 lockref_get_not_dead(&qd->qd_lockref)) { 252 if (lockref_get_not_dead(&qd->qd_lockref)) {
218 list_lru_del(&gfs2_qd_lru, &qd->qd_lru); 253 list_lru_del(&gfs2_qd_lru, &qd->qd_lru);
219 found = 1; 254 return qd;
220 break;
221 }
222 } 255 }
256 }
223 257
224 if (!found) 258 return NULL;
225 qd = NULL; 259}
226 260
227 if (!qd && new_qd) {
228 qd = new_qd;
229 list_add(&qd->qd_list, &sdp->sd_quota_list);
230 atomic_inc(&sdp->sd_quota_count);
231 new_qd = NULL;
232 }
233 261
234 spin_unlock(&qd_lock); 262static int qd_get(struct gfs2_sbd *sdp, struct kqid qid,
263 struct gfs2_quota_data **qdp)
264{
265 struct gfs2_quota_data *qd, *new_qd;
266 unsigned int hash = gfs2_qd_hash(sdp, qid);
235 267
236 if (qd) { 268 rcu_read_lock();
237 if (new_qd) { 269 *qdp = qd = gfs2_qd_search_bucket(hash, sdp, qid);
238 gfs2_glock_put(new_qd->qd_gl); 270 rcu_read_unlock();
239 kmem_cache_free(gfs2_quotad_cachep, new_qd);
240 }
241 *qdp = qd;
242 return 0;
243 }
244 271
245 error = qd_alloc(sdp, qid, &new_qd); 272 if (qd)
246 if (error) 273 return 0;
247 return error; 274
275 new_qd = qd_alloc(hash, sdp, qid);
276 if (!new_qd)
277 return -ENOMEM;
278
279 spin_lock(&qd_lock);
280 spin_lock_bucket(hash);
281 *qdp = qd = gfs2_qd_search_bucket(hash, sdp, qid);
282 if (qd == NULL) {
283 *qdp = new_qd;
284 list_add(&new_qd->qd_list, &sdp->sd_quota_list);
285 hlist_bl_add_head_rcu(&new_qd->qd_hlist, &qd_hash_table[hash]);
286 atomic_inc(&sdp->sd_quota_count);
248 } 287 }
288 spin_unlock_bucket(hash);
289 spin_unlock(&qd_lock);
290
291 if (qd) {
292 gfs2_glock_put(new_qd->qd_gl);
293 kmem_cache_free(gfs2_quotad_cachep, new_qd);
294 }
295
296 return 0;
249} 297}
250 298
299
251static void qd_hold(struct gfs2_quota_data *qd) 300static void qd_hold(struct gfs2_quota_data *qd)
252{ 301{
253 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 302 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
@@ -268,88 +317,48 @@ static void qd_put(struct gfs2_quota_data *qd)
268 317
269static int slot_get(struct gfs2_quota_data *qd) 318static int slot_get(struct gfs2_quota_data *qd)
270{ 319{
271 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 320 struct gfs2_sbd *sdp = qd->qd_sbd;
272 unsigned int c, o = 0, b; 321 unsigned int bit;
273 unsigned char byte = 0; 322 int error = 0;
274 323
275 spin_lock(&qd_lock); 324 spin_lock(&sdp->sd_bitmap_lock);
325 if (qd->qd_slot_count != 0)
326 goto out;
276 327
277 if (qd->qd_slot_count++) { 328 error = -ENOSPC;
278 spin_unlock(&qd_lock); 329 bit = find_first_zero_bit(sdp->sd_quota_bitmap, sdp->sd_quota_slots);
279 return 0; 330 if (bit < sdp->sd_quota_slots) {
331 set_bit(bit, sdp->sd_quota_bitmap);
332 qd->qd_slot = bit;
333out:
334 qd->qd_slot_count++;
280 } 335 }
336 spin_unlock(&sdp->sd_bitmap_lock);
281 337
282 for (c = 0; c < sdp->sd_quota_chunks; c++) 338 return error;
283 for (o = 0; o < PAGE_SIZE; o++) {
284 byte = sdp->sd_quota_bitmap[c][o];
285 if (byte != 0xFF)
286 goto found;
287 }
288
289 goto fail;
290
291found:
292 for (b = 0; b < 8; b++)
293 if (!(byte & (1 << b)))
294 break;
295 qd->qd_slot = c * (8 * PAGE_SIZE) + o * 8 + b;
296
297 if (qd->qd_slot >= sdp->sd_quota_slots)
298 goto fail;
299
300 sdp->sd_quota_bitmap[c][o] |= 1 << b;
301
302 spin_unlock(&qd_lock);
303
304 return 0;
305
306fail:
307 qd->qd_slot_count--;
308 spin_unlock(&qd_lock);
309 return -ENOSPC;
310} 339}
311 340
312static void slot_hold(struct gfs2_quota_data *qd) 341static void slot_hold(struct gfs2_quota_data *qd)
313{ 342{
314 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 343 struct gfs2_sbd *sdp = qd->qd_sbd;
315 344
316 spin_lock(&qd_lock); 345 spin_lock(&sdp->sd_bitmap_lock);
317 gfs2_assert(sdp, qd->qd_slot_count); 346 gfs2_assert(sdp, qd->qd_slot_count);
318 qd->qd_slot_count++; 347 qd->qd_slot_count++;
319 spin_unlock(&qd_lock); 348 spin_unlock(&sdp->sd_bitmap_lock);
320}
321
322static void gfs2_icbit_munge(struct gfs2_sbd *sdp, unsigned char **bitmap,
323 unsigned int bit, int new_value)
324{
325 unsigned int c, o, b = bit;
326 int old_value;
327
328 c = b / (8 * PAGE_SIZE);
329 b %= 8 * PAGE_SIZE;
330 o = b / 8;
331 b %= 8;
332
333 old_value = (bitmap[c][o] & (1 << b));
334 gfs2_assert_withdraw(sdp, !old_value != !new_value);
335
336 if (new_value)
337 bitmap[c][o] |= 1 << b;
338 else
339 bitmap[c][o] &= ~(1 << b);
340} 349}
341 350
342static void slot_put(struct gfs2_quota_data *qd) 351static void slot_put(struct gfs2_quota_data *qd)
343{ 352{
344 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 353 struct gfs2_sbd *sdp = qd->qd_sbd;
345 354
346 spin_lock(&qd_lock); 355 spin_lock(&sdp->sd_bitmap_lock);
347 gfs2_assert(sdp, qd->qd_slot_count); 356 gfs2_assert(sdp, qd->qd_slot_count);
348 if (!--qd->qd_slot_count) { 357 if (!--qd->qd_slot_count) {
349 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0); 358 BUG_ON(!test_and_clear_bit(qd->qd_slot, sdp->sd_quota_bitmap));
350 qd->qd_slot = -1; 359 qd->qd_slot = -1;
351 } 360 }
352 spin_unlock(&qd_lock); 361 spin_unlock(&sdp->sd_bitmap_lock);
353} 362}
354 363
355static int bh_get(struct gfs2_quota_data *qd) 364static int bh_get(struct gfs2_quota_data *qd)
@@ -427,8 +436,7 @@ static int qd_check_sync(struct gfs2_sbd *sdp, struct gfs2_quota_data *qd,
427 list_move_tail(&qd->qd_list, &sdp->sd_quota_list); 436 list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
428 set_bit(QDF_LOCKED, &qd->qd_flags); 437 set_bit(QDF_LOCKED, &qd->qd_flags);
429 qd->qd_change_sync = qd->qd_change; 438 qd->qd_change_sync = qd->qd_change;
430 gfs2_assert_warn(sdp, qd->qd_slot_count); 439 slot_hold(qd);
431 qd->qd_slot_count++;
432 return 1; 440 return 1;
433} 441}
434 442
@@ -1214,17 +1222,6 @@ int gfs2_quota_refresh(struct gfs2_sbd *sdp, struct kqid qid)
1214 return error; 1222 return error;
1215} 1223}
1216 1224
1217static void gfs2_quota_change_in(struct gfs2_quota_change_host *qc, const void *buf)
1218{
1219 const struct gfs2_quota_change *str = buf;
1220
1221 qc->qc_change = be64_to_cpu(str->qc_change);
1222 qc->qc_flags = be32_to_cpu(str->qc_flags);
1223 qc->qc_id = make_kqid(&init_user_ns,
1224 (qc->qc_flags & GFS2_QCF_USER)?USRQUOTA:GRPQUOTA,
1225 be32_to_cpu(str->qc_id));
1226}
1227
1228int gfs2_quota_init(struct gfs2_sbd *sdp) 1225int gfs2_quota_init(struct gfs2_sbd *sdp)
1229{ 1226{
1230 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode); 1227 struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
@@ -1232,6 +1229,8 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
1232 unsigned int blocks = size >> sdp->sd_sb.sb_bsize_shift; 1229 unsigned int blocks = size >> sdp->sd_sb.sb_bsize_shift;
1233 unsigned int x, slot = 0; 1230 unsigned int x, slot = 0;
1234 unsigned int found = 0; 1231 unsigned int found = 0;
1232 unsigned int hash;
1233 unsigned int bm_size;
1235 u64 dblock; 1234 u64 dblock;
1236 u32 extlen = 0; 1235 u32 extlen = 0;
1237 int error; 1236 int error;
@@ -1240,23 +1239,20 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
1240 return -EIO; 1239 return -EIO;
1241 1240
1242 sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block; 1241 sdp->sd_quota_slots = blocks * sdp->sd_qc_per_block;
1243 sdp->sd_quota_chunks = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * PAGE_SIZE); 1242 bm_size = DIV_ROUND_UP(sdp->sd_quota_slots, 8 * sizeof(unsigned long));
1244 1243 bm_size *= sizeof(unsigned long);
1245 error = -ENOMEM; 1244 error = -ENOMEM;
1246 1245 sdp->sd_quota_bitmap = kmalloc(bm_size, GFP_NOFS|__GFP_NOWARN);
1247 sdp->sd_quota_bitmap = kcalloc(sdp->sd_quota_chunks, 1246 if (sdp->sd_quota_bitmap == NULL)
1248 sizeof(unsigned char *), GFP_NOFS); 1247 sdp->sd_quota_bitmap = __vmalloc(bm_size, GFP_NOFS, PAGE_KERNEL);
1249 if (!sdp->sd_quota_bitmap) 1248 if (!sdp->sd_quota_bitmap)
1250 return error; 1249 return error;
1251 1250
1252 for (x = 0; x < sdp->sd_quota_chunks; x++) { 1251 memset(sdp->sd_quota_bitmap, 0, bm_size);
1253 sdp->sd_quota_bitmap[x] = kzalloc(PAGE_SIZE, GFP_NOFS);
1254 if (!sdp->sd_quota_bitmap[x])
1255 goto fail;
1256 }
1257 1252
1258 for (x = 0; x < blocks; x++) { 1253 for (x = 0; x < blocks; x++) {
1259 struct buffer_head *bh; 1254 struct buffer_head *bh;
1255 const struct gfs2_quota_change *qc;
1260 unsigned int y; 1256 unsigned int y;
1261 1257
1262 if (!extlen) { 1258 if (!extlen) {
@@ -1274,34 +1270,42 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
1274 goto fail; 1270 goto fail;
1275 } 1271 }
1276 1272
1273 qc = (const struct gfs2_quota_change *)(bh->b_data + sizeof(struct gfs2_meta_header));
1277 for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots; 1274 for (y = 0; y < sdp->sd_qc_per_block && slot < sdp->sd_quota_slots;
1278 y++, slot++) { 1275 y++, slot++) {
1279 struct gfs2_quota_change_host qc;
1280 struct gfs2_quota_data *qd; 1276 struct gfs2_quota_data *qd;
1281 1277 s64 qc_change = be64_to_cpu(qc->qc_change);
1282 gfs2_quota_change_in(&qc, bh->b_data + 1278 u32 qc_flags = be32_to_cpu(qc->qc_flags);
1283 sizeof(struct gfs2_meta_header) + 1279 enum quota_type qtype = (qc_flags & GFS2_QCF_USER) ?
1284 y * sizeof(struct gfs2_quota_change)); 1280 USRQUOTA : GRPQUOTA;
1285 if (!qc.qc_change) 1281 struct kqid qc_id = make_kqid(&init_user_ns, qtype,
1282 be32_to_cpu(qc->qc_id));
1283 qc++;
1284 if (!qc_change)
1286 continue; 1285 continue;
1287 1286
1288 error = qd_alloc(sdp, qc.qc_id, &qd); 1287 hash = gfs2_qd_hash(sdp, qc_id);
1289 if (error) { 1288 qd = qd_alloc(hash, sdp, qc_id);
1289 if (qd == NULL) {
1290 brelse(bh); 1290 brelse(bh);
1291 goto fail; 1291 goto fail;
1292 } 1292 }
1293 1293
1294 set_bit(QDF_CHANGE, &qd->qd_flags); 1294 set_bit(QDF_CHANGE, &qd->qd_flags);
1295 qd->qd_change = qc.qc_change; 1295 qd->qd_change = qc_change;
1296 qd->qd_slot = slot; 1296 qd->qd_slot = slot;
1297 qd->qd_slot_count = 1; 1297 qd->qd_slot_count = 1;
1298 1298
1299 spin_lock(&qd_lock); 1299 spin_lock(&qd_lock);
1300 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1); 1300 BUG_ON(test_and_set_bit(slot, sdp->sd_quota_bitmap));
1301 list_add(&qd->qd_list, &sdp->sd_quota_list); 1301 list_add(&qd->qd_list, &sdp->sd_quota_list);
1302 atomic_inc(&sdp->sd_quota_count); 1302 atomic_inc(&sdp->sd_quota_count);
1303 spin_unlock(&qd_lock); 1303 spin_unlock(&qd_lock);
1304 1304
1305 spin_lock_bucket(hash);
1306 hlist_bl_add_head_rcu(&qd->qd_hlist, &qd_hash_table[hash]);
1307 spin_unlock_bucket(hash);
1308
1305 found++; 1309 found++;
1306 } 1310 }
1307 1311
@@ -1324,44 +1328,28 @@ void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
1324{ 1328{
1325 struct list_head *head = &sdp->sd_quota_list; 1329 struct list_head *head = &sdp->sd_quota_list;
1326 struct gfs2_quota_data *qd; 1330 struct gfs2_quota_data *qd;
1327 unsigned int x;
1328 1331
1329 spin_lock(&qd_lock); 1332 spin_lock(&qd_lock);
1330 while (!list_empty(head)) { 1333 while (!list_empty(head)) {
1331 qd = list_entry(head->prev, struct gfs2_quota_data, qd_list); 1334 qd = list_entry(head->prev, struct gfs2_quota_data, qd_list);
1332 1335
1333 /*
1334 * To be removed in due course... we should be able to
1335 * ensure that all refs to the qd have done by this point
1336 * so that this rather odd test is not required
1337 */
1338 spin_lock(&qd->qd_lockref.lock);
1339 if (qd->qd_lockref.count > 1 ||
1340 (qd->qd_lockref.count && !test_bit(QDF_CHANGE, &qd->qd_flags))) {
1341 spin_unlock(&qd->qd_lockref.lock);
1342 list_move(&qd->qd_list, head);
1343 spin_unlock(&qd_lock);
1344 schedule();
1345 spin_lock(&qd_lock);
1346 continue;
1347 }
1348 spin_unlock(&qd->qd_lockref.lock);
1349
1350 list_del(&qd->qd_list); 1336 list_del(&qd->qd_list);
1337
1351 /* Also remove if this qd exists in the reclaim list */ 1338 /* Also remove if this qd exists in the reclaim list */
1352 list_lru_del(&gfs2_qd_lru, &qd->qd_lru); 1339 list_lru_del(&gfs2_qd_lru, &qd->qd_lru);
1353 atomic_dec(&sdp->sd_quota_count); 1340 atomic_dec(&sdp->sd_quota_count);
1354 spin_unlock(&qd_lock); 1341 spin_unlock(&qd_lock);
1355 1342
1356 if (!qd->qd_lockref.count) { 1343 spin_lock_bucket(qd->qd_hash);
1357 gfs2_assert_warn(sdp, !qd->qd_change); 1344 hlist_bl_del_rcu(&qd->qd_hlist);
1358 gfs2_assert_warn(sdp, !qd->qd_slot_count); 1345 spin_unlock_bucket(qd->qd_hash);
1359 } else 1346
1360 gfs2_assert_warn(sdp, qd->qd_slot_count == 1); 1347 gfs2_assert_warn(sdp, !qd->qd_change);
1348 gfs2_assert_warn(sdp, !qd->qd_slot_count);
1361 gfs2_assert_warn(sdp, !qd->qd_bh_count); 1349 gfs2_assert_warn(sdp, !qd->qd_bh_count);
1362 1350
1363 gfs2_glock_put(qd->qd_gl); 1351 gfs2_glock_put(qd->qd_gl);
1364 kmem_cache_free(gfs2_quotad_cachep, qd); 1352 call_rcu(&qd->qd_rcu, gfs2_qd_dealloc);
1365 1353
1366 spin_lock(&qd_lock); 1354 spin_lock(&qd_lock);
1367 } 1355 }
@@ -1370,9 +1358,11 @@ void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
1370 gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count)); 1358 gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count));
1371 1359
1372 if (sdp->sd_quota_bitmap) { 1360 if (sdp->sd_quota_bitmap) {
1373 for (x = 0; x < sdp->sd_quota_chunks; x++) 1361 if (is_vmalloc_addr(sdp->sd_quota_bitmap))
1374 kfree(sdp->sd_quota_bitmap[x]); 1362 vfree(sdp->sd_quota_bitmap);
1375 kfree(sdp->sd_quota_bitmap); 1363 else
1364 kfree(sdp->sd_quota_bitmap);
1365 sdp->sd_quota_bitmap = NULL;
1376 } 1366 }
1377} 1367}
1378 1368
@@ -1656,3 +1646,11 @@ const struct quotactl_ops gfs2_quotactl_ops = {
1656 .get_dqblk = gfs2_get_dqblk, 1646 .get_dqblk = gfs2_get_dqblk,
1657 .set_dqblk = gfs2_set_dqblk, 1647 .set_dqblk = gfs2_set_dqblk,
1658}; 1648};
1649
1650void __init gfs2_quota_hash_init(void)
1651{
1652 unsigned i;
1653
1654 for(i = 0; i < GFS2_QD_HASH_SIZE; i++)
1655 INIT_HLIST_BL_HEAD(&qd_hash_table[i]);
1656}
diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h
index 96e4f34a03b0..55d506eb3c4a 100644
--- a/fs/gfs2/quota.h
+++ b/fs/gfs2/quota.h
@@ -57,5 +57,6 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip)
57extern const struct quotactl_ops gfs2_quotactl_ops; 57extern const struct quotactl_ops gfs2_quotactl_ops;
58extern struct shrinker gfs2_qd_shrinker; 58extern struct shrinker gfs2_qd_shrinker;
59extern struct list_lru gfs2_qd_lru; 59extern struct list_lru gfs2_qd_lru;
60extern void __init gfs2_quota_hash_init(void);
60 61
61#endif /* __QUOTA_DOT_H__ */ 62#endif /* __QUOTA_DOT_H__ */
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index c8d6161bd682..a1da21349235 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -57,6 +57,11 @@
57 * 3 = Used (metadata) 57 * 3 = Used (metadata)
58 */ 58 */
59 59
60struct gfs2_extent {
61 struct gfs2_rbm rbm;
62 u32 len;
63};
64
60static const char valid_change[16] = { 65static const char valid_change[16] = {
61 /* current */ 66 /* current */
62 /* n */ 0, 1, 1, 1, 67 /* n */ 0, 1, 1, 1,
@@ -65,8 +70,9 @@ static const char valid_change[16] = {
65 1, 0, 0, 0 70 1, 0, 0, 0
66}; 71};
67 72
68static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, 73static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
69 const struct gfs2_inode *ip, bool nowrap); 74 const struct gfs2_inode *ip, bool nowrap,
75 const struct gfs2_alloc_parms *ap);
70 76
71 77
72/** 78/**
@@ -635,9 +641,13 @@ static void __rs_deltree(struct gfs2_blkreserv *rs)
635 /* return reserved blocks to the rgrp */ 641 /* return reserved blocks to the rgrp */
636 BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free); 642 BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free);
637 rs->rs_rbm.rgd->rd_reserved -= rs->rs_free; 643 rs->rs_rbm.rgd->rd_reserved -= rs->rs_free;
644 /* The rgrp extent failure point is likely not to increase;
645 it will only do so if the freed blocks are somehow
646 contiguous with a span of free blocks that follows. Still,
647 it will force the number to be recalculated later. */
648 rgd->rd_extfail_pt += rs->rs_free;
638 rs->rs_free = 0; 649 rs->rs_free = 0;
639 clear_bit(GBF_FULL, &bi->bi_flags); 650 clear_bit(GBF_FULL, &bi->bi_flags);
640 smp_mb__after_clear_bit();
641 } 651 }
642} 652}
643 653
@@ -876,6 +886,7 @@ static int rgd_insert(struct gfs2_rgrpd *rgd)
876static int read_rindex_entry(struct gfs2_inode *ip) 886static int read_rindex_entry(struct gfs2_inode *ip)
877{ 887{
878 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 888 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
889 const unsigned bsize = sdp->sd_sb.sb_bsize;
879 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex); 890 loff_t pos = sdp->sd_rgrps * sizeof(struct gfs2_rindex);
880 struct gfs2_rindex buf; 891 struct gfs2_rindex buf;
881 int error; 892 int error;
@@ -913,6 +924,8 @@ static int read_rindex_entry(struct gfs2_inode *ip)
913 goto fail; 924 goto fail;
914 925
915 rgd->rd_gl->gl_object = rgd; 926 rgd->rd_gl->gl_object = rgd;
927 rgd->rd_gl->gl_vm.start = rgd->rd_addr * bsize;
928 rgd->rd_gl->gl_vm.end = rgd->rd_gl->gl_vm.start + (rgd->rd_length * bsize) - 1;
916 rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr; 929 rgd->rd_rgl = (struct gfs2_rgrp_lvb *)rgd->rd_gl->gl_lksb.sb_lvbptr;
917 rgd->rd_flags &= ~GFS2_RDF_UPTODATE; 930 rgd->rd_flags &= ~GFS2_RDF_UPTODATE;
918 if (rgd->rd_data > sdp->sd_max_rg_data) 931 if (rgd->rd_data > sdp->sd_max_rg_data)
@@ -1126,6 +1139,8 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd)
1126 gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data); 1139 gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data);
1127 rgd->rd_flags |= (GFS2_RDF_UPTODATE | GFS2_RDF_CHECK); 1140 rgd->rd_flags |= (GFS2_RDF_UPTODATE | GFS2_RDF_CHECK);
1128 rgd->rd_free_clone = rgd->rd_free; 1141 rgd->rd_free_clone = rgd->rd_free;
1142 /* max out the rgrp allocation failure point */
1143 rgd->rd_extfail_pt = rgd->rd_free;
1129 } 1144 }
1130 if (cpu_to_be32(GFS2_MAGIC) != rgd->rd_rgl->rl_magic) { 1145 if (cpu_to_be32(GFS2_MAGIC) != rgd->rd_rgl->rl_magic) {
1131 rgd->rd_rgl->rl_unlinked = cpu_to_be32(count_unlinked(rgd)); 1146 rgd->rd_rgl->rl_unlinked = cpu_to_be32(count_unlinked(rgd));
@@ -1184,7 +1199,7 @@ int gfs2_rgrp_go_lock(struct gfs2_holder *gh)
1184 1199
1185 if (gh->gh_flags & GL_SKIP && sdp->sd_args.ar_rgrplvb) 1200 if (gh->gh_flags & GL_SKIP && sdp->sd_args.ar_rgrplvb)
1186 return 0; 1201 return 0;
1187 return gfs2_rgrp_bh_get((struct gfs2_rgrpd *)gh->gh_gl->gl_object); 1202 return gfs2_rgrp_bh_get(rgd);
1188} 1203}
1189 1204
1190/** 1205/**
@@ -1455,7 +1470,7 @@ static void rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip,
1455 if (WARN_ON(gfs2_rbm_from_block(&rbm, goal))) 1470 if (WARN_ON(gfs2_rbm_from_block(&rbm, goal)))
1456 return; 1471 return;
1457 1472
1458 ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, extlen, ip, true); 1473 ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &extlen, ip, true, ap);
1459 if (ret == 0) { 1474 if (ret == 0) {
1460 rs->rs_rbm = rbm; 1475 rs->rs_rbm = rbm;
1461 rs->rs_free = extlen; 1476 rs->rs_free = extlen;
@@ -1520,6 +1535,7 @@ static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block,
1520 * @rbm: The current position in the resource group 1535 * @rbm: The current position in the resource group
1521 * @ip: The inode for which we are searching for blocks 1536 * @ip: The inode for which we are searching for blocks
1522 * @minext: The minimum extent length 1537 * @minext: The minimum extent length
1538 * @maxext: A pointer to the maximum extent structure
1523 * 1539 *
1524 * This checks the current position in the rgrp to see whether there is 1540 * This checks the current position in the rgrp to see whether there is
1525 * a reservation covering this block. If not then this function is a 1541 * a reservation covering this block. If not then this function is a
@@ -1532,7 +1548,8 @@ static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block,
1532 1548
1533static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm, 1549static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,
1534 const struct gfs2_inode *ip, 1550 const struct gfs2_inode *ip,
1535 u32 minext) 1551 u32 minext,
1552 struct gfs2_extent *maxext)
1536{ 1553{
1537 u64 block = gfs2_rbm_to_block(rbm); 1554 u64 block = gfs2_rbm_to_block(rbm);
1538 u32 extlen = 1; 1555 u32 extlen = 1;
@@ -1545,8 +1562,7 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,
1545 */ 1562 */
1546 if (minext) { 1563 if (minext) {
1547 extlen = gfs2_free_extlen(rbm, minext); 1564 extlen = gfs2_free_extlen(rbm, minext);
1548 nblock = block + extlen; 1565 if (extlen <= maxext->len)
1549 if (extlen < minext)
1550 goto fail; 1566 goto fail;
1551 } 1567 }
1552 1568
@@ -1555,9 +1571,17 @@ static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm,
1555 * and skip if parts of it are already reserved 1571 * and skip if parts of it are already reserved
1556 */ 1572 */
1557 nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, ip); 1573 nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, ip);
1558 if (nblock == block) 1574 if (nblock == block) {
1559 return 0; 1575 if (!minext || extlen >= minext)
1576 return 0;
1577
1578 if (extlen > maxext->len) {
1579 maxext->len = extlen;
1580 maxext->rbm = *rbm;
1581 }
1560fail: 1582fail:
1583 nblock = block + extlen;
1584 }
1561 ret = gfs2_rbm_from_block(rbm, nblock); 1585 ret = gfs2_rbm_from_block(rbm, nblock);
1562 if (ret < 0) 1586 if (ret < 0)
1563 return ret; 1587 return ret;
@@ -1568,30 +1592,38 @@ fail:
1568 * gfs2_rbm_find - Look for blocks of a particular state 1592 * gfs2_rbm_find - Look for blocks of a particular state
1569 * @rbm: Value/result starting position and final position 1593 * @rbm: Value/result starting position and final position
1570 * @state: The state which we want to find 1594 * @state: The state which we want to find
1571 * @minext: The requested extent length (0 for a single block) 1595 * @minext: Pointer to the requested extent length (NULL for a single block)
1596 * This is updated to be the actual reservation size.
1572 * @ip: If set, check for reservations 1597 * @ip: If set, check for reservations
1573 * @nowrap: Stop looking at the end of the rgrp, rather than wrapping 1598 * @nowrap: Stop looking at the end of the rgrp, rather than wrapping
1574 * around until we've reached the starting point. 1599 * around until we've reached the starting point.
1600 * @ap: the allocation parameters
1575 * 1601 *
1576 * Side effects: 1602 * Side effects:
1577 * - If looking for free blocks, we set GBF_FULL on each bitmap which 1603 * - If looking for free blocks, we set GBF_FULL on each bitmap which
1578 * has no free blocks in it. 1604 * has no free blocks in it.
1605 * - If looking for free blocks, we set rd_extfail_pt on each rgrp which
1606 * has come up short on a free block search.
1579 * 1607 *
1580 * Returns: 0 on success, -ENOSPC if there is no block of the requested state 1608 * Returns: 0 on success, -ENOSPC if there is no block of the requested state
1581 */ 1609 */
1582 1610
1583static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, 1611static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 *minext,
1584 const struct gfs2_inode *ip, bool nowrap) 1612 const struct gfs2_inode *ip, bool nowrap,
1613 const struct gfs2_alloc_parms *ap)
1585{ 1614{
1586 struct buffer_head *bh; 1615 struct buffer_head *bh;
1587 int initial_bii; 1616 int initial_bii;
1588 u32 initial_offset; 1617 u32 initial_offset;
1618 int first_bii = rbm->bii;
1619 u32 first_offset = rbm->offset;
1589 u32 offset; 1620 u32 offset;
1590 u8 *buffer; 1621 u8 *buffer;
1591 int n = 0; 1622 int n = 0;
1592 int iters = rbm->rgd->rd_length; 1623 int iters = rbm->rgd->rd_length;
1593 int ret; 1624 int ret;
1594 struct gfs2_bitmap *bi; 1625 struct gfs2_bitmap *bi;
1626 struct gfs2_extent maxext = { .rbm.rgd = rbm->rgd, };
1595 1627
1596 /* If we are not starting at the beginning of a bitmap, then we 1628 /* If we are not starting at the beginning of a bitmap, then we
1597 * need to add one to the bitmap count to ensure that we search 1629 * need to add one to the bitmap count to ensure that we search
@@ -1620,7 +1652,9 @@ static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext,
1620 return 0; 1652 return 0;
1621 1653
1622 initial_bii = rbm->bii; 1654 initial_bii = rbm->bii;
1623 ret = gfs2_reservation_check_and_update(rbm, ip, minext); 1655 ret = gfs2_reservation_check_and_update(rbm, ip,
1656 minext ? *minext : 0,
1657 &maxext);
1624 if (ret == 0) 1658 if (ret == 0)
1625 return 0; 1659 return 0;
1626 if (ret > 0) { 1660 if (ret > 0) {
@@ -1655,6 +1689,24 @@ next_iter:
1655 break; 1689 break;
1656 } 1690 }
1657 1691
1692 if (minext == NULL || state != GFS2_BLKST_FREE)
1693 return -ENOSPC;
1694
1695 /* If the extent was too small, and it's smaller than the smallest
1696 to have failed before, remember for future reference that it's
1697 useless to search this rgrp again for this amount or more. */
1698 if ((first_offset == 0) && (first_bii == 0) &&
1699 (*minext < rbm->rgd->rd_extfail_pt))
1700 rbm->rgd->rd_extfail_pt = *minext;
1701
1702 /* If the maximum extent we found is big enough to fulfill the
1703 minimum requirements, use it anyway. */
1704 if (maxext.len) {
1705 *rbm = maxext.rbm;
1706 *minext = maxext.len;
1707 return 0;
1708 }
1709
1658 return -ENOSPC; 1710 return -ENOSPC;
1659} 1711}
1660 1712
@@ -1680,7 +1732,8 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
1680 1732
1681 while (1) { 1733 while (1) {
1682 down_write(&sdp->sd_log_flush_lock); 1734 down_write(&sdp->sd_log_flush_lock);
1683 error = gfs2_rbm_find(&rbm, GFS2_BLKST_UNLINKED, 0, NULL, true); 1735 error = gfs2_rbm_find(&rbm, GFS2_BLKST_UNLINKED, NULL, NULL,
1736 true, NULL);
1684 up_write(&sdp->sd_log_flush_lock); 1737 up_write(&sdp->sd_log_flush_lock);
1685 if (error == -ENOSPC) 1738 if (error == -ENOSPC)
1686 break; 1739 break;
@@ -1891,7 +1944,9 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *a
1891 } 1944 }
1892 1945
1893 /* Skip unuseable resource groups */ 1946 /* Skip unuseable resource groups */
1894 if (rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR)) 1947 if ((rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC |
1948 GFS2_RDF_ERROR)) ||
1949 (ap->target > rs->rs_rbm.rgd->rd_extfail_pt))
1895 goto skip_rgrp; 1950 goto skip_rgrp;
1896 1951
1897 if (sdp->sd_args.ar_rgrplvb) 1952 if (sdp->sd_args.ar_rgrplvb)
@@ -1911,15 +1966,16 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, const struct gfs2_alloc_parms *a
1911 return 0; 1966 return 0;
1912 } 1967 }
1913 1968
1914 /* Drop reservation, if we couldn't use reserved rgrp */
1915 if (gfs2_rs_active(rs))
1916 gfs2_rs_deltree(rs);
1917check_rgrp: 1969check_rgrp:
1918 /* Check for unlinked inodes which can be reclaimed */ 1970 /* Check for unlinked inodes which can be reclaimed */
1919 if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK) 1971 if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK)
1920 try_rgrp_unlink(rs->rs_rbm.rgd, &last_unlinked, 1972 try_rgrp_unlink(rs->rs_rbm.rgd, &last_unlinked,
1921 ip->i_no_addr); 1973 ip->i_no_addr);
1922skip_rgrp: 1974skip_rgrp:
1975 /* Drop reservation, if we couldn't use reserved rgrp */
1976 if (gfs2_rs_active(rs))
1977 gfs2_rs_deltree(rs);
1978
1923 /* Unlock rgrp if required */ 1979 /* Unlock rgrp if required */
1924 if (!rg_locked) 1980 if (!rg_locked)
1925 gfs2_glock_dq_uninit(&rs->rs_rgd_gh); 1981 gfs2_glock_dq_uninit(&rs->rs_rgd_gh);
@@ -2064,25 +2120,24 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
2064 * 2120 *
2065 */ 2121 */
2066 2122
2067int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl) 2123void gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl)
2068{ 2124{
2069 struct gfs2_rgrpd *rgd = gl->gl_object; 2125 struct gfs2_rgrpd *rgd = gl->gl_object;
2070 struct gfs2_blkreserv *trs; 2126 struct gfs2_blkreserv *trs;
2071 const struct rb_node *n; 2127 const struct rb_node *n;
2072 2128
2073 if (rgd == NULL) 2129 if (rgd == NULL)
2074 return 0; 2130 return;
2075 gfs2_print_dbg(seq, " R: n:%llu f:%02x b:%u/%u i:%u r:%u\n", 2131 gfs2_print_dbg(seq, " R: n:%llu f:%02x b:%u/%u i:%u r:%u e:%u\n",
2076 (unsigned long long)rgd->rd_addr, rgd->rd_flags, 2132 (unsigned long long)rgd->rd_addr, rgd->rd_flags,
2077 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes, 2133 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes,
2078 rgd->rd_reserved); 2134 rgd->rd_reserved, rgd->rd_extfail_pt);
2079 spin_lock(&rgd->rd_rsspin); 2135 spin_lock(&rgd->rd_rsspin);
2080 for (n = rb_first(&rgd->rd_rstree); n; n = rb_next(&trs->rs_node)) { 2136 for (n = rb_first(&rgd->rd_rstree); n; n = rb_next(&trs->rs_node)) {
2081 trs = rb_entry(n, struct gfs2_blkreserv, rs_node); 2137 trs = rb_entry(n, struct gfs2_blkreserv, rs_node);
2082 dump_rs(seq, trs); 2138 dump_rs(seq, trs);
2083 } 2139 }
2084 spin_unlock(&rgd->rd_rsspin); 2140 spin_unlock(&rgd->rd_rsspin);
2085 return 0;
2086} 2141}
2087 2142
2088static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd) 2143static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)
@@ -2184,18 +2239,20 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
2184 int error; 2239 int error;
2185 2240
2186 gfs2_set_alloc_start(&rbm, ip, dinode); 2241 gfs2_set_alloc_start(&rbm, ip, dinode);
2187 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false); 2242 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, NULL, ip, false, NULL);
2188 2243
2189 if (error == -ENOSPC) { 2244 if (error == -ENOSPC) {
2190 gfs2_set_alloc_start(&rbm, ip, dinode); 2245 gfs2_set_alloc_start(&rbm, ip, dinode);
2191 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false); 2246 error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, NULL, NULL, false,
2247 NULL);
2192 } 2248 }
2193 2249
2194 /* Since all blocks are reserved in advance, this shouldn't happen */ 2250 /* Since all blocks are reserved in advance, this shouldn't happen */
2195 if (error) { 2251 if (error) {
2196 fs_warn(sdp, "inum=%llu error=%d, nblocks=%u, full=%d\n", 2252 fs_warn(sdp, "inum=%llu error=%d, nblocks=%u, full=%d fail_pt=%d\n",
2197 (unsigned long long)ip->i_no_addr, error, *nblocks, 2253 (unsigned long long)ip->i_no_addr, error, *nblocks,
2198 test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags)); 2254 test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags),
2255 rbm.rgd->rd_extfail_pt);
2199 goto rgrp_error; 2256 goto rgrp_error;
2200 } 2257 }
2201 2258
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index 3a10d2ffbbe7..463ab2e95d1c 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -68,7 +68,7 @@ extern void gfs2_rlist_add(struct gfs2_inode *ip, struct gfs2_rgrp_list *rlist,
68extern void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state); 68extern void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state);
69extern void gfs2_rlist_free(struct gfs2_rgrp_list *rlist); 69extern void gfs2_rlist_free(struct gfs2_rgrp_list *rlist);
70extern u64 gfs2_ri_total(struct gfs2_sbd *sdp); 70extern u64 gfs2_ri_total(struct gfs2_sbd *sdp);
71extern int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl); 71extern void gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl);
72extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset, 72extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
73 struct buffer_head *bh, 73 struct buffer_head *bh,
74 const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed); 74 const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed);
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 35da5b19c0de..60f60f6181f3 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -369,6 +369,33 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
369 return 0; 369 return 0;
370} 370}
371 371
372static int init_threads(struct gfs2_sbd *sdp)
373{
374 struct task_struct *p;
375 int error = 0;
376
377 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
378 if (IS_ERR(p)) {
379 error = PTR_ERR(p);
380 fs_err(sdp, "can't start logd thread: %d\n", error);
381 return error;
382 }
383 sdp->sd_logd_process = p;
384
385 p = kthread_run(gfs2_quotad, sdp, "gfs2_quotad");
386 if (IS_ERR(p)) {
387 error = PTR_ERR(p);
388 fs_err(sdp, "can't start quotad thread: %d\n", error);
389 goto fail;
390 }
391 sdp->sd_quotad_process = p;
392 return 0;
393
394fail:
395 kthread_stop(sdp->sd_logd_process);
396 return error;
397}
398
372/** 399/**
373 * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one 400 * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
374 * @sdp: the filesystem 401 * @sdp: the filesystem
@@ -384,10 +411,14 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
384 struct gfs2_log_header_host head; 411 struct gfs2_log_header_host head;
385 int error; 412 int error;
386 413
387 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &t_gh); 414 error = init_threads(sdp);
388 if (error) 415 if (error)
389 return error; 416 return error;
390 417
418 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &t_gh);
419 if (error)
420 goto fail_threads;
421
391 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 422 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
392 423
393 error = gfs2_find_jhead(sdp->sd_jdesc, &head); 424 error = gfs2_find_jhead(sdp->sd_jdesc, &head);
@@ -417,7 +448,9 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
417fail: 448fail:
418 t_gh.gh_flags |= GL_NOCACHE; 449 t_gh.gh_flags |= GL_NOCACHE;
419 gfs2_glock_dq_uninit(&t_gh); 450 gfs2_glock_dq_uninit(&t_gh);
420 451fail_threads:
452 kthread_stop(sdp->sd_quotad_process);
453 kthread_stop(sdp->sd_logd_process);
421 return error; 454 return error;
422} 455}
423 456
@@ -800,6 +833,9 @@ static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
800 struct gfs2_holder t_gh; 833 struct gfs2_holder t_gh;
801 int error; 834 int error;
802 835
836 kthread_stop(sdp->sd_quotad_process);
837 kthread_stop(sdp->sd_logd_process);
838
803 flush_workqueue(gfs2_delete_workqueue); 839 flush_workqueue(gfs2_delete_workqueue);
804 gfs2_quota_sync(sdp->sd_vfs, 0); 840 gfs2_quota_sync(sdp->sd_vfs, 0);
805 gfs2_statfs_sync(sdp->sd_vfs, 0); 841 gfs2_statfs_sync(sdp->sd_vfs, 0);
@@ -857,9 +893,6 @@ restart:
857 } 893 }
858 spin_unlock(&sdp->sd_jindex_spin); 894 spin_unlock(&sdp->sd_jindex_spin);
859 895
860 kthread_stop(sdp->sd_quotad_process);
861 kthread_stop(sdp->sd_logd_process);
862
863 if (!(sb->s_flags & MS_RDONLY)) { 896 if (!(sb->s_flags & MS_RDONLY)) {
864 error = gfs2_make_fs_ro(sdp); 897 error = gfs2_make_fs_ro(sdp);
865 if (error) 898 if (error)
diff --git a/include/uapi/linux/gfs2_ondisk.h b/include/uapi/linux/gfs2_ondisk.h
index b2de1f9a88d6..0f24c07aed51 100644
--- a/include/uapi/linux/gfs2_ondisk.h
+++ b/include/uapi/linux/gfs2_ondisk.h
@@ -319,7 +319,16 @@ struct gfs2_leaf {
319 __be32 lf_dirent_format; /* Format of the dirents */ 319 __be32 lf_dirent_format; /* Format of the dirents */
320 __be64 lf_next; /* Next leaf, if overflow */ 320 __be64 lf_next; /* Next leaf, if overflow */
321 321
322 __u8 lf_reserved[64]; 322 union {
323 __u8 lf_reserved[64];
324 struct {
325 __be64 lf_inode; /* Dir inode number */
326 __be32 lf_dist; /* Dist from inode on chain */
327 __be32 lf_nsec; /* Last ins/del usecs */
328 __be64 lf_sec; /* Last ins/del in secs */
329 __u8 lf_reserved2[40];
330 };
331 };
323}; 332};
324 333
325/* 334/*