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.c107
1 files changed, 43 insertions, 64 deletions
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
index e2d4285fbe9..fea8dd661d2 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
@@ -1131,6 +1135,14 @@ static int journal_get_superblock(journal_t *journal)
1131 goto out; 1135 goto out;
1132 } 1136 }
1133 1137
1138 if (be32_to_cpu(sb->s_first) == 0 ||
1139 be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
1140 printk(KERN_WARNING
1141 "JBD: Invalid start block of journal: %u\n",
1142 be32_to_cpu(sb->s_first));
1143 goto out;
1144 }
1145
1134 return 0; 1146 return 0;
1135 1147
1136out: 1148out:
@@ -1799,10 +1811,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 1811 * When a buffer has its BH_JBD bit set it is immune from being released by
1800 * core kernel code, mainly via ->b_count. 1812 * core kernel code, mainly via ->b_count.
1801 * 1813 *
1802 * A journal_head may be detached from its buffer_head when the journal_head's 1814 * 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. 1815 * b_jcount reaches zero. Running transaction (b_transaction) and checkpoint
1804 * Various places in JBD call journal_remove_journal_head() to indicate that the 1816 * transaction (b_cp_transaction) hold their references to b_jcount.
1805 * journal_head can be dropped if needed.
1806 * 1817 *
1807 * Various places in the kernel want to attach a journal_head to a buffer_head 1818 * 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 1819 * _before_ attaching the journal_head to a transaction. To protect the
@@ -1815,17 +1826,16 @@ static void journal_free_journal_head(struct journal_head *jh)
1815 * (Attach a journal_head if needed. Increments b_jcount) 1826 * (Attach a journal_head if needed. Increments b_jcount)
1816 * struct journal_head *jh = journal_add_journal_head(bh); 1827 * struct journal_head *jh = journal_add_journal_head(bh);
1817 * ... 1828 * ...
1818 * jh->b_transaction = xxx; 1829 * (Get another reference for transaction)
1819 * journal_put_journal_head(jh); 1830 * journal_grab_journal_head(bh);
1820 * 1831 * jh->b_transaction = xxx;
1821 * Now, the journal_head's b_jcount is zero, but it is safe from being released 1832 * (Put original reference)
1822 * because it has a non-zero b_transaction. 1833 * journal_put_journal_head(jh);
1823 */ 1834 */
1824 1835
1825/* 1836/*
1826 * Give a buffer_head a journal_head. 1837 * Give a buffer_head a journal_head.
1827 * 1838 *
1828 * Doesn't need the journal lock.
1829 * May sleep. 1839 * May sleep.
1830 */ 1840 */
1831struct journal_head *journal_add_journal_head(struct buffer_head *bh) 1841struct journal_head *journal_add_journal_head(struct buffer_head *bh)
@@ -1889,61 +1899,29 @@ static void __journal_remove_journal_head(struct buffer_head *bh)
1889 struct journal_head *jh = bh2jh(bh); 1899 struct journal_head *jh = bh2jh(bh);
1890 1900
1891 J_ASSERT_JH(jh, jh->b_jcount >= 0); 1901 J_ASSERT_JH(jh, jh->b_jcount >= 0);
1892 1902 J_ASSERT_JH(jh, jh->b_transaction == NULL);
1893 get_bh(bh); 1903 J_ASSERT_JH(jh, jh->b_next_transaction == NULL);
1894 if (jh->b_jcount == 0) { 1904 J_ASSERT_JH(jh, jh->b_cp_transaction == NULL);
1895 if (jh->b_transaction == NULL && 1905 J_ASSERT_JH(jh, jh->b_jlist == BJ_None);
1896 jh->b_next_transaction == NULL && 1906 J_ASSERT_BH(bh, buffer_jbd(bh));
1897 jh->b_cp_transaction == NULL) { 1907 J_ASSERT_BH(bh, jh2bh(jh) == bh);
1898 J_ASSERT_JH(jh, jh->b_jlist == BJ_None); 1908 BUFFER_TRACE(bh, "remove journal_head");
1899 J_ASSERT_BH(bh, buffer_jbd(bh)); 1909 if (jh->b_frozen_data) {
1900 J_ASSERT_BH(bh, jh2bh(jh) == bh); 1910 printk(KERN_WARNING "%s: freeing b_frozen_data\n", __func__);
1901 BUFFER_TRACE(bh, "remove journal_head"); 1911 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 } 1912 }
1913 if (jh->b_committed_data) {
1914 printk(KERN_WARNING "%s: freeing b_committed_data\n", __func__);
1915 jbd_free(jh->b_committed_data, bh->b_size);
1916 }
1917 bh->b_private = NULL;
1918 jh->b_bh = NULL; /* debug, really */
1919 clear_buffer_jbd(bh);
1920 journal_free_journal_head(jh);
1923} 1921}
1924 1922
1925/* 1923/*
1926 * journal_remove_journal_head(): if the buffer isn't attached to a transaction 1924 * 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. 1925 * release the journal_head from the buffer_head.
1948 */ 1926 */
1949void journal_put_journal_head(struct journal_head *jh) 1927void journal_put_journal_head(struct journal_head *jh)
@@ -1953,11 +1931,12 @@ void journal_put_journal_head(struct journal_head *jh)
1953 jbd_lock_bh_journal_head(bh); 1931 jbd_lock_bh_journal_head(bh);
1954 J_ASSERT_JH(jh, jh->b_jcount > 0); 1932 J_ASSERT_JH(jh, jh->b_jcount > 0);
1955 --jh->b_jcount; 1933 --jh->b_jcount;
1956 if (!jh->b_jcount && !jh->b_transaction) { 1934 if (!jh->b_jcount) {
1957 __journal_remove_journal_head(bh); 1935 __journal_remove_journal_head(bh);
1936 jbd_unlock_bh_journal_head(bh);
1958 __brelse(bh); 1937 __brelse(bh);
1959 } 1938 } else
1960 jbd_unlock_bh_journal_head(bh); 1939 jbd_unlock_bh_journal_head(bh);
1961} 1940}
1962 1941
1963/* 1942/*