Skip to content

Commit

Permalink
zonefs: fix to update .i_wr_refcnt correctly in zonefs_open_zone()
Browse files Browse the repository at this point in the history
In zonefs_open_zone(), if opened zone count is larger than
.s_max_open_zones threshold, we missed to recover .i_wr_refcnt,
fix this.

Fixes: b5c00e9 ("zonefs: open/close zone on file open/close")
Cc: <stable@vger.kernel.org>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
  • Loading branch information
Chao Yu authored and Damien Le Moal committed Mar 16, 2021
1 parent ebfd68c commit 6980d29
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions fs/zonefs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1040,9 +1040,7 @@ static int zonefs_open_zone(struct inode *inode)

mutex_lock(&zi->i_truncate_mutex);

zi->i_wr_refcnt++;
if (zi->i_wr_refcnt == 1) {

if (!zi->i_wr_refcnt) {
if (atomic_inc_return(&sbi->s_open_zones) > sbi->s_max_open_zones) {
atomic_dec(&sbi->s_open_zones);
ret = -EBUSY;
Expand All @@ -1052,14 +1050,15 @@ static int zonefs_open_zone(struct inode *inode)
if (i_size_read(inode) < zi->i_max_size) {
ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_OPEN);
if (ret) {
zi->i_wr_refcnt--;
atomic_dec(&sbi->s_open_zones);
goto unlock;
}
zi->i_flags |= ZONEFS_ZONE_OPEN;
}
}

zi->i_wr_refcnt++;

unlock:
mutex_unlock(&zi->i_truncate_mutex);

Expand Down

0 comments on commit 6980d29

Please sign in to comment.