Skip to content

Commit d3add1a

Browse files
AstralBobAndreas Gruenbacher
authored andcommitted
gfs2: Fix gfs2_release for non-writers regression
When a file is opened for writing, the vfs code (do_dentry_open) calls get_write_access for the inode, thus incrementing the inode's write count. That writer normally then creates a multi-block reservation for the inode (i_res) that can be re-used by other writers, which speeds up writes for applications that stupidly loop on open/write/close. When the writes are all done, the multi-block reservation should be deleted when the file is closed by the last "writer." Commit 0ec9b9e broke that concept when it moved the call to gfs2_rs_delete before the check for FMODE_WRITE. Non-writers have no business removing the multi-block reservations of writers. In fact, if someone opens and closes the file for RO while a writer has a multi-block reservation, the RO closer will delete the reservation midway through the write, and this results in: kernel BUG at fs/gfs2/rgrp.c:677! (or thereabouts) which is: BUG_ON(rs->rs_requested); from function gfs2_rs_deltree. This patch moves the check back inside the check for FMODE_WRITE. Fixes: 0ec9b9e ("gfs2: Check for active reservation in gfs2_release") Cc: [email protected] # v5.12+ Signed-off-by: Bob Peterson <[email protected]> Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 356b810 commit d3add1a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/gfs2/file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,11 @@ static int gfs2_release(struct inode *inode, struct file *file)
704704
kfree(file->private_data);
705705
file->private_data = NULL;
706706

707-
if (gfs2_rs_active(&ip->i_res))
708-
gfs2_rs_delete(ip, &inode->i_writecount);
709-
if (file->f_mode & FMODE_WRITE)
707+
if (file->f_mode & FMODE_WRITE) {
708+
if (gfs2_rs_active(&ip->i_res))
709+
gfs2_rs_delete(ip, &inode->i_writecount);
710710
gfs2_qa_put(ip);
711+
}
711712
return 0;
712713
}
713714

0 commit comments

Comments
 (0)