aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jbd/journal.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jbd/journal.c')
-rw-r--r--fs/jbd/journal.c99
1 files changed, 35 insertions, 64 deletions
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
index e2d4285fbe90..9fe061fb8779 100644
--- a/fs/jbd/journal.c
+++ b/fs/jbd/journal.c
@@ -38,6 +38,9 @@
38#include <linux/debugfs.h> 38#include <linux/debugfs.h>
39#include <linux/ratelimit.h> 39#include <linux/ratelimit.h>
40 40
41#define CREATE_TRACE_POINTS
42#include <trace/events/jbd.h>
43
41#include <asm/uaccess.h> 44#include <asm/uaccess.h>
42#include <asm/page.h> 45#include <asm/page.h>
43 46
@@ -1065,6 +1068,7 @@ void journal_update_superblock(journal_t *journal, int wait)
1065 } else 1068 } else
1066 write_dirty_buffer(bh, WRITE); 1069 write_dirty_buffer(bh, WRITE);
1067 1070
1071 trace_jbd_update_superblock_end(journal, wait);
1068out: 1072out:
1069 /* If we have just flushed the log (by marking s_start==0), then 1073 /* If we have just flushed the log (by marking s_start==0), then
1070 * any future commit will have to be careful to update the 1074 * any future commit will have to be careful to update the
@@ -1799,10 +1803,9 @@ static void journal_free_journal_head(struct journal_head *jh)
1799 * When a buffer has its BH_JBD bit set it is immune from being released by 1803 * When a buffer has its BH_JBD bit set it is immune from being released by
1800 * core kernel code, mainly via ->b_count. 1804 * core kernel code, mainly via ->b_count.
1801 * 1805 *
1802 * A journal_head may be detached from its buffer_head when the journal_head's 1806 * A journal_head is detached from its buffer_head when the journal_head's
1803 * b_transaction, b_cp_transaction and b_next_transaction pointers are NULL. 1807 * b_jcount reaches zero. Running transaction (b_transaction) and checkpoint
1804 * Various places in JBD call journal_remove_journal_head() to indicate that the 1808 * transaction (b_cp_transaction) hold their references to b_jcount.
1805 * journal_head can be dropped if needed.
1806 * 1809 *
1807 * Various places in the kernel want to attach a journal_head to a buffer_head 1810 * Various places in the kernel want to attach a journal_head to a buffer_head
1808 * _before_ attaching the journal_head to a transaction. To protect the 1811 * _before_ attaching the journal_head to a transaction. To protect the
@@ -1815,17 +1818,16 @@ static void journal_free_journal_head(struct journal_head *jh)
1815 * (Attach a journal_head if needed. Increments b_jcount) 1818 * (Attach a journal_head if needed. Increments b_jcount)
1816 * struct journal_head *jh = journal_add_journal_head(bh); 1819 * struct journal_head *jh = journal_add_journal_head(bh);
1817 * ... 1820 * ...
1818 * jh->b_transaction = xxx; 1821 * (Get another reference for transaction)
1819 * journal_put_journal_head(jh); 1822 * journal_grab_journal_head(bh);
1820 * 1823 * jh->b_transaction = xxx;
1821 * Now, the journal_head's b_jcount is zero, but it is safe from being released 1824 * (Put original reference)
1822 * because it has a non-zero b_transaction. 1825 * journal_put_journal_head(jh);
1823 */ 1826 */
1824 1827
1825/* 1828/*
1826 * Give a buffer_head a journal_head. 1829 * Give a buffer_head a journal_head.
1827 * 1830 *
1828 * Doesn't need the journal lock.
1829 * May sleep. 1831 * May sleep.
1830 */ 1832 */
1831struct journal_head *journal_add_journal_head(struct buffer_head *bh) 1833struct journal_head *journal_add_journal_head(struct buffer_head *bh)
@@ -1889,61 +1891,29 @@ static void __journal_remove_journal_head(struct buffer_head *bh)
1889 struct journal_head *jh = bh2jh(bh); 1891 struct journal_head *jh = bh2jh(bh);
1890 1892
1891 J_ASSERT_JH(jh, jh->b_jcount >= 0); 1893 J_ASSERT_JH(jh, jh->b_jcount >= 0);
1892 1894 J_ASSERT_JH(jh, jh->b_transaction == NULL);
1893 get_bh(bh); 1895 J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
1894 if (jh->b_jcount == 0) { 1896 J_ASSERT_JH(jh, jh->b_cp_transaction == NULL);
1895 if (jh->b_transaction == NULL && 1897 J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
1896 jh->b_next_transaction == NULL && 1898 J_ASSERT_BH(bh, buffer_jbd(bh));
1897 jh->b_cp_transaction == NULL) { 1899 J_ASSERT_BH(bh, jh2bh(jh) == bh);
1898 J_ASSERT_JH(jh, jh->b_jlist == BJ_None); 1900 BUFFER_TRACE(bh, "remove journal_head");
1899 J_ASSERT_BH(bh, buffer_jbd(bh)); 1901 if (jh->b_frozen_data) {
1900 J_ASSERT_BH(bh, jh2bh(jh) == bh); 1902 printk(KERN_WARNING "%s: freeing b_frozen_data\n", __func__);
1901 BUFFER_TRACE(bh, "remove journal_head"); 1903 jbd_free(jh->b_frozen_data, bh->b_size);
1902 if (jh->b_frozen_data) {
1903 printk(KERN_WARNING "%s: freeing "
1904 "b_frozen_data\n",
1905 __func__);
1906 jbd_free(jh->b_frozen_data, bh->b_size);
1907 }
1908 if (jh->b_committed_data) {
1909 printk(KERN_WARNING "%s: freeing "
1910 "b_committed_data\n",
1911 __func__);
1912 jbd_free(jh->b_committed_data, bh->b_size);
1913 }
1914 bh->b_private = NULL;
1915 jh->b_bh = NULL; /* debug, really */
1916 clear_buffer_jbd(bh);
1917 __brelse(bh);
1918 journal_free_journal_head(jh);
1919 } else {
1920 BUFFER_TRACE(bh, "journal_head was locked");
1921 }
1922 } 1904 }
1905 if (jh->b_committed_data) {
1906 printk(KERN_WARNING "%s: freeing b_committed_data\n", __func__);
1907 jbd_free(jh->b_committed_data, bh->b_size);
1908 }
1909 bh->b_private = NULL;
1910 jh->b_bh = NULL; /* debug, really */
1911 clear_buffer_jbd(bh);
1912 journal_free_journal_head(jh);
1923} 1913}
1924 1914
1925/* 1915/*
1926 * journal_remove_journal_head(): if the buffer isn't attached to a transaction 1916 * Drop a reference on the passed journal_head. If it fell to zero then
1927 * and has a zero b_jcount then remove and release its journal_head. If we did
1928 * see that the buffer is not used by any transaction we also "logically"
1929 * decrement ->b_count.
1930 *
1931 * We in fact take an additional increment on ->b_count as a convenience,
1932 * because the caller usually wants to do additional things with the bh
1933 * after calling here.
1934 * The caller of journal_remove_journal_head() *must* run __brelse(bh) at some
1935 * time. Once the caller has run __brelse(), the buffer is eligible for
1936 * reaping by try_to_free_buffers().
1937 */
1938void journal_remove_journal_head(struct buffer_head *bh)
1939{
1940 jbd_lock_bh_journal_head(bh);
1941 __journal_remove_journal_head(bh);
1942 jbd_unlock_bh_journal_head(bh);
1943}
1944
1945/*
1946 * Drop a reference on the passed journal_head. If it fell to zero then try to
1947 * release the journal_head from the buffer_head. 1917 * release the journal_head from the buffer_head.
1948 */ 1918 */
1949void journal_put_journal_head(struct journal_head *jh) 1919void journal_put_journal_head(struct journal_head *jh)
@@ -1953,11 +1923,12 @@ void journal_put_journal_head(struct journal_head *jh)
1953 jbd_lock_bh_journal_head(bh); 1923 jbd_lock_bh_journal_head(bh);
1954 J_ASSERT_JH(jh, jh->b_jcount > 0); 1924 J_ASSERT_JH(jh, jh->b_jcount > 0);
1955 --jh->b_jcount; 1925 --jh->b_jcount;
1956 if (!jh->b_jcount && !jh->b_transaction) { 1926 if (!jh->b_jcount) {
1957 __journal_remove_journal_head(bh); 1927 __journal_remove_journal_head(bh);
1928 jbd_unlock_bh_journal_head(bh);
1958 __brelse(bh); 1929 __brelse(bh);
1959 } 1930 } else
1960 jbd_unlock_bh_journal_head(bh); 1931 jbd_unlock_bh_journal_head(bh);
1961} 1932}
1962 1933
1963/* 1934/*