Skip to content

Commit 5fe2fe8

Browse files
jankaratytso
authored andcommitted
ext4: provide wrappers for transaction reservation calls
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 8f7d89f commit 5fe2fe8

4 files changed

Lines changed: 103 additions & 25 deletions

File tree

‎fs/ext4/ext4_jbd2.c‎

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,43 @@ static void ext4_put_nojournal(handle_t *handle)
3838
/*
3939
* Wrappers for jbd2_journal_start/end.
4040
*/
41-
handle_t *__ext4_journal_start_sb(struct super_block *sb, unsigned int line,
42-
int type, int nblocks)
41+
static int ext4_journal_check_start(struct super_block *sb)
4342
{
4443
journal_t *journal;
4544

4645
might_sleep();
47-
48-
trace_ext4_journal_start(sb, nblocks, _RET_IP_);
4946
if (sb->s_flags & MS_RDONLY)
50-
return ERR_PTR(-EROFS);
51-
47+
return -EROFS;
5248
WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
5349
journal = EXT4_SB(sb)->s_journal;
54-
if (!journal)
55-
return ext4_get_nojournal();
5650
/*
5751
* Special case here: if the journal has aborted behind our
5852
* backs (eg. EIO in the commit thread), then we still need to
5953
* take the FS itself readonly cleanly.
6054
*/
61-
if (is_journal_aborted(journal)) {
55+
if (journal && is_journal_aborted(journal)) {
6256
ext4_abort(sb, "Detected aborted journal");
63-
return ERR_PTR(-EROFS);
57+
return -EROFS;
6458
}
65-
return jbd2__journal_start(journal, nblocks, 0, GFP_NOFS, type, line);
59+
return 0;
60+
}
61+
62+
handle_t *__ext4_journal_start_sb(struct super_block *sb, unsigned int line,
63+
int type, int blocks, int rsv_blocks)
64+
{
65+
journal_t *journal;
66+
int err;
67+
68+
trace_ext4_journal_start(sb, blocks, rsv_blocks, _RET_IP_);
69+
err = ext4_journal_check_start(sb);
70+
if (err < 0)
71+
return ERR_PTR(err);
72+
73+
journal = EXT4_SB(sb)->s_journal;
74+
if (!journal)
75+
return ext4_get_nojournal();
76+
return jbd2__journal_start(journal, blocks, rsv_blocks, GFP_NOFS,
77+
type, line);
6678
}
6779

6880
int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
@@ -86,6 +98,30 @@ int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
8698
return err;
8799
}
88100

101+
handle_t *__ext4_journal_start_reserved(handle_t *handle, unsigned int line,
102+
int type)
103+
{
104+
struct super_block *sb;
105+
int err;
106+
107+
if (!ext4_handle_valid(handle))
108+
return ext4_get_nojournal();
109+
110+
sb = handle->h_journal->j_private;
111+
trace_ext4_journal_start_reserved(sb, handle->h_buffer_credits,
112+
_RET_IP_);
113+
err = ext4_journal_check_start(sb);
114+
if (err < 0) {
115+
jbd2_journal_free_reserved(handle);
116+
return ERR_PTR(err);
117+
}
118+
119+
err = jbd2_journal_start_reserved(handle, type, line);
120+
if (err < 0)
121+
return ERR_PTR(err);
122+
return handle;
123+
}
124+
89125
void ext4_journal_abort_handle(const char *caller, unsigned int line,
90126
const char *err_fn, struct buffer_head *bh,
91127
handle_t *handle, int err)

‎fs/ext4/ext4_jbd2.h‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ int __ext4_handle_dirty_super(const char *where, unsigned int line,
265265
__ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb))
266266

267267
handle_t *__ext4_journal_start_sb(struct super_block *sb, unsigned int line,
268-
int type, int nblocks);
268+
int type, int blocks, int rsv_blocks);
269269
int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle);
270270

271271
#define EXT4_NOJOURNAL_MAX_REF_COUNT ((unsigned long) 4096)
@@ -300,21 +300,37 @@ static inline int ext4_handle_has_enough_credits(handle_t *handle, int needed)
300300
}
301301

302302
#define ext4_journal_start_sb(sb, type, nblocks) \
303-
__ext4_journal_start_sb((sb), __LINE__, (type), (nblocks))
303+
__ext4_journal_start_sb((sb), __LINE__, (type), (nblocks), 0)
304304

305305
#define ext4_journal_start(inode, type, nblocks) \
306-
__ext4_journal_start((inode), __LINE__, (type), (nblocks))
306+
__ext4_journal_start((inode), __LINE__, (type), (nblocks), 0)
307+
308+
#define ext4_journal_start_with_reserve(inode, type, blocks, rsv_blocks) \
309+
__ext4_journal_start((inode), __LINE__, (type), (blocks), (rsv_blocks))
307310

308311
static inline handle_t *__ext4_journal_start(struct inode *inode,
309312
unsigned int line, int type,
310-
int nblocks)
313+
int blocks, int rsv_blocks)
311314
{
312-
return __ext4_journal_start_sb(inode->i_sb, line, type, nblocks);
315+
return __ext4_journal_start_sb(inode->i_sb, line, type, blocks,
316+
rsv_blocks);
313317
}
314318

315319
#define ext4_journal_stop(handle) \
316320
__ext4_journal_stop(__func__, __LINE__, (handle))
317321

322+
#define ext4_journal_start_reserve(handle, type) \
323+
__ext4_journal_start_reserved((handle), __LINE__, (type))
324+
325+
handle_t *__ext4_journal_start_reserved(handle_t *handle, unsigned int line,
326+
int type);
327+
328+
static inline void ext4_journal_free_reserved(handle_t *handle)
329+
{
330+
if (ext4_handle_valid(handle))
331+
jbd2_journal_free_reserved(handle);
332+
}
333+
318334
static inline handle_t *ext4_journal_current_handle(void)
319335
{
320336
return journal_current_handle();

‎fs/ext4/ialloc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
747747
if (!handle) {
748748
BUG_ON(nblocks <= 0);
749749
handle = __ext4_journal_start_sb(dir->i_sb, line_no,
750-
handle_type, nblocks);
750+
handle_type, nblocks,
751+
0);
751752
if (IS_ERR(handle)) {
752753
err = PTR_ERR(handle);
753754
ext4_std_error(sb, err);

‎include/trace/events/ext4.h‎

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,25 +1640,50 @@ TRACE_EVENT(ext4_load_inode,
16401640
);
16411641

16421642
TRACE_EVENT(ext4_journal_start,
1643-
TP_PROTO(struct super_block *sb, int nblocks, unsigned long IP),
1643+
TP_PROTO(struct super_block *sb, int blocks, int rsv_blocks,
1644+
unsigned long IP),
16441645

1645-
TP_ARGS(sb, nblocks, IP),
1646+
TP_ARGS(sb, blocks, rsv_blocks, IP),
16461647

16471648
TP_STRUCT__entry(
16481649
__field( dev_t, dev )
16491650
__field(unsigned long, ip )
1650-
__field( int, nblocks )
1651+
__field( int, blocks )
1652+
__field( int, rsv_blocks )
16511653
),
16521654

16531655
TP_fast_assign(
1654-
__entry->dev = sb->s_dev;
1655-
__entry->ip = IP;
1656-
__entry->nblocks = nblocks;
1656+
__entry->dev = sb->s_dev;
1657+
__entry->ip = IP;
1658+
__entry->blocks = blocks;
1659+
__entry->rsv_blocks = rsv_blocks;
16571660
),
16581661

1659-
TP_printk("dev %d,%d nblocks %d caller %pF",
1662+
TP_printk("dev %d,%d blocks, %d rsv_blocks, %d caller %pF",
16601663
MAJOR(__entry->dev), MINOR(__entry->dev),
1661-
__entry->nblocks, (void *)__entry->ip)
1664+
__entry->blocks, __entry->rsv_blocks, (void *)__entry->ip)
1665+
);
1666+
1667+
TRACE_EVENT(ext4_journal_start_reserved,
1668+
TP_PROTO(struct super_block *sb, int blocks, unsigned long IP),
1669+
1670+
TP_ARGS(sb, blocks, IP),
1671+
1672+
TP_STRUCT__entry(
1673+
__field( dev_t, dev )
1674+
__field(unsigned long, ip )
1675+
__field( int, blocks )
1676+
),
1677+
1678+
TP_fast_assign(
1679+
__entry->dev = sb->s_dev;
1680+
__entry->ip = IP;
1681+
__entry->blocks = blocks;
1682+
),
1683+
1684+
TP_printk("dev %d,%d blocks, %d caller %pF",
1685+
MAJOR(__entry->dev), MINOR(__entry->dev),
1686+
__entry->blocks, (void *)__entry->ip)
16621687
);
16631688

16641689
DECLARE_EVENT_CLASS(ext4__trim,

0 commit comments

Comments
 (0)