Skip to content

Commit 1bc333f

Browse files
bmarzinsswhiteho
authored andcommitted
GFS2: don't overrun reserved revokes
When run during fsync, a gfs2_log_flush could happen between the time when gfs2_ail_flush checked the number of blocks to revoke, and when it actually started the transaction to do those revokes. This occassionally caused it to need more revokes than it reserved, causing gfs2 to crash. Instead of just reserving enough revokes to handle the blocks that currently need them, this patch makes gfs2_ail_flush reserve the maximum number of revokes it can, without increasing the total number of reserved log blocks. This patch also passes the number of reserved revokes to __gfs2_ail_flush() so that it doesn't go over its limit and cause a crash like we're seeing. Non-fsync calls to __gfs2_ail_flush will still cause a BUG() necessary revokes are skipped. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent d08fa65 commit 1bc333f

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎fs/gfs2/glops.c‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ static void gfs2_ail_error(struct gfs2_glock *gl, const struct buffer_head *bh)
4747
* None of the buffers should be dirty, locked, or pinned.
4848
*/
4949

50-
static void __gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
50+
static void __gfs2_ail_flush(struct gfs2_glock *gl, bool fsync,
51+
unsigned int nr_revokes)
5152
{
5253
struct gfs2_sbd *sdp = gl->gl_sbd;
5354
struct list_head *head = &gl->gl_ail_list;
@@ -57,14 +58,17 @@ static void __gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
5758

5859
gfs2_log_lock(sdp);
5960
spin_lock(&sdp->sd_ail_lock);
60-
list_for_each_entry_safe(bd, tmp, head, bd_ail_gl_list) {
61+
list_for_each_entry_safe_reverse(bd, tmp, head, bd_ail_gl_list) {
62+
if (nr_revokes == 0)
63+
break;
6164
bh = bd->bd_bh;
6265
if (bh->b_state & b_state) {
6366
if (fsync)
6467
continue;
6568
gfs2_ail_error(gl, bh);
6669
}
6770
gfs2_trans_add_revoke(sdp, bd);
71+
nr_revokes--;
6872
}
6973
GLOCK_BUG_ON(gl, !fsync && atomic_read(&gl->gl_ail_count));
7074
spin_unlock(&sdp->sd_ail_lock);
@@ -91,7 +95,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
9195
WARN_ON_ONCE(current->journal_info);
9296
current->journal_info = &tr;
9397

94-
__gfs2_ail_flush(gl, 0);
98+
__gfs2_ail_flush(gl, 0, tr.tr_revokes);
9599

96100
gfs2_trans_end(sdp);
97101
gfs2_log_flush(sdp, NULL);
@@ -101,15 +105,19 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
101105
{
102106
struct gfs2_sbd *sdp = gl->gl_sbd;
103107
unsigned int revokes = atomic_read(&gl->gl_ail_count);
108+
unsigned int max_revokes = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / sizeof(u64);
104109
int ret;
105110

106111
if (!revokes)
107112
return;
108113

109-
ret = gfs2_trans_begin(sdp, 0, revokes);
114+
while (revokes > max_revokes)
115+
max_revokes += (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header)) / sizeof(u64);
116+
117+
ret = gfs2_trans_begin(sdp, 0, max_revokes);
110118
if (ret)
111119
return;
112-
__gfs2_ail_flush(gl, fsync);
120+
__gfs2_ail_flush(gl, fsync, max_revokes);
113121
gfs2_trans_end(sdp);
114122
gfs2_log_flush(sdp, NULL);
115123
}

0 commit comments

Comments
 (0)