Skip to content

Commit b5b24d7

Browse files
committed
GFS2: Fix AIL flush issue during fsync
Unfortunately, it is not enough to just ignore locked buffers during the AIL flush from fsync. We need to be able to ignore all buffers which are locked, dirty or pinned at this stage as they might have been added subsequent to the log flush earlier in the fsync function. In addition, this means that we no longer need to rely on i_mutex to keep out writes during fsync, so we can, as a side-effect, remove that protection too. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com> Tested-By: Abhijith Das <adas@redhat.com>
1 parent 70b0c36 commit b5b24d7

4 files changed

Lines changed: 20 additions & 24 deletions

File tree

‎fs/gfs2/file.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,16 +593,12 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
593593
sync_state &= ~I_DIRTY_SYNC;
594594

595595
if (sync_state) {
596-
mutex_lock(&inode->i_mutex);
597596
ret = sync_inode_metadata(inode, 1);
598-
if (ret) {
599-
mutex_unlock(&inode->i_mutex);
597+
if (ret)
600598
return ret;
601-
}
602599
if (gfs2_is_jdata(ip))
603600
filemap_write_and_wait(mapping);
604-
gfs2_ail_flush(ip->i_gl);
605-
mutex_unlock(&inode->i_mutex);
601+
gfs2_ail_flush(ip->i_gl, 1);
606602
}
607603

608604
if (mapping->nrpages)

‎fs/gfs2/glops.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,41 @@ static void gfs2_ail_error(struct gfs2_glock *gl, const struct buffer_head *bh)
4242
/**
4343
* __gfs2_ail_flush - remove all buffers for a given lock from the AIL
4444
* @gl: the glock
45+
* @fsync: set when called from fsync (not all buffers will be clean)
4546
*
4647
* None of the buffers should be dirty, locked, or pinned.
4748
*/
4849

49-
static void __gfs2_ail_flush(struct gfs2_glock *gl, unsigned long b_state)
50+
static void __gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
5051
{
5152
struct gfs2_sbd *sdp = gl->gl_sbd;
5253
struct list_head *head = &gl->gl_ail_list;
53-
struct gfs2_bufdata *bd;
54+
struct gfs2_bufdata *bd, *tmp;
5455
struct buffer_head *bh;
56+
const unsigned long b_state = (1UL << BH_Dirty)|(1UL << BH_Pinned)|(1UL << BH_Lock);
5557
sector_t blocknr;
5658

59+
gfs2_log_lock(sdp);
5760
spin_lock(&sdp->sd_ail_lock);
58-
while (!list_empty(head)) {
59-
bd = list_entry(head->next, struct gfs2_bufdata,
60-
bd_ail_gl_list);
61+
list_for_each_entry_safe(bd, tmp, head, bd_ail_gl_list) {
6162
bh = bd->bd_bh;
62-
blocknr = bh->b_blocknr;
63-
if (bh->b_state & b_state)
63+
if (bh->b_state & b_state) {
64+
if (fsync)
65+
continue;
6466
gfs2_ail_error(gl, bh);
67+
}
68+
blocknr = bh->b_blocknr;
6569
bh->b_private = NULL;
6670
gfs2_remove_from_ail(bd); /* drops ref on bh */
67-
spin_unlock(&sdp->sd_ail_lock);
6871

6972
bd->bd_bh = NULL;
7073
bd->bd_blkno = blocknr;
7174

72-
gfs2_log_lock(sdp);
7375
gfs2_trans_add_revoke(sdp, bd);
74-
gfs2_log_unlock(sdp);
75-
76-
spin_lock(&sdp->sd_ail_lock);
7776
}
78-
gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
77+
BUG_ON(!fsync && atomic_read(&gl->gl_ail_count));
7978
spin_unlock(&sdp->sd_ail_lock);
79+
gfs2_log_unlock(sdp);
8080
}
8181

8282

@@ -99,13 +99,13 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
9999
BUG_ON(current->journal_info);
100100
current->journal_info = &tr;
101101

102-
__gfs2_ail_flush(gl, (1ul << BH_Dirty)|(1ul << BH_Pinned)|(1ul << BH_Lock));
102+
__gfs2_ail_flush(gl, 0);
103103

104104
gfs2_trans_end(sdp);
105105
gfs2_log_flush(sdp, NULL);
106106
}
107107

108-
void gfs2_ail_flush(struct gfs2_glock *gl)
108+
void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
109109
{
110110
struct gfs2_sbd *sdp = gl->gl_sbd;
111111
unsigned int revokes = atomic_read(&gl->gl_ail_count);
@@ -117,7 +117,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl)
117117
ret = gfs2_trans_begin(sdp, 0, revokes);
118118
if (ret)
119119
return;
120-
__gfs2_ail_flush(gl, (1ul << BH_Dirty)|(1ul << BH_Pinned));
120+
__gfs2_ail_flush(gl, fsync);
121121
gfs2_trans_end(sdp);
122122
gfs2_log_flush(sdp, NULL);
123123
}

‎fs/gfs2/glops.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ extern const struct gfs2_glock_operations gfs2_quota_glops;
2323
extern const struct gfs2_glock_operations gfs2_journal_glops;
2424
extern const struct gfs2_glock_operations *gfs2_glops_list[];
2525

26-
extern void gfs2_ail_flush(struct gfs2_glock *gl);
26+
extern void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync);
2727

2828
#endif /* __GLOPS_DOT_H__ */

‎fs/gfs2/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ static void gfs2_evict_inode(struct inode *inode)
15331533
out_truncate:
15341534
gfs2_log_flush(sdp, ip->i_gl);
15351535
write_inode_now(inode, 1);
1536-
gfs2_ail_flush(ip->i_gl);
1536+
gfs2_ail_flush(ip->i_gl, 0);
15371537

15381538
/* Case 2 starts here */
15391539
error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);

0 commit comments

Comments
 (0)