aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 21:00:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 21:00:03 -0400
commitad12ab259d9131a53aa11c7c4561d97f7cc900df (patch)
tree457e99e4c4b1facf029a6a094428eaef73f5d261
parent30d73f375238441d6dc31de0d90bc39f5bb0bfe5 (diff)
parent220cca2a4f5867db595135e0450381032eb54902 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw
Pull gfs2 changes from Steven Whitehouse. * git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw: GFS2: Change truncate page allocation to be GFP_NOFS GFS2: call gfs2_write_alloc_required for each chunk GFS2: Clean up log flush header writing GFS2: Remove a __GFP_NOFAIL allocation GFS2: Flush pending glock work when evicting an inode GFS2: make sure rgrps are up to date in func gfs2_blk2rgrpd GFS2: Eliminate sd_rindex_mutex GFS2: Unlock rindex mutex on glock error GFS2: Make bd_cmp() static GFS2: Sort the ordered write list GFS2: FITRIM ioctl support GFS2: Move two functions from log.c to lops.c GFS2: glock statistics gathering
-rw-r--r--fs/gfs2/bmap.c4
-rw-r--r--fs/gfs2/file.c15
-rw-r--r--fs/gfs2/glock.c210
-rw-r--r--fs/gfs2/incore.h50
-rw-r--r--fs/gfs2/inode.c4
-rw-r--r--fs/gfs2/lock_dlm.c123
-rw-r--r--fs/gfs2/log.c244
-rw-r--r--fs/gfs2/log.h5
-rw-r--r--fs/gfs2/lops.c95
-rw-r--r--fs/gfs2/main.c18
-rw-r--r--fs/gfs2/ops_fstype.c9
-rw-r--r--fs/gfs2/quota.c2
-rw-r--r--fs/gfs2/rgrp.c189
-rw-r--r--fs/gfs2/rgrp.h10
-rw-r--r--fs/gfs2/super.c3
-rw-r--r--fs/gfs2/trace_gfs2.h60
-rw-r--r--fs/gfs2/util.c1
-rw-r--r--fs/gfs2/util.h3
-rw-r--r--fs/gfs2/xattr.c4
-rw-r--r--include/linux/gfs2_ondisk.h1
20 files changed, 805 insertions, 245 deletions
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 14a704015970..197c5c47e577 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -60,7 +60,7 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
60 int release = 0; 60 int release = 0;
61 61
62 if (!page || page->index) { 62 if (!page || page->index) {
63 page = grab_cache_page(inode->i_mapping, 0); 63 page = find_or_create_page(inode->i_mapping, 0, GFP_NOFS);
64 if (!page) 64 if (!page)
65 return -ENOMEM; 65 return -ENOMEM;
66 release = 1; 66 release = 1;
@@ -930,7 +930,7 @@ static int gfs2_block_truncate_page(struct address_space *mapping, loff_t from)
930 struct page *page; 930 struct page *page;
931 int err; 931 int err;
932 932
933 page = grab_cache_page(mapping, index); 933 page = find_or_create_page(mapping, index, GFP_NOFS);
934 if (!page) 934 if (!page)
935 return 0; 935 return 0;
936 936
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
index c5fb3597f696..76834587a8a4 100644
--- a/fs/gfs2/file.c
+++ b/fs/gfs2/file.c
@@ -313,6 +313,8 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
313 return gfs2_get_flags(filp, (u32 __user *)arg); 313 return gfs2_get_flags(filp, (u32 __user *)arg);
314 case FS_IOC_SETFLAGS: 314 case FS_IOC_SETFLAGS:
315 return gfs2_set_flags(filp, (u32 __user *)arg); 315 return gfs2_set_flags(filp, (u32 __user *)arg);
316 case FITRIM:
317 return gfs2_fitrim(filp, (void __user *)arg);
316 } 318 }
317 return -ENOTTY; 319 return -ENOTTY;
318} 320}
@@ -674,6 +676,7 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
674 struct gfs2_inode *ip = GFS2_I(inode); 676 struct gfs2_inode *ip = GFS2_I(inode);
675 struct buffer_head *dibh; 677 struct buffer_head *dibh;
676 int error; 678 int error;
679 loff_t size = len;
677 unsigned int nr_blks; 680 unsigned int nr_blks;
678 sector_t lblock = offset >> inode->i_blkbits; 681 sector_t lblock = offset >> inode->i_blkbits;
679 682
@@ -707,8 +710,8 @@ static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
707 goto out; 710 goto out;
708 } 711 }
709 } 712 }
710 if (offset + len > inode->i_size && !(mode & FALLOC_FL_KEEP_SIZE)) 713 if (offset + size > inode->i_size && !(mode & FALLOC_FL_KEEP_SIZE))
711 i_size_write(inode, offset + len); 714 i_size_write(inode, offset + size);
712 715
713 mark_inode_dirty(inode); 716 mark_inode_dirty(inode);
714 717
@@ -777,12 +780,14 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset,
777 if (unlikely(error)) 780 if (unlikely(error))
778 goto out_uninit; 781 goto out_uninit;
779 782
780 if (!gfs2_write_alloc_required(ip, offset, len))
781 goto out_unlock;
782
783 while (len > 0) { 783 while (len > 0) {
784 if (len < bytes) 784 if (len < bytes)
785 bytes = len; 785 bytes = len;
786 if (!gfs2_write_alloc_required(ip, offset, bytes)) {
787 len -= bytes;
788 offset += bytes;
789 continue;
790 }
786 qa = gfs2_qadata_get(ip); 791 qa = gfs2_qadata_get(ip);
787 if (!qa) { 792 if (!qa) {
788 error = -ENOMEM; 793 error = -ENOMEM;
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 351a3e797789..dab2526071cc 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -29,6 +29,7 @@
29#include <linux/rcupdate.h> 29#include <linux/rcupdate.h>
30#include <linux/rculist_bl.h> 30#include <linux/rculist_bl.h>
31#include <linux/bit_spinlock.h> 31#include <linux/bit_spinlock.h>
32#include <linux/percpu.h>
32 33
33#include "gfs2.h" 34#include "gfs2.h"
34#include "incore.h" 35#include "incore.h"
@@ -543,6 +544,11 @@ __acquires(&gl->gl_spin)
543 do_error(gl, 0); /* Fail queued try locks */ 544 do_error(gl, 0); /* Fail queued try locks */
544 } 545 }
545 gl->gl_req = target; 546 gl->gl_req = target;
547 set_bit(GLF_BLOCKING, &gl->gl_flags);
548 if ((gl->gl_req == LM_ST_UNLOCKED) ||
549 (gl->gl_state == LM_ST_EXCLUSIVE) ||
550 (lck_flags & (LM_FLAG_TRY|LM_FLAG_TRY_1CB)))
551 clear_bit(GLF_BLOCKING, &gl->gl_flags);
546 spin_unlock(&gl->gl_spin); 552 spin_unlock(&gl->gl_spin);
547 if (glops->go_xmote_th) 553 if (glops->go_xmote_th)
548 glops->go_xmote_th(gl); 554 glops->go_xmote_th(gl);
@@ -744,6 +750,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
744 return -ENOMEM; 750 return -ENOMEM;
745 751
746 atomic_inc(&sdp->sd_glock_disposal); 752 atomic_inc(&sdp->sd_glock_disposal);
753 gl->gl_sbd = sdp;
747 gl->gl_flags = 0; 754 gl->gl_flags = 0;
748 gl->gl_name = name; 755 gl->gl_name = name;
749 atomic_set(&gl->gl_ref, 1); 756 atomic_set(&gl->gl_ref, 1);
@@ -752,12 +759,17 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
752 gl->gl_demote_state = LM_ST_EXCLUSIVE; 759 gl->gl_demote_state = LM_ST_EXCLUSIVE;
753 gl->gl_hash = hash; 760 gl->gl_hash = hash;
754 gl->gl_ops = glops; 761 gl->gl_ops = glops;
755 snprintf(gl->gl_strname, GDLM_STRNAME_BYTES, "%8x%16llx", name.ln_type, (unsigned long long)number); 762 gl->gl_dstamp = ktime_set(0, 0);
763 preempt_disable();
764 /* We use the global stats to estimate the initial per-glock stats */
765 gl->gl_stats = this_cpu_ptr(sdp->sd_lkstats)->lkstats[glops->go_type];
766 preempt_enable();
767 gl->gl_stats.stats[GFS2_LKS_DCOUNT] = 0;
768 gl->gl_stats.stats[GFS2_LKS_QCOUNT] = 0;
756 memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb)); 769 memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb));
757 gl->gl_lksb.sb_lvbptr = gl->gl_lvb; 770 gl->gl_lksb.sb_lvbptr = gl->gl_lvb;
758 gl->gl_tchange = jiffies; 771 gl->gl_tchange = jiffies;
759 gl->gl_object = NULL; 772 gl->gl_object = NULL;
760 gl->gl_sbd = sdp;
761 gl->gl_hold_time = GL_GLOCK_DFT_HOLD; 773 gl->gl_hold_time = GL_GLOCK_DFT_HOLD;
762 INIT_DELAYED_WORK(&gl->gl_work, glock_work_func); 774 INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
763 INIT_WORK(&gl->gl_delete, delete_work_func); 775 INIT_WORK(&gl->gl_delete, delete_work_func);
@@ -999,6 +1011,8 @@ fail:
999 } 1011 }
1000 set_bit(GLF_QUEUED, &gl->gl_flags); 1012 set_bit(GLF_QUEUED, &gl->gl_flags);
1001 trace_gfs2_glock_queue(gh, 1); 1013 trace_gfs2_glock_queue(gh, 1);
1014 gfs2_glstats_inc(gl, GFS2_LKS_QCOUNT);
1015 gfs2_sbstats_inc(gl, GFS2_LKS_QCOUNT);
1002 if (likely(insert_pt == NULL)) { 1016 if (likely(insert_pt == NULL)) {
1003 list_add_tail(&gh->gh_list, &gl->gl_holders); 1017 list_add_tail(&gh->gh_list, &gl->gl_holders);
1004 if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY)) 1018 if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY))
@@ -1658,6 +1672,8 @@ static const char *gflags2str(char *buf, const struct gfs2_glock *gl)
1658 *p++ = 'L'; 1672 *p++ = 'L';
1659 if (gl->gl_object) 1673 if (gl->gl_object)
1660 *p++ = 'o'; 1674 *p++ = 'o';
1675 if (test_bit(GLF_BLOCKING, gflags))
1676 *p++ = 'b';
1661 *p = 0; 1677 *p = 0;
1662 return buf; 1678 return buf;
1663} 1679}
@@ -1714,8 +1730,78 @@ out:
1714 return error; 1730 return error;
1715} 1731}
1716 1732
1733static int gfs2_glstats_seq_show(struct seq_file *seq, void *iter_ptr)
1734{
1735 struct gfs2_glock *gl = iter_ptr;
1736
1737 seq_printf(seq, "G: n:%u/%llx rtt:%lld/%lld rttb:%lld/%lld irt:%lld/%lld dcnt: %lld qcnt: %lld\n",
1738 gl->gl_name.ln_type,
1739 (unsigned long long)gl->gl_name.ln_number,
1740 (long long)gl->gl_stats.stats[GFS2_LKS_SRTT],
1741 (long long)gl->gl_stats.stats[GFS2_LKS_SRTTVAR],
1742 (long long)gl->gl_stats.stats[GFS2_LKS_SRTTB],
1743 (long long)gl->gl_stats.stats[GFS2_LKS_SRTTVARB],
1744 (long long)gl->gl_stats.stats[GFS2_LKS_SIRT],
1745 (long long)gl->gl_stats.stats[GFS2_LKS_SIRTVAR],
1746 (long long)gl->gl_stats.stats[GFS2_LKS_DCOUNT],
1747 (long long)gl->gl_stats.stats[GFS2_LKS_QCOUNT]);
1748 return 0;
1749}
1750
1751static const char *gfs2_gltype[] = {
1752 "type",
1753 "reserved",
1754 "nondisk",
1755 "inode",
1756 "rgrp",
1757 "meta",
1758 "iopen",
1759 "flock",
1760 "plock",
1761 "quota",
1762 "journal",
1763};
1764
1765static const char *gfs2_stype[] = {
1766 [GFS2_LKS_SRTT] = "srtt",
1767 [GFS2_LKS_SRTTVAR] = "srttvar",
1768 [GFS2_LKS_SRTTB] = "srttb",
1769 [GFS2_LKS_SRTTVARB] = "srttvarb",
1770 [GFS2_LKS_SIRT] = "sirt",
1771 [GFS2_LKS_SIRTVAR] = "sirtvar",
1772 [GFS2_LKS_DCOUNT] = "dlm",
1773 [GFS2_LKS_QCOUNT] = "queue",
1774};
1775
1776#define GFS2_NR_SBSTATS (ARRAY_SIZE(gfs2_gltype) * ARRAY_SIZE(gfs2_stype))
1777
1778static int gfs2_sbstats_seq_show(struct seq_file *seq, void *iter_ptr)
1779{
1780 struct gfs2_glock_iter *gi = seq->private;
1781 struct gfs2_sbd *sdp = gi->sdp;
1782 unsigned index = gi->hash >> 3;
1783 unsigned subindex = gi->hash & 0x07;
1784 s64 value;
1785 int i;
1786
1787 if (index == 0 && subindex != 0)
1788 return 0;
1717 1789
1790 seq_printf(seq, "%-10s %8s:", gfs2_gltype[index],
1791 (index == 0) ? "cpu": gfs2_stype[subindex]);
1718 1792
1793 for_each_possible_cpu(i) {
1794 const struct gfs2_pcpu_lkstats *lkstats = per_cpu_ptr(sdp->sd_lkstats, i);
1795 if (index == 0) {
1796 value = i;
1797 } else {
1798 value = lkstats->lkstats[index - 1].stats[subindex];
1799 }
1800 seq_printf(seq, " %15lld", (long long)value);
1801 }
1802 seq_putc(seq, '\n');
1803 return 0;
1804}
1719 1805
1720int __init gfs2_glock_init(void) 1806int __init gfs2_glock_init(void)
1721{ 1807{
@@ -1828,6 +1914,35 @@ static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr)
1828 return dump_glock(seq, iter_ptr); 1914 return dump_glock(seq, iter_ptr);
1829} 1915}
1830 1916
1917static void *gfs2_sbstats_seq_start(struct seq_file *seq, loff_t *pos)
1918{
1919 struct gfs2_glock_iter *gi = seq->private;
1920
1921 gi->hash = *pos;
1922 if (*pos >= GFS2_NR_SBSTATS)
1923 return NULL;
1924 preempt_disable();
1925 return SEQ_START_TOKEN;
1926}
1927
1928static void *gfs2_sbstats_seq_next(struct seq_file *seq, void *iter_ptr,
1929 loff_t *pos)
1930{
1931 struct gfs2_glock_iter *gi = seq->private;
1932 (*pos)++;
1933 gi->hash++;
1934 if (gi->hash >= GFS2_NR_SBSTATS) {
1935 preempt_enable();
1936 return NULL;
1937 }
1938 return SEQ_START_TOKEN;
1939}
1940
1941static void gfs2_sbstats_seq_stop(struct seq_file *seq, void *iter_ptr)
1942{
1943 preempt_enable();
1944}
1945
1831static const struct seq_operations gfs2_glock_seq_ops = { 1946static const struct seq_operations gfs2_glock_seq_ops = {
1832 .start = gfs2_glock_seq_start, 1947 .start = gfs2_glock_seq_start,
1833 .next = gfs2_glock_seq_next, 1948 .next = gfs2_glock_seq_next,
@@ -1835,7 +1950,21 @@ static const struct seq_operations gfs2_glock_seq_ops = {
1835 .show = gfs2_glock_seq_show, 1950 .show = gfs2_glock_seq_show,
1836}; 1951};
1837 1952
1838static int gfs2_debugfs_open(struct inode *inode, struct file *file) 1953static const struct seq_operations gfs2_glstats_seq_ops = {
1954 .start = gfs2_glock_seq_start,
1955 .next = gfs2_glock_seq_next,
1956 .stop = gfs2_glock_seq_stop,
1957 .show = gfs2_glstats_seq_show,
1958};
1959
1960static const struct seq_operations gfs2_sbstats_seq_ops = {
1961 .start = gfs2_sbstats_seq_start,
1962 .next = gfs2_sbstats_seq_next,
1963 .stop = gfs2_sbstats_seq_stop,
1964 .show = gfs2_sbstats_seq_show,
1965};
1966
1967static int gfs2_glocks_open(struct inode *inode, struct file *file)
1839{ 1968{
1840 int ret = seq_open_private(file, &gfs2_glock_seq_ops, 1969 int ret = seq_open_private(file, &gfs2_glock_seq_ops,
1841 sizeof(struct gfs2_glock_iter)); 1970 sizeof(struct gfs2_glock_iter));
@@ -1847,9 +1976,49 @@ static int gfs2_debugfs_open(struct inode *inode, struct file *file)
1847 return ret; 1976 return ret;
1848} 1977}
1849 1978
1850static const struct file_operations gfs2_debug_fops = { 1979static int gfs2_glstats_open(struct inode *inode, struct file *file)
1980{
1981 int ret = seq_open_private(file, &gfs2_glstats_seq_ops,
1982 sizeof(struct gfs2_glock_iter));
1983 if (ret == 0) {
1984 struct seq_file *seq = file->private_data;
1985 struct gfs2_glock_iter *gi = seq->private;
1986 gi->sdp = inode->i_private;
1987 }
1988 return ret;
1989}
1990
1991static int gfs2_sbstats_open(struct inode *inode, struct file *file)
1992{
1993 int ret = seq_open_private(file, &gfs2_sbstats_seq_ops,
1994 sizeof(struct gfs2_glock_iter));
1995 if (ret == 0) {
1996 struct seq_file *seq = file->private_data;
1997 struct gfs2_glock_iter *gi = seq->private;
1998 gi->sdp = inode->i_private;
1999 }
2000 return ret;
2001}
2002
2003static const struct file_operations gfs2_glocks_fops = {
2004 .owner = THIS_MODULE,
2005 .open = gfs2_glocks_open,
2006 .read = seq_read,
2007 .llseek = seq_lseek,
2008 .release = seq_release_private,
2009};
2010
2011static const struct file_operations gfs2_glstats_fops = {
1851 .owner = THIS_MODULE, 2012 .owner = THIS_MODULE,
1852 .open = gfs2_debugfs_open, 2013 .open = gfs2_glstats_open,
2014 .read = seq_read,
2015 .llseek = seq_lseek,
2016 .release = seq_release_private,
2017};
2018
2019static const struct file_operations gfs2_sbstats_fops = {
2020 .owner = THIS_MODULE,
2021 .open = gfs2_sbstats_open,
1853 .read = seq_read, 2022 .read = seq_read,
1854 .llseek = seq_lseek, 2023 .llseek = seq_lseek,
1855 .release = seq_release_private, 2024 .release = seq_release_private,
@@ -1863,20 +2032,45 @@ int gfs2_create_debugfs_file(struct gfs2_sbd *sdp)
1863 sdp->debugfs_dentry_glocks = debugfs_create_file("glocks", 2032 sdp->debugfs_dentry_glocks = debugfs_create_file("glocks",
1864 S_IFREG | S_IRUGO, 2033 S_IFREG | S_IRUGO,
1865 sdp->debugfs_dir, sdp, 2034 sdp->debugfs_dir, sdp,
1866 &gfs2_debug_fops); 2035 &gfs2_glocks_fops);
1867 if (!sdp->debugfs_dentry_glocks) 2036 if (!sdp->debugfs_dentry_glocks)
1868 return -ENOMEM; 2037 goto fail;
2038
2039 sdp->debugfs_dentry_glstats = debugfs_create_file("glstats",
2040 S_IFREG | S_IRUGO,
2041 sdp->debugfs_dir, sdp,
2042 &gfs2_glstats_fops);
2043 if (!sdp->debugfs_dentry_glstats)
2044 goto fail;
2045
2046 sdp->debugfs_dentry_sbstats = debugfs_create_file("sbstats",
2047 S_IFREG | S_IRUGO,
2048 sdp->debugfs_dir, sdp,
2049 &gfs2_sbstats_fops);
2050 if (!sdp->debugfs_dentry_sbstats)
2051 goto fail;
1869 2052
1870 return 0; 2053 return 0;
2054fail:
2055 gfs2_delete_debugfs_file(sdp);
2056 return -ENOMEM;
1871} 2057}
1872 2058
1873void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp) 2059void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp)
1874{ 2060{
1875 if (sdp && sdp->debugfs_dir) { 2061 if (sdp->debugfs_dir) {
1876 if (sdp->debugfs_dentry_glocks) { 2062 if (sdp->debugfs_dentry_glocks) {
1877 debugfs_remove(sdp->debugfs_dentry_glocks); 2063 debugfs_remove(sdp->debugfs_dentry_glocks);
1878 sdp->debugfs_dentry_glocks = NULL; 2064 sdp->debugfs_dentry_glocks = NULL;
1879 } 2065 }
2066 if (sdp->debugfs_dentry_glstats) {
2067 debugfs_remove(sdp->debugfs_dentry_glstats);
2068 sdp->debugfs_dentry_glstats = NULL;
2069 }
2070 if (sdp->debugfs_dentry_sbstats) {
2071 debugfs_remove(sdp->debugfs_dentry_sbstats);
2072 sdp->debugfs_dentry_sbstats = NULL;
2073 }
1880 debugfs_remove(sdp->debugfs_dir); 2074 debugfs_remove(sdp->debugfs_dir);
1881 sdp->debugfs_dir = NULL; 2075 sdp->debugfs_dir = NULL;
1882 } 2076 }
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 97742a7ea9cc..47d0bda5ac2b 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -19,6 +19,8 @@
19#include <linux/rculist_bl.h> 19#include <linux/rculist_bl.h>
20#include <linux/completion.h> 20#include <linux/completion.h>
21#include <linux/rbtree.h> 21#include <linux/rbtree.h>
22#include <linux/ktime.h>
23#include <linux/percpu.h>
22 24
23#define DIO_WAIT 0x00000010 25#define DIO_WAIT 0x00000010
24#define DIO_METADATA 0x00000020 26#define DIO_METADATA 0x00000020
@@ -205,6 +207,22 @@ struct gfs2_glock_operations {
205}; 207};
206 208
207enum { 209enum {
210 GFS2_LKS_SRTT = 0, /* Non blocking smoothed round trip time */
211 GFS2_LKS_SRTTVAR = 1, /* Non blocking smoothed variance */
212 GFS2_LKS_SRTTB = 2, /* Blocking smoothed round trip time */
213 GFS2_LKS_SRTTVARB = 3, /* Blocking smoothed variance */
214 GFS2_LKS_SIRT = 4, /* Smoothed Inter-request time */
215 GFS2_LKS_SIRTVAR = 5, /* Smoothed Inter-request variance */
216 GFS2_LKS_DCOUNT = 6, /* Count of dlm requests */
217 GFS2_LKS_QCOUNT = 7, /* Count of gfs2_holder queues */
218 GFS2_NR_LKSTATS
219};
220
221struct gfs2_lkstats {
222 s64 stats[GFS2_NR_LKSTATS];
223};
224
225enum {
208 /* States */ 226 /* States */
209 HIF_HOLDER = 6, /* Set for gh that "holds" the glock */ 227 HIF_HOLDER = 6, /* Set for gh that "holds" the glock */
210 HIF_FIRST = 7, 228 HIF_FIRST = 7,
@@ -238,10 +256,12 @@ enum {
238 GLF_QUEUED = 12, 256 GLF_QUEUED = 12,
239 GLF_LRU = 13, 257 GLF_LRU = 13,
240 GLF_OBJECT = 14, /* Used only for tracing */ 258 GLF_OBJECT = 14, /* Used only for tracing */
259 GLF_BLOCKING = 15,
241}; 260};
242 261
243struct gfs2_glock { 262struct gfs2_glock {
244 struct hlist_bl_node gl_list; 263 struct hlist_bl_node gl_list;
264 struct gfs2_sbd *gl_sbd;
245 unsigned long gl_flags; /* GLF_... */ 265 unsigned long gl_flags; /* GLF_... */
246 struct lm_lockname gl_name; 266 struct lm_lockname gl_name;
247 atomic_t gl_ref; 267 atomic_t gl_ref;
@@ -261,16 +281,14 @@ struct gfs2_glock {
261 struct list_head gl_holders; 281 struct list_head gl_holders;
262 282
263 const struct gfs2_glock_operations *gl_ops; 283 const struct gfs2_glock_operations *gl_ops;
264 char gl_strname[GDLM_STRNAME_BYTES]; 284 ktime_t gl_dstamp;
285 struct gfs2_lkstats gl_stats;
265 struct dlm_lksb gl_lksb; 286 struct dlm_lksb gl_lksb;
266 char gl_lvb[32]; 287 char gl_lvb[32];
267 unsigned long gl_tchange; 288 unsigned long gl_tchange;
268 void *gl_object; 289 void *gl_object;
269 290
270 struct list_head gl_lru; 291 struct list_head gl_lru;
271
272 struct gfs2_sbd *gl_sbd;
273
274 struct list_head gl_ail_list; 292 struct list_head gl_ail_list;
275 atomic_t gl_ail_count; 293 atomic_t gl_ail_count;
276 atomic_t gl_revokes; 294 atomic_t gl_revokes;
@@ -560,8 +578,14 @@ struct lm_lockstruct {
560 uint32_t *ls_recover_result; /* result of last jid recovery */ 578 uint32_t *ls_recover_result; /* result of last jid recovery */
561}; 579};
562 580
581struct gfs2_pcpu_lkstats {
582 /* One struct for each glock type */
583 struct gfs2_lkstats lkstats[10];
584};
585
563struct gfs2_sbd { 586struct gfs2_sbd {
564 struct super_block *sd_vfs; 587 struct super_block *sd_vfs;
588 struct gfs2_pcpu_lkstats __percpu *sd_lkstats;
565 struct kobject sd_kobj; 589 struct kobject sd_kobj;
566 unsigned long sd_flags; /* SDF_... */ 590 unsigned long sd_flags; /* SDF_... */
567 struct gfs2_sb_host sd_sb; 591 struct gfs2_sb_host sd_sb;
@@ -620,7 +644,6 @@ struct gfs2_sbd {
620 644
621 int sd_rindex_uptodate; 645 int sd_rindex_uptodate;
622 spinlock_t sd_rindex_spin; 646 spinlock_t sd_rindex_spin;
623 struct mutex sd_rindex_mutex;
624 struct rb_root sd_rindex_tree; 647 struct rb_root sd_rindex_tree;
625 unsigned int sd_rgrps; 648 unsigned int sd_rgrps;
626 unsigned int sd_max_rg_data; 649 unsigned int sd_max_rg_data;
@@ -725,8 +748,23 @@ struct gfs2_sbd {
725 748
726 unsigned long sd_last_warning; 749 unsigned long sd_last_warning;
727 struct dentry *debugfs_dir; /* debugfs directory */ 750 struct dentry *debugfs_dir; /* debugfs directory */
728 struct dentry *debugfs_dentry_glocks; /* for debugfs */ 751 struct dentry *debugfs_dentry_glocks;
752 struct dentry *debugfs_dentry_glstats;
753 struct dentry *debugfs_dentry_sbstats;
729}; 754};
730 755
756static inline void gfs2_glstats_inc(struct gfs2_glock *gl, int which)
757{
758 gl->gl_stats.stats[which]++;
759}
760
761static inline void gfs2_sbstats_inc(const struct gfs2_glock *gl, int which)
762{
763 const struct gfs2_sbd *sdp = gl->gl_sbd;
764 preempt_disable();
765 this_cpu_ptr(sdp->sd_lkstats)->lkstats[gl->gl_name.ln_type].stats[which]++;
766 preempt_enable();
767}
768
731#endif /* __INCORE_DOT_H__ */ 769#endif /* __INCORE_DOT_H__ */
732 770
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 56987460cdae..c98a60ee6dfd 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -1036,7 +1036,7 @@ static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
1036 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 1036 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
1037 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1); 1037 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
1038 1038
1039 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); 1039 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1);
1040 if (!rgd) 1040 if (!rgd)
1041 goto out_inodes; 1041 goto out_inodes;
1042 1042
@@ -1255,7 +1255,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
1255 * this is the case of the target file already existing 1255 * this is the case of the target file already existing
1256 * so we unlink before doing the rename 1256 * so we unlink before doing the rename
1257 */ 1257 */
1258 nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr); 1258 nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr, 1);
1259 if (nrgd) 1259 if (nrgd)
1260 gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++); 1260 gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
1261 } 1261 }
diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c
index 8944d1e32ab5..f8411bd1b805 100644
--- a/fs/gfs2/lock_dlm.c
+++ b/fs/gfs2/lock_dlm.c
@@ -18,14 +18,106 @@
18#include "glock.h" 18#include "glock.h"
19#include "util.h" 19#include "util.h"
20#include "sys.h" 20#include "sys.h"
21#include "trace_gfs2.h"
21 22
22extern struct workqueue_struct *gfs2_control_wq; 23extern struct workqueue_struct *gfs2_control_wq;
23 24
25/**
26 * gfs2_update_stats - Update time based stats
27 * @mv: Pointer to mean/variance structure to update
28 * @sample: New data to include
29 *
30 * @delta is the difference between the current rtt sample and the
31 * running average srtt. We add 1/8 of that to the srtt in order to
32 * update the current srtt estimate. The varience estimate is a bit
33 * more complicated. We subtract the abs value of the @delta from
34 * the current variance estimate and add 1/4 of that to the running
35 * total.
36 *
37 * Note that the index points at the array entry containing the smoothed
38 * mean value, and the variance is always in the following entry
39 *
40 * Reference: TCP/IP Illustrated, vol 2, p. 831,832
41 * All times are in units of integer nanoseconds. Unlike the TCP/IP case,
42 * they are not scaled fixed point.
43 */
44
45static inline void gfs2_update_stats(struct gfs2_lkstats *s, unsigned index,
46 s64 sample)
47{
48 s64 delta = sample - s->stats[index];
49 s->stats[index] += (delta >> 3);
50 index++;
51 s->stats[index] += ((abs64(delta) - s->stats[index]) >> 2);
52}
53
54/**
55 * gfs2_update_reply_times - Update locking statistics
56 * @gl: The glock to update
57 *
58 * This assumes that gl->gl_dstamp has been set earlier.
59 *
60 * The rtt (lock round trip time) is an estimate of the time
61 * taken to perform a dlm lock request. We update it on each
62 * reply from the dlm.
63 *
64 * The blocking flag is set on the glock for all dlm requests
65 * which may potentially block due to lock requests from other nodes.
66 * DLM requests where the current lock state is exclusive, the
67 * requested state is null (or unlocked) or where the TRY or
68 * TRY_1CB flags are set are classified as non-blocking. All
69 * other DLM requests are counted as (potentially) blocking.
70 */
71static inline void gfs2_update_reply_times(struct gfs2_glock *gl)
72{
73 struct gfs2_pcpu_lkstats *lks;
74 const unsigned gltype = gl->gl_name.ln_type;
75 unsigned index = test_bit(GLF_BLOCKING, &gl->gl_flags) ?
76 GFS2_LKS_SRTTB : GFS2_LKS_SRTT;
77 s64 rtt;
78
79 preempt_disable();
80 rtt = ktime_to_ns(ktime_sub(ktime_get_real(), gl->gl_dstamp));
81 lks = this_cpu_ptr(gl->gl_sbd->sd_lkstats);
82 gfs2_update_stats(&gl->gl_stats, index, rtt); /* Local */
83 gfs2_update_stats(&lks->lkstats[gltype], index, rtt); /* Global */
84 preempt_enable();
85
86 trace_gfs2_glock_lock_time(gl, rtt);
87}
88
89/**
90 * gfs2_update_request_times - Update locking statistics
91 * @gl: The glock to update
92 *
93 * The irt (lock inter-request times) measures the average time
94 * between requests to the dlm. It is updated immediately before
95 * each dlm call.
96 */
97
98static inline void gfs2_update_request_times(struct gfs2_glock *gl)
99{
100 struct gfs2_pcpu_lkstats *lks;
101 const unsigned gltype = gl->gl_name.ln_type;
102 ktime_t dstamp;
103 s64 irt;
104
105 preempt_disable();
106 dstamp = gl->gl_dstamp;
107 gl->gl_dstamp = ktime_get_real();
108 irt = ktime_to_ns(ktime_sub(gl->gl_dstamp, dstamp));
109 lks = this_cpu_ptr(gl->gl_sbd->sd_lkstats);
110 gfs2_update_stats(&gl->gl_stats, GFS2_LKS_SIRT, irt); /* Local */
111 gfs2_update_stats(&lks->lkstats[gltype], GFS2_LKS_SIRT, irt); /* Global */
112 preempt_enable();
113}
114
24static void gdlm_ast(void *arg) 115static void gdlm_ast(void *arg)
25{ 116{
26 struct gfs2_glock *gl = arg; 117 struct gfs2_glock *gl = arg;
27 unsigned ret = gl->gl_state; 118 unsigned ret = gl->gl_state;
28 119
120 gfs2_update_reply_times(gl);
29 BUG_ON(gl->gl_lksb.sb_flags & DLM_SBF_DEMOTED); 121 BUG_ON(gl->gl_lksb.sb_flags & DLM_SBF_DEMOTED);
30 122
31 if (gl->gl_lksb.sb_flags & DLM_SBF_VALNOTVALID) 123 if (gl->gl_lksb.sb_flags & DLM_SBF_VALNOTVALID)
@@ -111,7 +203,7 @@ static int make_mode(const unsigned int lmstate)
111static u32 make_flags(const u32 lkid, const unsigned int gfs_flags, 203static u32 make_flags(const u32 lkid, const unsigned int gfs_flags,
112 const int req) 204 const int req)
113{ 205{
114 u32 lkf = 0; 206 u32 lkf = DLM_LKF_VALBLK;
115 207
116 if (gfs_flags & LM_FLAG_TRY) 208 if (gfs_flags & LM_FLAG_TRY)
117 lkf |= DLM_LKF_NOQUEUE; 209 lkf |= DLM_LKF_NOQUEUE;
@@ -138,26 +230,43 @@ static u32 make_flags(const u32 lkid, const unsigned int gfs_flags,
138 if (lkid != 0) 230 if (lkid != 0)
139 lkf |= DLM_LKF_CONVERT; 231 lkf |= DLM_LKF_CONVERT;
140 232
141 lkf |= DLM_LKF_VALBLK;
142
143 return lkf; 233 return lkf;
144} 234}
145 235
236static void gfs2_reverse_hex(char *c, u64 value)
237{
238 while (value) {
239 *c-- = hex_asc[value & 0x0f];
240 value >>= 4;
241 }
242}
243
146static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state, 244static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
147 unsigned int flags) 245 unsigned int flags)
148{ 246{
149 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct; 247 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
150 int req; 248 int req;
151 u32 lkf; 249 u32 lkf;
250 char strname[GDLM_STRNAME_BYTES] = "";
152 251
153 req = make_mode(req_state); 252 req = make_mode(req_state);
154 lkf = make_flags(gl->gl_lksb.sb_lkid, flags, req); 253 lkf = make_flags(gl->gl_lksb.sb_lkid, flags, req);
155 254 gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
255 gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
256 if (gl->gl_lksb.sb_lkid) {
257 gfs2_update_request_times(gl);
258 } else {
259 memset(strname, ' ', GDLM_STRNAME_BYTES - 1);
260 strname[GDLM_STRNAME_BYTES - 1] = '\0';
261 gfs2_reverse_hex(strname + 7, gl->gl_name.ln_type);
262 gfs2_reverse_hex(strname + 23, gl->gl_name.ln_number);
263 gl->gl_dstamp = ktime_get_real();
264 }
156 /* 265 /*
157 * Submit the actual lock request. 266 * Submit the actual lock request.
158 */ 267 */
159 268
160 return dlm_lock(ls->ls_dlm, req, &gl->gl_lksb, lkf, gl->gl_strname, 269 return dlm_lock(ls->ls_dlm, req, &gl->gl_lksb, lkf, strname,
161 GDLM_STRNAME_BYTES - 1, 0, gdlm_ast, gl, gdlm_bast); 270 GDLM_STRNAME_BYTES - 1, 0, gdlm_ast, gl, gdlm_bast);
162} 271}
163 272
@@ -172,6 +281,10 @@ static void gdlm_put_lock(struct gfs2_glock *gl)
172 return; 281 return;
173 } 282 }
174 283
284 clear_bit(GLF_BLOCKING, &gl->gl_flags);
285 gfs2_glstats_inc(gl, GFS2_LKS_DCOUNT);
286 gfs2_sbstats_inc(gl, GFS2_LKS_DCOUNT);
287 gfs2_update_request_times(gl);
175 error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_VALBLK, 288 error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_VALBLK,
176 NULL, gl); 289 NULL, gl);
177 if (error) { 290 if (error) {
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 756fae9eaf8f..4752eadc7f6e 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -19,6 +19,7 @@
19#include <linux/freezer.h> 19#include <linux/freezer.h>
20#include <linux/bio.h> 20#include <linux/bio.h>
21#include <linux/writeback.h> 21#include <linux/writeback.h>
22#include <linux/list_sort.h>
22 23
23#include "gfs2.h" 24#include "gfs2.h"
24#include "incore.h" 25#include "incore.h"
@@ -358,7 +359,7 @@ retry:
358 return 0; 359 return 0;
359} 360}
360 361
361static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) 362u64 gfs2_log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
362{ 363{
363 struct gfs2_journal_extent *je; 364 struct gfs2_journal_extent *je;
364 365
@@ -467,8 +468,8 @@ static unsigned int current_tail(struct gfs2_sbd *sdp)
467 468
468void gfs2_log_incr_head(struct gfs2_sbd *sdp) 469void gfs2_log_incr_head(struct gfs2_sbd *sdp)
469{ 470{
470 if (sdp->sd_log_flush_head == sdp->sd_log_tail) 471 BUG_ON((sdp->sd_log_flush_head == sdp->sd_log_tail) &&
471 BUG_ON(sdp->sd_log_flush_head != sdp->sd_log_head); 472 (sdp->sd_log_flush_head != sdp->sd_log_head));
472 473
473 if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) { 474 if (++sdp->sd_log_flush_head == sdp->sd_jdesc->jd_blocks) {
474 sdp->sd_log_flush_head = 0; 475 sdp->sd_log_flush_head = 0;
@@ -476,99 +477,6 @@ void gfs2_log_incr_head(struct gfs2_sbd *sdp)
476 } 477 }
477} 478}
478 479
479/**
480 * gfs2_log_write_endio - End of I/O for a log buffer
481 * @bh: The buffer head
482 * @uptodate: I/O Status
483 *
484 */
485
486static void gfs2_log_write_endio(struct buffer_head *bh, int uptodate)
487{
488 struct gfs2_sbd *sdp = bh->b_private;
489 bh->b_private = NULL;
490
491 end_buffer_write_sync(bh, uptodate);
492 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
493 wake_up(&sdp->sd_log_flush_wait);
494}
495
496/**
497 * gfs2_log_get_buf - Get and initialize a buffer to use for log control data
498 * @sdp: The GFS2 superblock
499 *
500 * Returns: the buffer_head
501 */
502
503struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp)
504{
505 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
506 struct buffer_head *bh;
507
508 bh = sb_getblk(sdp->sd_vfs, blkno);
509 lock_buffer(bh);
510 memset(bh->b_data, 0, bh->b_size);
511 set_buffer_uptodate(bh);
512 clear_buffer_dirty(bh);
513 gfs2_log_incr_head(sdp);
514 atomic_inc(&sdp->sd_log_in_flight);
515 bh->b_private = sdp;
516 bh->b_end_io = gfs2_log_write_endio;
517
518 return bh;
519}
520
521/**
522 * gfs2_fake_write_endio -
523 * @bh: The buffer head
524 * @uptodate: The I/O Status
525 *
526 */
527
528static void gfs2_fake_write_endio(struct buffer_head *bh, int uptodate)
529{
530 struct buffer_head *real_bh = bh->b_private;
531 struct gfs2_bufdata *bd = real_bh->b_private;
532 struct gfs2_sbd *sdp = bd->bd_gl->gl_sbd;
533
534 end_buffer_write_sync(bh, uptodate);
535 free_buffer_head(bh);
536 unlock_buffer(real_bh);
537 brelse(real_bh);
538 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
539 wake_up(&sdp->sd_log_flush_wait);
540}
541
542/**
543 * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log
544 * @sdp: the filesystem
545 * @data: the data the buffer_head should point to
546 *
547 * Returns: the log buffer descriptor
548 */
549
550struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
551 struct buffer_head *real)
552{
553 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
554 struct buffer_head *bh;
555
556 bh = alloc_buffer_head(GFP_NOFS | __GFP_NOFAIL);
557 atomic_set(&bh->b_count, 1);
558 bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate) | (1 << BH_Lock);
559 set_bh_page(bh, real->b_page, bh_offset(real));
560 bh->b_blocknr = blkno;
561 bh->b_size = sdp->sd_sb.sb_bsize;
562 bh->b_bdev = sdp->sd_vfs->s_bdev;
563 bh->b_private = real;
564 bh->b_end_io = gfs2_fake_write_endio;
565
566 gfs2_log_incr_head(sdp);
567 atomic_inc(&sdp->sd_log_in_flight);
568
569 return bh;
570}
571
572static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail) 480static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail)
573{ 481{
574 unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail); 482 unsigned int dist = log_distance(sdp, new_tail, sdp->sd_log_tail);
@@ -583,66 +491,8 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail)
583 sdp->sd_log_tail = new_tail; 491 sdp->sd_log_tail = new_tail;
584} 492}
585 493
586/**
587 * log_write_header - Get and initialize a journal header buffer
588 * @sdp: The GFS2 superblock
589 *
590 * Returns: the initialized log buffer descriptor
591 */
592 494
593static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull) 495static void log_flush_wait(struct gfs2_sbd *sdp)
594{
595 u64 blkno = log_bmap(sdp, sdp->sd_log_flush_head);
596 struct buffer_head *bh;
597 struct gfs2_log_header *lh;
598 unsigned int tail;
599 u32 hash;
600
601 bh = sb_getblk(sdp->sd_vfs, blkno);
602 lock_buffer(bh);
603 memset(bh->b_data, 0, bh->b_size);
604 set_buffer_uptodate(bh);
605 clear_buffer_dirty(bh);
606
607 gfs2_ail1_empty(sdp);
608 tail = current_tail(sdp);
609
610 lh = (struct gfs2_log_header *)bh->b_data;
611 memset(lh, 0, sizeof(struct gfs2_log_header));
612 lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
613 lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
614 lh->lh_header.__pad0 = cpu_to_be64(0);
615 lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
616 lh->lh_header.mh_jid = cpu_to_be32(sdp->sd_jdesc->jd_jid);
617 lh->lh_sequence = cpu_to_be64(sdp->sd_log_sequence++);
618 lh->lh_flags = cpu_to_be32(flags);
619 lh->lh_tail = cpu_to_be32(tail);
620 lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head);
621 hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
622 lh->lh_hash = cpu_to_be32(hash);
623
624 bh->b_end_io = end_buffer_write_sync;
625 get_bh(bh);
626 if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags))
627 submit_bh(WRITE_SYNC | REQ_META | REQ_PRIO, bh);
628 else
629 submit_bh(WRITE_FLUSH_FUA | REQ_META, bh);
630 wait_on_buffer(bh);
631
632 if (!buffer_uptodate(bh))
633 gfs2_io_error_bh(sdp, bh);
634 brelse(bh);
635
636 if (sdp->sd_log_tail != tail)
637 log_pull_tail(sdp, tail);
638 else
639 gfs2_assert_withdraw(sdp, !pull);
640
641 sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
642 gfs2_log_incr_head(sdp);
643}
644
645static void log_flush_commit(struct gfs2_sbd *sdp)
646{ 496{
647 DEFINE_WAIT(wait); 497 DEFINE_WAIT(wait);
648 498
@@ -655,8 +505,20 @@ static void log_flush_commit(struct gfs2_sbd *sdp)
655 } while(atomic_read(&sdp->sd_log_in_flight)); 505 } while(atomic_read(&sdp->sd_log_in_flight));
656 finish_wait(&sdp->sd_log_flush_wait, &wait); 506 finish_wait(&sdp->sd_log_flush_wait, &wait);
657 } 507 }
508}
509
510static int bd_cmp(void *priv, struct list_head *a, struct list_head *b)
511{
512 struct gfs2_bufdata *bda, *bdb;
658 513
659 log_write_header(sdp, 0, 0); 514 bda = list_entry(a, struct gfs2_bufdata, bd_le.le_list);
515 bdb = list_entry(b, struct gfs2_bufdata, bd_le.le_list);
516
517 if (bda->bd_bh->b_blocknr < bdb->bd_bh->b_blocknr)
518 return -1;
519 if (bda->bd_bh->b_blocknr > bdb->bd_bh->b_blocknr)
520 return 1;
521 return 0;
660} 522}
661 523
662static void gfs2_ordered_write(struct gfs2_sbd *sdp) 524static void gfs2_ordered_write(struct gfs2_sbd *sdp)
@@ -666,6 +528,7 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp)
666 LIST_HEAD(written); 528 LIST_HEAD(written);
667 529
668 gfs2_log_lock(sdp); 530 gfs2_log_lock(sdp);
531 list_sort(NULL, &sdp->sd_log_le_ordered, &bd_cmp);
669 while (!list_empty(&sdp->sd_log_le_ordered)) { 532 while (!list_empty(&sdp->sd_log_le_ordered)) {
670 bd = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_bufdata, bd_le.le_list); 533 bd = list_entry(sdp->sd_log_le_ordered.next, struct gfs2_bufdata, bd_le.le_list);
671 list_move(&bd->bd_le.le_list, &written); 534 list_move(&bd->bd_le.le_list, &written);
@@ -711,6 +574,68 @@ static void gfs2_ordered_wait(struct gfs2_sbd *sdp)
711} 574}
712 575
713/** 576/**
577 * log_write_header - Get and initialize a journal header buffer
578 * @sdp: The GFS2 superblock
579 *
580 * Returns: the initialized log buffer descriptor
581 */
582
583static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull)
584{
585 u64 blkno = gfs2_log_bmap(sdp, sdp->sd_log_flush_head);
586 struct buffer_head *bh;
587 struct gfs2_log_header *lh;
588 unsigned int tail;
589 u32 hash;
590
591 bh = sb_getblk(sdp->sd_vfs, blkno);
592 lock_buffer(bh);
593 memset(bh->b_data, 0, bh->b_size);
594 set_buffer_uptodate(bh);
595 clear_buffer_dirty(bh);
596
597 gfs2_ail1_empty(sdp);
598 tail = current_tail(sdp);
599
600 lh = (struct gfs2_log_header *)bh->b_data;
601 memset(lh, 0, sizeof(struct gfs2_log_header));
602 lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
603 lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH);
604 lh->lh_header.__pad0 = cpu_to_be64(0);
605 lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH);
606 lh->lh_header.mh_jid = cpu_to_be32(sdp->sd_jdesc->jd_jid);
607 lh->lh_sequence = cpu_to_be64(sdp->sd_log_sequence++);
608 lh->lh_flags = cpu_to_be32(flags);
609 lh->lh_tail = cpu_to_be32(tail);
610 lh->lh_blkno = cpu_to_be32(sdp->sd_log_flush_head);
611 hash = gfs2_disk_hash(bh->b_data, sizeof(struct gfs2_log_header));
612 lh->lh_hash = cpu_to_be32(hash);
613
614 bh->b_end_io = end_buffer_write_sync;
615 get_bh(bh);
616 if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) {
617 gfs2_ordered_wait(sdp);
618 log_flush_wait(sdp);
619 submit_bh(WRITE_SYNC | REQ_META | REQ_PRIO, bh);
620 } else {
621 submit_bh(WRITE_FLUSH_FUA | REQ_META, bh);
622 }
623 wait_on_buffer(bh);
624
625 if (!buffer_uptodate(bh))
626 gfs2_io_error_bh(sdp, bh);
627 brelse(bh);
628
629 if (sdp->sd_log_tail != tail)
630 log_pull_tail(sdp, tail);
631 else
632 gfs2_assert_withdraw(sdp, !pull);
633
634 sdp->sd_log_idle = (tail == sdp->sd_log_flush_head);
635 gfs2_log_incr_head(sdp);
636}
637
638/**
714 * gfs2_log_flush - flush incore transaction(s) 639 * gfs2_log_flush - flush incore transaction(s)
715 * @sdp: the filesystem 640 * @sdp: the filesystem
716 * @gl: The glock structure to flush. If NULL, flush the whole incore log 641 * @gl: The glock structure to flush. If NULL, flush the whole incore log
@@ -753,11 +678,10 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
753 678
754 gfs2_ordered_write(sdp); 679 gfs2_ordered_write(sdp);
755 lops_before_commit(sdp); 680 lops_before_commit(sdp);
756 gfs2_ordered_wait(sdp);
757 681
758 if (sdp->sd_log_head != sdp->sd_log_flush_head) 682 if (sdp->sd_log_head != sdp->sd_log_flush_head) {
759 log_flush_commit(sdp); 683 log_write_header(sdp, 0, 0);
760 else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){ 684 } else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){
761 gfs2_log_lock(sdp); 685 gfs2_log_lock(sdp);
762 atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */ 686 atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */
763 trace_gfs2_log_blocks(sdp, -1); 687 trace_gfs2_log_blocks(sdp, -1);
diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h
index ab0621698b73..ff07454b582c 100644
--- a/fs/gfs2/log.h
+++ b/fs/gfs2/log.h
@@ -53,10 +53,7 @@ extern unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
53 53
54extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks); 54extern int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
55extern void gfs2_log_incr_head(struct gfs2_sbd *sdp); 55extern void gfs2_log_incr_head(struct gfs2_sbd *sdp);
56 56extern u64 gfs2_log_bmap(struct gfs2_sbd *sdp, unsigned int lbn);
57extern struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp);
58extern struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
59 struct buffer_head *real);
60extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl); 57extern void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl);
61extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans); 58extern void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
62extern void gfs2_remove_from_ail(struct gfs2_bufdata *bd); 59extern void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index df7c6e8d0764..6b1efb594d90 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -12,6 +12,7 @@
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/completion.h> 13#include <linux/completion.h>
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/mempool.h>
15#include <linux/gfs2_ondisk.h> 16#include <linux/gfs2_ondisk.h>
16#include <linux/bio.h> 17#include <linux/bio.h>
17#include <linux/fs.h> 18#include <linux/fs.h>
@@ -76,7 +77,7 @@ static void maybe_release_space(struct gfs2_bufdata *bd)
76 if (bi->bi_clone == 0) 77 if (bi->bi_clone == 0)
77 return; 78 return;
78 if (sdp->sd_args.ar_discard) 79 if (sdp->sd_args.ar_discard)
79 gfs2_rgrp_send_discards(sdp, rgd->rd_data0, bd->bd_bh, bi); 80 gfs2_rgrp_send_discards(sdp, rgd->rd_data0, bd->bd_bh, bi, 1, NULL);
80 memcpy(bi->bi_clone + bi->bi_offset, 81 memcpy(bi->bi_clone + bi->bi_offset,
81 bd->bd_bh->b_data + bi->bi_offset, bi->bi_len); 82 bd->bd_bh->b_data + bi->bi_offset, bi->bi_len);
82 clear_bit(GBF_FULL, &bi->bi_flags); 83 clear_bit(GBF_FULL, &bi->bi_flags);
@@ -143,6 +144,98 @@ static inline __be64 *bh_ptr_end(struct buffer_head *bh)
143 return (__force __be64 *)(bh->b_data + bh->b_size); 144 return (__force __be64 *)(bh->b_data + bh->b_size);
144} 145}
145 146
147/**
148 * gfs2_log_write_endio - End of I/O for a log buffer
149 * @bh: The buffer head
150 * @uptodate: I/O Status
151 *
152 */
153
154static void gfs2_log_write_endio(struct buffer_head *bh, int uptodate)
155{
156 struct gfs2_sbd *sdp = bh->b_private;
157 bh->b_private = NULL;
158
159 end_buffer_write_sync(bh, uptodate);
160 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
161 wake_up(&sdp->sd_log_flush_wait);
162}
163
164/**
165 * gfs2_log_get_buf - Get and initialize a buffer to use for log control data
166 * @sdp: The GFS2 superblock
167 *
168 * tReturns: the buffer_head
169 */
170
171static struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp)
172{
173 u64 blkno = gfs2_log_bmap(sdp, sdp->sd_log_flush_head);
174 struct buffer_head *bh;
175
176 bh = sb_getblk(sdp->sd_vfs, blkno);
177 lock_buffer(bh);
178 memset(bh->b_data, 0, bh->b_size);
179 set_buffer_uptodate(bh);
180 clear_buffer_dirty(bh);
181 gfs2_log_incr_head(sdp);
182 atomic_inc(&sdp->sd_log_in_flight);
183 bh->b_private = sdp;
184 bh->b_end_io = gfs2_log_write_endio;
185
186 return bh;
187}
188
189/**
190 * gfs2_fake_write_endio -
191 * @bh: The buffer head
192 * @uptodate: The I/O Status
193 *
194 */
195
196static void gfs2_fake_write_endio(struct buffer_head *bh, int uptodate)
197{
198 struct buffer_head *real_bh = bh->b_private;
199 struct gfs2_bufdata *bd = real_bh->b_private;
200 struct gfs2_sbd *sdp = bd->bd_gl->gl_sbd;
201
202 end_buffer_write_sync(bh, uptodate);
203 mempool_free(bh, gfs2_bh_pool);
204 unlock_buffer(real_bh);
205 brelse(real_bh);
206 if (atomic_dec_and_test(&sdp->sd_log_in_flight))
207 wake_up(&sdp->sd_log_flush_wait);
208}
209
210/**
211 * gfs2_log_fake_buf - Build a fake buffer head to write metadata buffer to log
212 * @sdp: the filesystem
213 * @data: the data the buffer_head should point to
214 *
215 * Returns: the log buffer descriptor
216 */
217
218static struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
219 struct buffer_head *real)
220{
221 u64 blkno = gfs2_log_bmap(sdp, sdp->sd_log_flush_head);
222 struct buffer_head *bh;
223
224 bh = mempool_alloc(gfs2_bh_pool, GFP_NOFS);
225 atomic_set(&bh->b_count, 1);
226 bh->b_state = (1 << BH_Mapped) | (1 << BH_Uptodate) | (1 << BH_Lock);
227 set_bh_page(bh, real->b_page, bh_offset(real));
228 bh->b_blocknr = blkno;
229 bh->b_size = sdp->sd_sb.sb_bsize;
230 bh->b_bdev = sdp->sd_vfs->s_bdev;
231 bh->b_private = real;
232 bh->b_end_io = gfs2_fake_write_endio;
233
234 gfs2_log_incr_head(sdp);
235 atomic_inc(&sdp->sd_log_in_flight);
236
237 return bh;
238}
146 239
147static struct buffer_head *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type) 240static struct buffer_head *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type)
148{ 241{
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index a8d9bcd0e19c..754426b1e52c 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -17,6 +17,7 @@
17#include <linux/rcupdate.h> 17#include <linux/rcupdate.h>
18#include <linux/rculist_bl.h> 18#include <linux/rculist_bl.h>
19#include <linux/atomic.h> 19#include <linux/atomic.h>
20#include <linux/mempool.h>
20 21
21#include "gfs2.h" 22#include "gfs2.h"
22#include "incore.h" 23#include "incore.h"
@@ -69,6 +70,16 @@ static void gfs2_init_gl_aspace_once(void *foo)
69 address_space_init_once(mapping); 70 address_space_init_once(mapping);
70} 71}
71 72
73static void *gfs2_bh_alloc(gfp_t mask, void *data)
74{
75 return alloc_buffer_head(mask);
76}
77
78static void gfs2_bh_free(void *ptr, void *data)
79{
80 return free_buffer_head(ptr);
81}
82
72/** 83/**
73 * init_gfs2_fs - Register GFS2 as a filesystem 84 * init_gfs2_fs - Register GFS2 as a filesystem
74 * 85 *
@@ -151,6 +162,10 @@ static int __init init_gfs2_fs(void)
151 gfs2_control_wq = alloc_workqueue("gfs2_control", 162 gfs2_control_wq = alloc_workqueue("gfs2_control",
152 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_FREEZABLE, 0); 163 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_FREEZABLE, 0);
153 if (!gfs2_control_wq) 164 if (!gfs2_control_wq)
165 goto fail_recovery;
166
167 gfs2_bh_pool = mempool_create(1024, gfs2_bh_alloc, gfs2_bh_free, NULL);
168 if (!gfs2_bh_pool)
154 goto fail_control; 169 goto fail_control;
155 170
156 gfs2_register_debugfs(); 171 gfs2_register_debugfs();
@@ -160,6 +175,8 @@ static int __init init_gfs2_fs(void)
160 return 0; 175 return 0;
161 176
162fail_control: 177fail_control:
178 destroy_workqueue(gfs2_control_wq);
179fail_recovery:
163 destroy_workqueue(gfs_recovery_wq); 180 destroy_workqueue(gfs_recovery_wq);
164fail_wq: 181fail_wq:
165 unregister_filesystem(&gfs2meta_fs_type); 182 unregister_filesystem(&gfs2meta_fs_type);
@@ -208,6 +225,7 @@ static void __exit exit_gfs2_fs(void)
208 225
209 rcu_barrier(); 226 rcu_barrier();
210 227
228 mempool_destroy(gfs2_bh_pool);
211 kmem_cache_destroy(gfs2_quotad_cachep); 229 kmem_cache_destroy(gfs2_quotad_cachep);
212 kmem_cache_destroy(gfs2_rgrpd_cachep); 230 kmem_cache_destroy(gfs2_rgrpd_cachep);
213 kmem_cache_destroy(gfs2_bufdata_cachep); 231 kmem_cache_destroy(gfs2_bufdata_cachep);
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 10e848c6d1b5..6f3a18f9e176 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -68,6 +68,12 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
68 68
69 sb->s_fs_info = sdp; 69 sb->s_fs_info = sdp;
70 sdp->sd_vfs = sb; 70 sdp->sd_vfs = sb;
71 sdp->sd_lkstats = alloc_percpu(struct gfs2_pcpu_lkstats);
72 if (!sdp->sd_lkstats) {
73 kfree(sdp);
74 return NULL;
75 }
76
71 set_bit(SDF_NOJOURNALID, &sdp->sd_flags); 77 set_bit(SDF_NOJOURNALID, &sdp->sd_flags);
72 gfs2_tune_init(&sdp->sd_tune); 78 gfs2_tune_init(&sdp->sd_tune);
73 79
@@ -77,7 +83,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
77 spin_lock_init(&sdp->sd_statfs_spin); 83 spin_lock_init(&sdp->sd_statfs_spin);
78 84
79 spin_lock_init(&sdp->sd_rindex_spin); 85 spin_lock_init(&sdp->sd_rindex_spin);
80 mutex_init(&sdp->sd_rindex_mutex);
81 sdp->sd_rindex_tree.rb_node = NULL; 86 sdp->sd_rindex_tree.rb_node = NULL;
82 87
83 INIT_LIST_HEAD(&sdp->sd_jindex_list); 88 INIT_LIST_HEAD(&sdp->sd_jindex_list);
@@ -1220,6 +1225,7 @@ fail_sys:
1220 gfs2_sys_fs_del(sdp); 1225 gfs2_sys_fs_del(sdp);
1221fail: 1226fail:
1222 gfs2_delete_debugfs_file(sdp); 1227 gfs2_delete_debugfs_file(sdp);
1228 free_percpu(sdp->sd_lkstats);
1223 kfree(sdp); 1229 kfree(sdp);
1224 sb->s_fs_info = NULL; 1230 sb->s_fs_info = NULL;
1225 return error; 1231 return error;
@@ -1392,6 +1398,7 @@ static void gfs2_kill_sb(struct super_block *sb)
1392 shrink_dcache_sb(sb); 1398 shrink_dcache_sb(sb);
1393 kill_block_super(sb); 1399 kill_block_super(sb);
1394 gfs2_delete_debugfs_file(sdp); 1400 gfs2_delete_debugfs_file(sdp);
1401 free_percpu(sdp->sd_lkstats);
1395 kfree(sdp); 1402 kfree(sdp);
1396} 1403}
1397 1404
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index c0f8904f0860..6019da3dcaed 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -681,7 +681,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
681 ptr = qp; 681 ptr = qp;
682 nbytes = sizeof(struct gfs2_quota); 682 nbytes = sizeof(struct gfs2_quota);
683get_a_page: 683get_a_page:
684 page = grab_cache_page(mapping, index); 684 page = find_or_create_page(mapping, index, GFP_NOFS);
685 if (!page) 685 if (!page)
686 return -ENOMEM; 686 return -ENOMEM;
687 687
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 49ada95209d0..19bde40b4864 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -327,23 +327,34 @@ static inline int rgrp_contains_block(struct gfs2_rgrpd *rgd, u64 block)
327 * Returns: The resource group, or NULL if not found 327 * Returns: The resource group, or NULL if not found
328 */ 328 */
329 329
330struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk) 330struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk, bool exact)
331{ 331{
332 struct rb_node **newn; 332 struct rb_node *n, *next;
333 struct gfs2_rgrpd *cur; 333 struct gfs2_rgrpd *cur;
334 334
335 if (gfs2_rindex_update(sdp))
336 return NULL;
337
335 spin_lock(&sdp->sd_rindex_spin); 338 spin_lock(&sdp->sd_rindex_spin);
336 newn = &sdp->sd_rindex_tree.rb_node; 339 n = sdp->sd_rindex_tree.rb_node;
337 while (*newn) { 340 while (n) {
338 cur = rb_entry(*newn, struct gfs2_rgrpd, rd_node); 341 cur = rb_entry(n, struct gfs2_rgrpd, rd_node);
342 next = NULL;
339 if (blk < cur->rd_addr) 343 if (blk < cur->rd_addr)
340 newn = &((*newn)->rb_left); 344 next = n->rb_left;
341 else if (blk >= cur->rd_data0 + cur->rd_data) 345 else if (blk >= cur->rd_data0 + cur->rd_data)
342 newn = &((*newn)->rb_right); 346 next = n->rb_right;
343 else { 347 if (next == NULL) {
344 spin_unlock(&sdp->sd_rindex_spin); 348 spin_unlock(&sdp->sd_rindex_spin);
349 if (exact) {
350 if (blk < cur->rd_addr)
351 return NULL;
352 if (blk >= cur->rd_data0 + cur->rd_data)
353 return NULL;
354 }
345 return cur; 355 return cur;
346 } 356 }
357 n = next;
347 } 358 }
348 spin_unlock(&sdp->sd_rindex_spin); 359 spin_unlock(&sdp->sd_rindex_spin);
349 360
@@ -532,7 +543,6 @@ u64 gfs2_ri_total(struct gfs2_sbd *sdp)
532 struct file_ra_state ra_state; 543 struct file_ra_state ra_state;
533 int error, rgrps; 544 int error, rgrps;
534 545
535 mutex_lock(&sdp->sd_rindex_mutex);
536 file_ra_state_init(&ra_state, inode->i_mapping); 546 file_ra_state_init(&ra_state, inode->i_mapping);
537 for (rgrps = 0;; rgrps++) { 547 for (rgrps = 0;; rgrps++) {
538 loff_t pos = rgrps * sizeof(struct gfs2_rindex); 548 loff_t pos = rgrps * sizeof(struct gfs2_rindex);
@@ -545,11 +555,10 @@ u64 gfs2_ri_total(struct gfs2_sbd *sdp)
545 break; 555 break;
546 total_data += be32_to_cpu(((struct gfs2_rindex *)buf)->ri_data); 556 total_data += be32_to_cpu(((struct gfs2_rindex *)buf)->ri_data);
547 } 557 }
548 mutex_unlock(&sdp->sd_rindex_mutex);
549 return total_data; 558 return total_data;
550} 559}
551 560
552static void rgd_insert(struct gfs2_rgrpd *rgd) 561static int rgd_insert(struct gfs2_rgrpd *rgd)
553{ 562{
554 struct gfs2_sbd *sdp = rgd->rd_sbd; 563 struct gfs2_sbd *sdp = rgd->rd_sbd;
555 struct rb_node **newn = &sdp->sd_rindex_tree.rb_node, *parent = NULL; 564 struct rb_node **newn = &sdp->sd_rindex_tree.rb_node, *parent = NULL;
@@ -565,11 +574,13 @@ static void rgd_insert(struct gfs2_rgrpd *rgd)
565 else if (rgd->rd_addr > cur->rd_addr) 574 else if (rgd->rd_addr > cur->rd_addr)
566 newn = &((*newn)->rb_right); 575 newn = &((*newn)->rb_right);
567 else 576 else
568 return; 577 return -EEXIST;
569 } 578 }
570 579
571 rb_link_node(&rgd->rd_node, parent, newn); 580 rb_link_node(&rgd->rd_node, parent, newn);
572 rb_insert_color(&rgd->rd_node, &sdp->sd_rindex_tree); 581 rb_insert_color(&rgd->rd_node, &sdp->sd_rindex_tree);
582 sdp->sd_rgrps++;
583 return 0;
573} 584}
574 585
575/** 586/**
@@ -623,10 +634,12 @@ static int read_rindex_entry(struct gfs2_inode *ip,
623 if (rgd->rd_data > sdp->sd_max_rg_data) 634 if (rgd->rd_data > sdp->sd_max_rg_data)
624 sdp->sd_max_rg_data = rgd->rd_data; 635 sdp->sd_max_rg_data = rgd->rd_data;
625 spin_lock(&sdp->sd_rindex_spin); 636 spin_lock(&sdp->sd_rindex_spin);
626 rgd_insert(rgd); 637 error = rgd_insert(rgd);
627 sdp->sd_rgrps++;
628 spin_unlock(&sdp->sd_rindex_spin); 638 spin_unlock(&sdp->sd_rindex_spin);
629 return error; 639 if (!error)
640 return 0;
641
642 error = 0; /* someone else read in the rgrp; free it and ignore it */
630 643
631fail: 644fail:
632 kfree(rgd->rd_bits); 645 kfree(rgd->rd_bits);
@@ -687,7 +700,6 @@ int gfs2_rindex_update(struct gfs2_sbd *sdp)
687 700
688 /* Read new copy from disk if we don't have the latest */ 701 /* Read new copy from disk if we don't have the latest */
689 if (!sdp->sd_rindex_uptodate) { 702 if (!sdp->sd_rindex_uptodate) {
690 mutex_lock(&sdp->sd_rindex_mutex);
691 if (!gfs2_glock_is_locked_by_me(gl)) { 703 if (!gfs2_glock_is_locked_by_me(gl)) {
692 error = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &ri_gh); 704 error = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &ri_gh);
693 if (error) 705 if (error)
@@ -698,10 +710,8 @@ int gfs2_rindex_update(struct gfs2_sbd *sdp)
698 error = gfs2_ri_update(ip); 710 error = gfs2_ri_update(ip);
699 if (unlock_required) 711 if (unlock_required)
700 gfs2_glock_dq_uninit(&ri_gh); 712 gfs2_glock_dq_uninit(&ri_gh);
701 mutex_unlock(&sdp->sd_rindex_mutex);
702 } 713 }
703 714
704
705 return error; 715 return error;
706} 716}
707 717
@@ -810,9 +820,9 @@ void gfs2_rgrp_go_unlock(struct gfs2_holder *gh)
810 820
811} 821}
812 822
813void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset, 823int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
814 struct buffer_head *bh, 824 struct buffer_head *bh,
815 const struct gfs2_bitmap *bi) 825 const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed)
816{ 826{
817 struct super_block *sb = sdp->sd_vfs; 827 struct super_block *sb = sdp->sd_vfs;
818 struct block_device *bdev = sb->s_bdev; 828 struct block_device *bdev = sb->s_bdev;
@@ -823,11 +833,19 @@ void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
823 sector_t nr_sects = 0; 833 sector_t nr_sects = 0;
824 int rv; 834 int rv;
825 unsigned int x; 835 unsigned int x;
836 u32 trimmed = 0;
837 u8 diff;
826 838
827 for (x = 0; x < bi->bi_len; x++) { 839 for (x = 0; x < bi->bi_len; x++) {
828 const u8 *orig = bh->b_data + bi->bi_offset + x; 840 const u8 *clone = bi->bi_clone ? bi->bi_clone : bi->bi_bh->b_data;
829 const u8 *clone = bi->bi_clone + bi->bi_offset + x; 841 clone += bi->bi_offset;
830 u8 diff = ~(*orig | (*orig >> 1)) & (*clone | (*clone >> 1)); 842 clone += x;
843 if (bh) {
844 const u8 *orig = bh->b_data + bi->bi_offset + x;
845 diff = ~(*orig | (*orig >> 1)) & (*clone | (*clone >> 1));
846 } else {
847 diff = ~(*clone | (*clone >> 1));
848 }
831 diff &= 0x55; 849 diff &= 0x55;
832 if (diff == 0) 850 if (diff == 0)
833 continue; 851 continue;
@@ -838,11 +856,14 @@ void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
838 if (nr_sects == 0) 856 if (nr_sects == 0)
839 goto start_new_extent; 857 goto start_new_extent;
840 if ((start + nr_sects) != blk) { 858 if ((start + nr_sects) != blk) {
841 rv = blkdev_issue_discard(bdev, start, 859 if (nr_sects >= minlen) {
842 nr_sects, GFP_NOFS, 860 rv = blkdev_issue_discard(bdev,
843 0); 861 start, nr_sects,
844 if (rv) 862 GFP_NOFS, 0);
845 goto fail; 863 if (rv)
864 goto fail;
865 trimmed += nr_sects;
866 }
846 nr_sects = 0; 867 nr_sects = 0;
847start_new_extent: 868start_new_extent:
848 start = blk; 869 start = blk;
@@ -853,15 +874,104 @@ start_new_extent:
853 blk += sects_per_blk; 874 blk += sects_per_blk;
854 } 875 }
855 } 876 }
856 if (nr_sects) { 877 if (nr_sects >= minlen) {
857 rv = blkdev_issue_discard(bdev, start, nr_sects, GFP_NOFS, 0); 878 rv = blkdev_issue_discard(bdev, start, nr_sects, GFP_NOFS, 0);
858 if (rv) 879 if (rv)
859 goto fail; 880 goto fail;
881 trimmed += nr_sects;
860 } 882 }
861 return; 883 if (ptrimmed)
884 *ptrimmed = trimmed;
885 return 0;
886
862fail: 887fail:
863 fs_warn(sdp, "error %d on discard request, turning discards off for this filesystem", rv); 888 if (sdp->sd_args.ar_discard)
889 fs_warn(sdp, "error %d on discard request, turning discards off for this filesystem", rv);
864 sdp->sd_args.ar_discard = 0; 890 sdp->sd_args.ar_discard = 0;
891 return -EIO;
892}
893
894/**
895 * gfs2_fitrim - Generate discard requests for unused bits of the filesystem
896 * @filp: Any file on the filesystem
897 * @argp: Pointer to the arguments (also used to pass result)
898 *
899 * Returns: 0 on success, otherwise error code
900 */
901
902int gfs2_fitrim(struct file *filp, void __user *argp)
903{
904 struct inode *inode = filp->f_dentry->d_inode;
905 struct gfs2_sbd *sdp = GFS2_SB(inode);
906 struct request_queue *q = bdev_get_queue(sdp->sd_vfs->s_bdev);
907 struct buffer_head *bh;
908 struct gfs2_rgrpd *rgd;
909 struct gfs2_rgrpd *rgd_end;
910 struct gfs2_holder gh;
911 struct fstrim_range r;
912 int ret = 0;
913 u64 amt;
914 u64 trimmed = 0;
915 unsigned int x;
916
917 if (!capable(CAP_SYS_ADMIN))
918 return -EPERM;
919
920 if (!blk_queue_discard(q))
921 return -EOPNOTSUPP;
922
923 if (argp == NULL) {
924 r.start = 0;
925 r.len = ULLONG_MAX;
926 r.minlen = 0;
927 } else if (copy_from_user(&r, argp, sizeof(r)))
928 return -EFAULT;
929
930 rgd = gfs2_blk2rgrpd(sdp, r.start, 0);
931 rgd_end = gfs2_blk2rgrpd(sdp, r.start + r.len, 0);
932
933 while (1) {
934
935 ret = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, &gh);
936 if (ret)
937 goto out;
938
939 if (!(rgd->rd_flags & GFS2_RGF_TRIMMED)) {
940 /* Trim each bitmap in the rgrp */
941 for (x = 0; x < rgd->rd_length; x++) {
942 struct gfs2_bitmap *bi = rgd->rd_bits + x;
943 ret = gfs2_rgrp_send_discards(sdp, rgd->rd_data0, NULL, bi, r.minlen, &amt);
944 if (ret) {
945 gfs2_glock_dq_uninit(&gh);
946 goto out;
947 }
948 trimmed += amt;
949 }
950
951 /* Mark rgrp as having been trimmed */
952 ret = gfs2_trans_begin(sdp, RES_RG_HDR, 0);
953 if (ret == 0) {
954 bh = rgd->rd_bits[0].bi_bh;
955 rgd->rd_flags |= GFS2_RGF_TRIMMED;
956 gfs2_trans_add_bh(rgd->rd_gl, bh, 1);
957 gfs2_rgrp_out(rgd, bh->b_data);
958 gfs2_trans_end(sdp);
959 }
960 }
961 gfs2_glock_dq_uninit(&gh);
962
963 if (rgd == rgd_end)
964 break;
965
966 rgd = gfs2_rgrpd_get_next(rgd);
967 }
968
969out:
970 r.len = trimmed << 9;
971 if (argp && copy_to_user(argp, &r, sizeof(r)))
972 return -EFAULT;
973
974 return ret;
865} 975}
866 976
867/** 977/**
@@ -1008,7 +1118,7 @@ static int get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1008 if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal)) 1118 if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal))
1009 rgd = begin = ip->i_rgd; 1119 rgd = begin = ip->i_rgd;
1010 else 1120 else
1011 rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal); 1121 rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1);
1012 1122
1013 if (rgd == NULL) 1123 if (rgd == NULL)
1014 return -EBADSLT; 1124 return -EBADSLT;
@@ -1293,7 +1403,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
1293 u32 length, rgrp_blk, buf_blk; 1403 u32 length, rgrp_blk, buf_blk;
1294 unsigned int buf; 1404 unsigned int buf;
1295 1405
1296 rgd = gfs2_blk2rgrpd(sdp, bstart); 1406 rgd = gfs2_blk2rgrpd(sdp, bstart, 1);
1297 if (!rgd) { 1407 if (!rgd) {
1298 if (gfs2_consist(sdp)) 1408 if (gfs2_consist(sdp))
1299 fs_err(sdp, "block = %llu\n", (unsigned long long)bstart); 1409 fs_err(sdp, "block = %llu\n", (unsigned long long)bstart);
@@ -1474,7 +1584,7 @@ void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta)
1474 return; 1584 return;
1475 trace_gfs2_block_alloc(ip, bstart, blen, GFS2_BLKST_FREE); 1585 trace_gfs2_block_alloc(ip, bstart, blen, GFS2_BLKST_FREE);
1476 rgd->rd_free += blen; 1586 rgd->rd_free += blen;
1477 1587 rgd->rd_flags &= ~GFS2_RGF_TRIMMED;
1478 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); 1588 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
1479 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); 1589 gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
1480 1590
@@ -1560,14 +1670,9 @@ int gfs2_check_blk_type(struct gfs2_sbd *sdp, u64 no_addr, unsigned int type)
1560{ 1670{
1561 struct gfs2_rgrpd *rgd; 1671 struct gfs2_rgrpd *rgd;
1562 struct gfs2_holder rgd_gh; 1672 struct gfs2_holder rgd_gh;
1563 int error; 1673 int error = -EINVAL;
1564
1565 error = gfs2_rindex_update(sdp);
1566 if (error)
1567 return error;
1568 1674
1569 error = -EINVAL; 1675 rgd = gfs2_blk2rgrpd(sdp, no_addr, 1);
1570 rgd = gfs2_blk2rgrpd(sdp, no_addr);
1571 if (!rgd) 1676 if (!rgd)
1572 goto fail; 1677 goto fail;
1573 1678
@@ -1610,7 +1715,7 @@ void gfs2_rlist_add(struct gfs2_inode *ip, struct gfs2_rgrp_list *rlist,
1610 if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, block)) 1715 if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, block))
1611 rgd = ip->i_rgd; 1716 rgd = ip->i_rgd;
1612 else 1717 else
1613 rgd = gfs2_blk2rgrpd(sdp, block); 1718 rgd = gfs2_blk2rgrpd(sdp, block, 1);
1614 if (!rgd) { 1719 if (!rgd) {
1615 fs_err(sdp, "rlist_add: no rgrp for block %llu\n", (unsigned long long)block); 1720 fs_err(sdp, "rlist_add: no rgrp for block %llu\n", (unsigned long long)block);
1616 return; 1721 return;
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index ceec9106cdf4..b4b10f4de25f 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -11,6 +11,7 @@
11#define __RGRP_DOT_H__ 11#define __RGRP_DOT_H__
12 12
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/uaccess.h>
14 15
15struct gfs2_rgrpd; 16struct gfs2_rgrpd;
16struct gfs2_sbd; 17struct gfs2_sbd;
@@ -18,7 +19,7 @@ struct gfs2_holder;
18 19
19extern void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd); 20extern void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd);
20 21
21extern struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk); 22extern struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk, bool exact);
22extern struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp); 23extern struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp);
23extern struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd); 24extern struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd);
24 25
@@ -62,8 +63,9 @@ extern void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state);
62extern void gfs2_rlist_free(struct gfs2_rgrp_list *rlist); 63extern void gfs2_rlist_free(struct gfs2_rgrp_list *rlist);
63extern u64 gfs2_ri_total(struct gfs2_sbd *sdp); 64extern u64 gfs2_ri_total(struct gfs2_sbd *sdp);
64extern int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl); 65extern int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl);
65extern void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset, 66extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
66 struct buffer_head *bh, 67 struct buffer_head *bh,
67 const struct gfs2_bitmap *bi); 68 const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed);
69extern int gfs2_fitrim(struct file *filp, void __user *argp);
68 70
69#endif /* __RGRP_DOT_H__ */ 71#endif /* __RGRP_DOT_H__ */
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 4553ce515f62..6172fa77ad59 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1417,7 +1417,7 @@ static int gfs2_dinode_dealloc(struct gfs2_inode *ip)
1417 if (error) 1417 if (error)
1418 goto out; 1418 goto out;
1419 1419
1420 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr); 1420 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr, 1);
1421 if (!rgd) { 1421 if (!rgd) {
1422 gfs2_consist_inode(ip); 1422 gfs2_consist_inode(ip);
1423 error = -EIO; 1423 error = -EIO;
@@ -1557,6 +1557,7 @@ out:
1557 end_writeback(inode); 1557 end_writeback(inode);
1558 gfs2_dir_hash_inval(ip); 1558 gfs2_dir_hash_inval(ip);
1559 ip->i_gl->gl_object = NULL; 1559 ip->i_gl->gl_object = NULL;
1560 flush_delayed_work_sync(&ip->i_gl->gl_work);
1560 gfs2_glock_add_to_lru(ip->i_gl); 1561 gfs2_glock_add_to_lru(ip->i_gl);
1561 gfs2_glock_put(ip->i_gl); 1562 gfs2_glock_put(ip->i_gl);
1562 ip->i_gl = NULL; 1563 ip->i_gl = NULL;
diff --git a/fs/gfs2/trace_gfs2.h b/fs/gfs2/trace_gfs2.h
index 5d07609ec57d..dfa89cd75534 100644
--- a/fs/gfs2/trace_gfs2.h
+++ b/fs/gfs2/trace_gfs2.h
@@ -11,6 +11,7 @@
11#include <linux/dlmconstants.h> 11#include <linux/dlmconstants.h>
12#include <linux/gfs2_ondisk.h> 12#include <linux/gfs2_ondisk.h>
13#include <linux/writeback.h> 13#include <linux/writeback.h>
14#include <linux/ktime.h>
14#include "incore.h" 15#include "incore.h"
15#include "glock.h" 16#include "glock.h"
16 17
@@ -43,7 +44,8 @@
43 {(1UL << GLF_FROZEN), "F" }, \ 44 {(1UL << GLF_FROZEN), "F" }, \
44 {(1UL << GLF_QUEUED), "q" }, \ 45 {(1UL << GLF_QUEUED), "q" }, \
45 {(1UL << GLF_LRU), "L" }, \ 46 {(1UL << GLF_LRU), "L" }, \
46 {(1UL << GLF_OBJECT), "o" }) 47 {(1UL << GLF_OBJECT), "o" }, \
48 {(1UL << GLF_BLOCKING), "b" })
47 49
48#ifndef NUMPTY 50#ifndef NUMPTY
49#define NUMPTY 51#define NUMPTY
@@ -236,6 +238,62 @@ TRACE_EVENT(gfs2_glock_queue,
236 glock_trace_name(__entry->state)) 238 glock_trace_name(__entry->state))
237); 239);
238 240
241/* DLM sends a reply to GFS2 */
242TRACE_EVENT(gfs2_glock_lock_time,
243
244 TP_PROTO(const struct gfs2_glock *gl, s64 tdiff),
245
246 TP_ARGS(gl, tdiff),
247
248 TP_STRUCT__entry(
249 __field( dev_t, dev )
250 __field( u64, glnum )
251 __field( u32, gltype )
252 __field( int, status )
253 __field( char, flags )
254 __field( s64, tdiff )
255 __field( s64, srtt )
256 __field( s64, srttvar )
257 __field( s64, srttb )
258 __field( s64, srttvarb )
259 __field( s64, sirt )
260 __field( s64, sirtvar )
261 __field( s64, dcount )
262 __field( s64, qcount )
263 ),
264
265 TP_fast_assign(
266 __entry->dev = gl->gl_sbd->sd_vfs->s_dev;
267 __entry->glnum = gl->gl_name.ln_number;
268 __entry->gltype = gl->gl_name.ln_type;
269 __entry->status = gl->gl_lksb.sb_status;
270 __entry->flags = gl->gl_lksb.sb_flags;
271 __entry->tdiff = tdiff;
272 __entry->srtt = gl->gl_stats.stats[GFS2_LKS_SRTT];
273 __entry->srttvar = gl->gl_stats.stats[GFS2_LKS_SRTTVAR];
274 __entry->srttb = gl->gl_stats.stats[GFS2_LKS_SRTTB];
275 __entry->srttvarb = gl->gl_stats.stats[GFS2_LKS_SRTTVARB];
276 __entry->sirt = gl->gl_stats.stats[GFS2_LKS_SIRT];
277 __entry->sirtvar = gl->gl_stats.stats[GFS2_LKS_SIRTVAR];
278 __entry->dcount = gl->gl_stats.stats[GFS2_LKS_DCOUNT];
279 __entry->qcount = gl->gl_stats.stats[GFS2_LKS_QCOUNT];
280 ),
281
282 TP_printk("%u,%u glock %d:%lld status:%d flags:%02x tdiff:%lld srtt:%lld/%lld srttb:%lld/%lld sirt:%lld/%lld dcnt:%lld qcnt:%lld",
283 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->gltype,
284 (unsigned long long)__entry->glnum,
285 __entry->status, __entry->flags,
286 (long long)__entry->tdiff,
287 (long long)__entry->srtt,
288 (long long)__entry->srttvar,
289 (long long)__entry->srttb,
290 (long long)__entry->srttvarb,
291 (long long)__entry->sirt,
292 (long long)__entry->sirtvar,
293 (long long)__entry->dcount,
294 (long long)__entry->qcount)
295);
296
239/* Section 2 - Log/journal 297/* Section 2 - Log/journal
240 * 298 *
241 * Objectives: 299 * Objectives:
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
index 53511291fe36..9e7765e8e7b0 100644
--- a/fs/gfs2/util.c
+++ b/fs/gfs2/util.c
@@ -25,6 +25,7 @@ struct kmem_cache *gfs2_inode_cachep __read_mostly;
25struct kmem_cache *gfs2_bufdata_cachep __read_mostly; 25struct kmem_cache *gfs2_bufdata_cachep __read_mostly;
26struct kmem_cache *gfs2_rgrpd_cachep __read_mostly; 26struct kmem_cache *gfs2_rgrpd_cachep __read_mostly;
27struct kmem_cache *gfs2_quotad_cachep __read_mostly; 27struct kmem_cache *gfs2_quotad_cachep __read_mostly;
28mempool_t *gfs2_bh_pool __read_mostly;
28 29
29void gfs2_assert_i(struct gfs2_sbd *sdp) 30void gfs2_assert_i(struct gfs2_sbd *sdp)
30{ 31{
diff --git a/fs/gfs2/util.h b/fs/gfs2/util.h
index b432e04600de..a4ce76c67dbb 100644
--- a/fs/gfs2/util.h
+++ b/fs/gfs2/util.h
@@ -10,6 +10,8 @@
10#ifndef __UTIL_DOT_H__ 10#ifndef __UTIL_DOT_H__
11#define __UTIL_DOT_H__ 11#define __UTIL_DOT_H__
12 12
13#include <linux/mempool.h>
14
13#include "incore.h" 15#include "incore.h"
14 16
15#define fs_printk(level, fs, fmt, arg...) \ 17#define fs_printk(level, fs, fmt, arg...) \
@@ -150,6 +152,7 @@ extern struct kmem_cache *gfs2_inode_cachep;
150extern struct kmem_cache *gfs2_bufdata_cachep; 152extern struct kmem_cache *gfs2_bufdata_cachep;
151extern struct kmem_cache *gfs2_rgrpd_cachep; 153extern struct kmem_cache *gfs2_rgrpd_cachep;
152extern struct kmem_cache *gfs2_quotad_cachep; 154extern struct kmem_cache *gfs2_quotad_cachep;
155extern mempool_t *gfs2_bh_pool;
153 156
154static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt, 157static inline unsigned int gfs2_tune_get_i(struct gfs2_tune *gt,
155 unsigned int *p) 158 unsigned int *p)
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index e9636591b5d5..2e5ba425cae7 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -251,7 +251,7 @@ static int ea_dealloc_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
251 if (!blks) 251 if (!blks)
252 return 0; 252 return 0;
253 253
254 rgd = gfs2_blk2rgrpd(sdp, bn); 254 rgd = gfs2_blk2rgrpd(sdp, bn, 1);
255 if (!rgd) { 255 if (!rgd) {
256 gfs2_consist_inode(ip); 256 gfs2_consist_inode(ip);
257 return -EIO; 257 return -EIO;
@@ -1439,7 +1439,7 @@ static int ea_dealloc_block(struct gfs2_inode *ip)
1439 struct gfs2_holder gh; 1439 struct gfs2_holder gh;
1440 int error; 1440 int error;
1441 1441
1442 rgd = gfs2_blk2rgrpd(sdp, ip->i_eattr); 1442 rgd = gfs2_blk2rgrpd(sdp, ip->i_eattr, 1);
1443 if (!rgd) { 1443 if (!rgd) {
1444 gfs2_consist_inode(ip); 1444 gfs2_consist_inode(ip);
1445 return -EIO; 1445 return -EIO;
diff --git a/include/linux/gfs2_ondisk.h b/include/linux/gfs2_ondisk.h
index b148087f49a6..fa98bdb073b9 100644
--- a/include/linux/gfs2_ondisk.h
+++ b/include/linux/gfs2_ondisk.h
@@ -168,6 +168,7 @@ struct gfs2_rindex {
168#define GFS2_RGF_METAONLY 0x00000002 168#define GFS2_RGF_METAONLY 0x00000002
169#define GFS2_RGF_DATAONLY 0x00000004 169#define GFS2_RGF_DATAONLY 0x00000004
170#define GFS2_RGF_NOALLOC 0x00000008 170#define GFS2_RGF_NOALLOC 0x00000008
171#define GFS2_RGF_TRIMMED 0x00000010
171 172
172struct gfs2_rgrp { 173struct gfs2_rgrp {
173 struct gfs2_meta_header rg_header; 174 struct gfs2_meta_header rg_header;