Skip to contentSkip to conversation

zonefs: fix to update .i_wr_refcnt correctly in zonefs_open_zone()

PATCH In review Chao Yu 2 participants 3 messages Mar 16, 2021 – Mar 17, 2021

Subsystems (2)
lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 zonefs: fix to update .i_wr_refcnt correctly in zonefs_open_zone()

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 b5c00e975779 ("zonefs: open/close zone on file open/close")
---
 fs/zonefs/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/zonefs/super.c +3 -3
index 0fe76f376dee..be6b99f7de74 100644
@@ -966,8 +966,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 == 0) {
 
 		if (atomic_inc_return(&sbi->s_open_zones) > sbi->s_max_open_zones) {
 			atomic_dec(&sbi->s_open_zones);
@@ -978,7 +977,6 @@ 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;
 			}
@@ -986,6 +984,8 @@ static int zonefs_open_zone(struct inode *inode)
 		}
 	}
 
+	zi->i_wr_refcnt++;
+
 unlock:
 	mutex_unlock(&zi->i_truncate_mutex);
 
Signature · 1 line
2.29.2
#1 lore raw
Quoted 15 lines · Chao Yu

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 b5c00e975779 ("zonefs: open/close zone on file open/close")
---
 fs/zonefs/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/zonefs/super.c +0 -0
index 0fe76f376dee..be6b99f7de74 100644

fs/zonefs/super.c static int zonefs_open_zone(struct inode *inode) · line 969

Quoted 6 lines
fs/zonefs/super.c +1 -2
@@ -966,8 +966,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 == 0) {

Nit: if (!zi->i_wr_refcnt) ? I can change that when applying.

Quoted 13 lines
fs/zonefs/super.c +0 -1
 		if (atomic_inc_return(&sbi->s_open_zones) > sbi->s_max_open_zones) {
 			atomic_dec(&sbi->s_open_zones);
@@ -978,7 +977,6 @@ 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;
 			}

fs/zonefs/super.c static int zonefs_open_zone(struct inode *inode) · line 991

Quoted 8 lines
fs/zonefs/super.c +2 -0
@@ -986,6 +984,8 @@ static int zonefs_open_zone(struct inode *inode)
 		}
 	}
 
+	zi->i_wr_refcnt++;
+
 unlock:
 	mutex_unlock(&zi->i_truncate_mutex);
 

Good catch ! Will apply this and check zonefs test suite as this bug went undetected.

Thanks.

Signature · 2 lines
Damien Le Moal
Western Digital Research
author
#2 lore raw
Quoted 17 lines · Damien Le Moal
Quoted 16 lines · Chao Yu

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 b5c00e975779 ("zonefs: open/close zone on file open/close")
---
  fs/zonefs/super.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
fs/zonefs/super.c +0 -0
index 0fe76f376dee..be6b99f7de74 100644
@@ -966,8 +966,7 @@ static int zonefs_open_zone(struct inode *inode)
 
Quoted 7 lines

fs/zonefs/super.c static int zonefs_open_zone(struct inode *inode) · line 969

Quoted 5 lines
fs/zonefs/super.c +1 -2
  	mutex_lock(&zi->i_truncate_mutex);
 
-	zi->i_wr_refcnt++;
-	if (zi->i_wr_refcnt == 1) {
+	if (zi->i_wr_refcnt == 0) {

Nit: if (!zi->i_wr_refcnt) ? I can change that when applying.

More clean, thanks. :)

Thanks,

Quoted 28 lines
Quoted 14 lines
fs/zonefs/super.c +0 -1
  		if (atomic_inc_return(&sbi->s_open_zones) > sbi->s_max_open_zones) {
  			atomic_dec(&sbi->s_open_zones);
@@ -978,7 +977,6 @@ 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;
  			}

fs/zonefs/super.c static int zonefs_open_zone(struct inode *inode) · line 991

Quoted 8 lines
fs/zonefs/super.c +2 -0
@@ -986,6 +984,8 @@ static int zonefs_open_zone(struct inode *inode)
  		}
  	}
 
+	zi->i_wr_refcnt++;
+
  unlock:
  	mutex_unlock(&zi->i_truncate_mutex);
 

Good catch ! Will apply this and check zonefs test suite as this bug went undetected.

Thanks.