Skip to content

Commit 722887d

Browse files
committed
ext4: move the jbd2 wrapper functions out of super.c
Move the jbd2 wrapper functions which start and stop handles out of super.c, where they don't really logically belong, and into ext4_jbd2.c. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 343d9c2 commit 722887d

3 files changed

Lines changed: 105 additions & 105 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,8 @@ extern void *ext4_kvzalloc(size_t size, gfp_t flags);
21492149
extern void ext4_kvfree(void *ptr);
21502150
extern int ext4_alloc_flex_bg_array(struct super_block *sb,
21512151
ext4_group_t ngroup);
2152+
extern const char *ext4_decode_error(struct super_block *sb, int errno,
2153+
char nbuf[16]);
21522154
extern __printf(4, 5)
21532155
void __ext4_error(struct super_block *, const char *, unsigned int,
21542156
const char *, ...);

‎fs/ext4/ext4_jbd2.c‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,107 @@
66

77
#include <trace/events/ext4.h>
88

9+
/* Just increment the non-pointer handle value */
10+
static 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 */
26+
static 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+
*/
41+
handle_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+
65+
int __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+
86+
void 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+
9110
int __ext4_journal_get_write_access(const char *where, unsigned int line,
10111
handle_t *handle, struct buffer_head *bh)
11112
{

‎fs/ext4/super.c‎

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ static void ext4_mark_recovery_complete(struct super_block *sb,
6969
static void ext4_clear_journal_err(struct super_block *sb,
7070
struct ext4_super_block *es);
7171
static int ext4_sync_fs(struct super_block *sb, int wait);
72-
static const char *ext4_decode_error(struct super_block *sb, int errno,
73-
char nbuf[16]);
7472
static int ext4_remount(struct super_block *sb, int *flags, char *data);
7573
static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf);
7674
static int ext4_unfreeze(struct super_block *sb);
@@ -296,107 +294,6 @@ void ext4_itable_unused_set(struct super_block *sb,
296294
}
297295

298296

299-
/* Just increment the non-pointer handle value */
300-
static handle_t *ext4_get_nojournal(void)
301-
{
302-
handle_t *handle = current->journal_info;
303-
unsigned long ref_cnt = (unsigned long)handle;
304-
305-
BUG_ON(ref_cnt >= EXT4_NOJOURNAL_MAX_REF_COUNT);
306-
307-
ref_cnt++;
308-
handle = (handle_t *)ref_cnt;
309-
310-
current->journal_info = handle;
311-
return handle;
312-
}
313-
314-
315-
/* Decrement the non-pointer handle value */
316-
static void ext4_put_nojournal(handle_t *handle)
317-
{
318-
unsigned long ref_cnt = (unsigned long)handle;
319-
320-
BUG_ON(ref_cnt == 0);
321-
322-
ref_cnt--;
323-
handle = (handle_t *)ref_cnt;
324-
325-
current->journal_info = handle;
326-
}
327-
328-
/*
329-
* Wrappers for jbd2_journal_start/end.
330-
*/
331-
handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
332-
{
333-
journal_t *journal;
334-
335-
trace_ext4_journal_start(sb, nblocks, _RET_IP_);
336-
if (sb->s_flags & MS_RDONLY)
337-
return ERR_PTR(-EROFS);
338-
339-
WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
340-
journal = EXT4_SB(sb)->s_journal;
341-
if (!journal)
342-
return ext4_get_nojournal();
343-
/*
344-
* Special case here: if the journal has aborted behind our
345-
* backs (eg. EIO in the commit thread), then we still need to
346-
* take the FS itself readonly cleanly.
347-
*/
348-
if (is_journal_aborted(journal)) {
349-
ext4_abort(sb, "Detected aborted journal");
350-
return ERR_PTR(-EROFS);
351-
}
352-
return jbd2_journal_start(journal, nblocks);
353-
}
354-
355-
int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
356-
{
357-
struct super_block *sb;
358-
int err;
359-
int rc;
360-
361-
if (!ext4_handle_valid(handle)) {
362-
ext4_put_nojournal(handle);
363-
return 0;
364-
}
365-
sb = handle->h_transaction->t_journal->j_private;
366-
err = handle->h_err;
367-
rc = jbd2_journal_stop(handle);
368-
369-
if (!err)
370-
err = rc;
371-
if (err)
372-
__ext4_std_error(sb, where, line, err);
373-
return err;
374-
}
375-
376-
void ext4_journal_abort_handle(const char *caller, unsigned int line,
377-
const char *err_fn, struct buffer_head *bh,
378-
handle_t *handle, int err)
379-
{
380-
char nbuf[16];
381-
const char *errstr = ext4_decode_error(NULL, err, nbuf);
382-
383-
BUG_ON(!ext4_handle_valid(handle));
384-
385-
if (bh)
386-
BUFFER_TRACE(bh, "abort");
387-
388-
if (!handle->h_err)
389-
handle->h_err = err;
390-
391-
if (is_handle_aborted(handle))
392-
return;
393-
394-
printk(KERN_ERR "EXT4-fs: %s:%d: aborting transaction: %s in %s\n",
395-
caller, line, errstr, err_fn);
396-
397-
jbd2_journal_abort_handle(handle);
398-
}
399-
400297
static void __save_error_info(struct super_block *sb, const char *func,
401298
unsigned int line)
402299
{
@@ -582,8 +479,8 @@ void ext4_error_file(struct file *file, const char *function,
582479
ext4_handle_error(inode->i_sb);
583480
}
584481

585-
static const char *ext4_decode_error(struct super_block *sb, int errno,
586-
char nbuf[16])
482+
const char *ext4_decode_error(struct super_block *sb, int errno,
483+
char nbuf[16])
587484
{
588485
char *errstr = NULL;
589486

0 commit comments

Comments
 (0)