aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/ext4_jbd2.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/ext4_jbd2.c')
-rw-r--r--fs/ext4/ext4_jbd2.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index b4323ba846b5..6f6114525535 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -6,6 +6,107 @@
6 6
7#include <trace/events/ext4.h> 7#include <trace/events/ext4.h>
8 8
9/* Just increment the non-pointer handle value */
10static handle_t *ext4_get_nojournal(void)
11{
12 handle_t *handle = current->journal_info;
13 unsigned long ref_cnt = (unsigned long)handle;
14
15 BUG_ON(ref_cnt >= EXT4_NOJOURNAL_MAX_REF_COUNT);
16
17 ref_cnt++;
18 handle = (handle_t *)ref_cnt;
19
20 current->journal_info = handle;
21 return handle;
22}
23
24
25/* Decrement the non-pointer handle value */
26static void ext4_put_nojournal(handle_t *handle)
27{
28 unsigned long ref_cnt = (unsigned long)handle;
29
30 BUG_ON(ref_cnt == 0);
31
32 ref_cnt--;
33 handle = (handle_t *)ref_cnt;
34
35 current->journal_info = handle;
36}
37
38/*
39 * Wrappers for jbd2_journal_start/end.
40 */
41handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
42{
43 journal_t *journal;
44
45 trace_ext4_journal_start(sb, nblocks, _RET_IP_);
46 if (sb->s_flags & MS_RDONLY)
47 return ERR_PTR(-EROFS);
48
49 WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
50 journal = EXT4_SB(sb)->s_journal;
51 if (!journal)
52 return ext4_get_nojournal();
53 /*
54 * Special case here: if the journal has aborted behind our
55 * backs (eg. EIO in the commit thread), then we still need to
56 * take the FS itself readonly cleanly.
57 */
58 if (is_journal_aborted(journal)) {
59 ext4_abort(sb, "Detected aborted journal");
60 return ERR_PTR(-EROFS);
61 }
62 return jbd2_journal_start(journal, nblocks);
63}
64
65int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
66{
67 struct super_block *sb;
68 int err;
69 int rc;
70
71 if (!ext4_handle_valid(handle)) {
72 ext4_put_nojournal(handle);
73 return 0;
74 }
75 sb = handle->h_transaction->t_journal->j_private;
76 err = handle->h_err;
77 rc = jbd2_journal_stop(handle);
78
79 if (!err)
80 err = rc;
81 if (err)
82 __ext4_std_error(sb, where, line, err);
83 return err;
84}
85
86void ext4_journal_abort_handle(const char *caller, unsigned int line,
87 const char *err_fn, struct buffer_head *bh,
88 handle_t *handle, int err)
89{
90 char nbuf[16];
91 const char *errstr = ext4_decode_error(NULL, err, nbuf);
92
93 BUG_ON(!ext4_handle_valid(handle));
94
95 if (bh)
96 BUFFER_TRACE(bh, "abort");
97
98 if (!handle->h_err)
99 handle->h_err = err;
100
101 if (is_handle_aborted(handle))
102 return;
103
104 printk(KERN_ERR "EXT4-fs: %s:%d: aborting transaction: %s in %s\n",
105 caller, line, errstr, err_fn);
106
107 jbd2_journal_abort_handle(handle);
108}
109
9int __ext4_journal_get_write_access(const char *where, unsigned int line, 110int __ext4_journal_get_write_access(const char *where, unsigned int line,
10 handle_t *handle, struct buffer_head *bh) 111 handle_t *handle, struct buffer_head *bh)
11{ 112{