stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] zonefs: Fix management of open zones" failed to apply to 5.18-stable tree
@ 2022-06-06 12:28 gregkh
  2022-06-07  5:36 ` Damien Le Moal
  0 siblings, 1 reply; 2+ messages in thread
From: gregkh @ 2022-06-06 12:28 UTC (permalink / raw)
  To: damien.lemoal, hans.holmberg, johannes.thumshirn, stable; +Cc: stable


The patch below does not apply to the 5.18-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 19139539207934aef6335bdef09c9e4bd70d1808 Mon Sep 17 00:00:00 2001
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Date: Tue, 12 Apr 2022 17:41:37 +0900
Subject: [PATCH] zonefs: Fix management of open zones

The mount option "explicit_open" manages the device open zone
resources to ensure that if an application opens a sequential file for
writing, the file zone can always be written by explicitly opening
the zone and accounting for that state with the s_open_zones counter.

However, if some zones are already open when mounting, the device open
zone resource usage status will be larger than the initial s_open_zones
value of 0. Ensure that this inconsistency does not happen by closing
any sequential zone that is open when mounting.

Furthermore, with ZNS drives, closing an explicitly open zone that has
not been written will change the zone state to "closed", that is, the
zone will remain in an active state. Since this can then cause failures
of explicit open operations on other zones if the drive active zone
resources are exceeded, we need to make sure that the zone is not
active anymore by resetting it instead of closing it. To address this,
zonefs_zone_mgmt() is modified to change a REQ_OP_ZONE_CLOSE request
into a REQ_OP_ZONE_RESET for sequential zones that have not been
written.

Fixes: b5c00e975779 ("zonefs: open/close zone on file open/close")
Cc: <stable@vger.kernel.org>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com>

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index 75d8dabe0807..e20e7c841489 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -35,6 +35,17 @@ static inline int zonefs_zone_mgmt(struct inode *inode,
 
 	lockdep_assert_held(&zi->i_truncate_mutex);
 
+	/*
+	 * With ZNS drives, closing an explicitly open zone that has not been
+	 * written will change the zone state to "closed", that is, the zone
+	 * will remain active. Since this can then cause failure of explicit
+	 * open operation on other zones if the drive active zone resources
+	 * are exceeded, make sure that the zone does not remain active by
+	 * resetting it.
+	 */
+	if (op == REQ_OP_ZONE_CLOSE && !zi->i_wpoffset)
+		op = REQ_OP_ZONE_RESET;
+
 	trace_zonefs_zone_mgmt(inode, op);
 	ret = blkdev_zone_mgmt(inode->i_sb->s_bdev, op, zi->i_zsector,
 			       zi->i_zone_size >> SECTOR_SHIFT, GFP_NOFS);
@@ -1294,12 +1305,13 @@ static void zonefs_init_dir_inode(struct inode *parent, struct inode *inode,
 	inc_nlink(parent);
 }
 
-static void zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone,
-				   enum zonefs_ztype type)
+static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone,
+				  enum zonefs_ztype type)
 {
 	struct super_block *sb = inode->i_sb;
 	struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
 	struct zonefs_inode_info *zi = ZONEFS_I(inode);
+	int ret = 0;
 
 	inode->i_ino = zone->start >> sbi->s_zone_sectors_shift;
 	inode->i_mode = S_IFREG | sbi->s_perm;
@@ -1324,6 +1336,22 @@ static void zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone,
 	sb->s_maxbytes = max(zi->i_max_size, sb->s_maxbytes);
 	sbi->s_blocks += zi->i_max_size >> sb->s_blocksize_bits;
 	sbi->s_used_blocks += zi->i_wpoffset >> sb->s_blocksize_bits;
+
+	/*
+	 * For sequential zones, make sure that any open zone is closed first
+	 * to ensure that the initial number of open zones is 0, in sync with
+	 * the open zone accounting done when the mount option
+	 * ZONEFS_MNTOPT_EXPLICIT_OPEN is used.
+	 */
+	if (type == ZONEFS_ZTYPE_SEQ &&
+	    (zone->cond == BLK_ZONE_COND_IMP_OPEN ||
+	     zone->cond == BLK_ZONE_COND_EXP_OPEN)) {
+		mutex_lock(&zi->i_truncate_mutex);
+		ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_CLOSE);
+		mutex_unlock(&zi->i_truncate_mutex);
+	}
+
+	return ret;
 }
 
 static struct dentry *zonefs_create_inode(struct dentry *parent,
@@ -1333,6 +1361,7 @@ static struct dentry *zonefs_create_inode(struct dentry *parent,
 	struct inode *dir = d_inode(parent);
 	struct dentry *dentry;
 	struct inode *inode;
+	int ret;
 
 	dentry = d_alloc_name(parent, name);
 	if (!dentry)
@@ -1343,10 +1372,16 @@ static struct dentry *zonefs_create_inode(struct dentry *parent,
 		goto dput;
 
 	inode->i_ctime = inode->i_mtime = inode->i_atime = dir->i_ctime;
-	if (zone)
-		zonefs_init_file_inode(inode, zone, type);
-	else
+	if (zone) {
+		ret = zonefs_init_file_inode(inode, zone, type);
+		if (ret) {
+			iput(inode);
+			goto dput;
+		}
+	} else {
 		zonefs_init_dir_inode(dir, inode, type);
+	}
+
 	d_add(dentry, inode);
 	dir->i_size++;
 


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: FAILED: patch "[PATCH] zonefs: Fix management of open zones" failed to apply to 5.18-stable tree
  2022-06-06 12:28 FAILED: patch "[PATCH] zonefs: Fix management of open zones" failed to apply to 5.18-stable tree gregkh
@ 2022-06-07  5:36 ` Damien Le Moal
  0 siblings, 0 replies; 2+ messages in thread
From: Damien Le Moal @ 2022-06-07  5:36 UTC (permalink / raw)
  To: gregkh, hans.holmberg, johannes.thumshirn, stable

On 6/6/22 21:28, gregkh@linuxfoundation.org wrote:
> 
> The patch below does not apply to the 5.18-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.
> 
> thanks,
> 
> greg k-h

Greg,

This patch is already applied to 5.18, 5.17, 5.15 and 5.10. I think that 
your bot picked it up again because of the bad PR I sent to Linus for 
5.19 which had these patches included again.

My apologies for the noise.

Thanks !

> 
> ------------------ original commit in Linus's tree ------------------
> 
>  From 19139539207934aef6335bdef09c9e4bd70d1808 Mon Sep 17 00:00:00 2001
> From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> Date: Tue, 12 Apr 2022 17:41:37 +0900
> Subject: [PATCH] zonefs: Fix management of open zones
> 
> The mount option "explicit_open" manages the device open zone
> resources to ensure that if an application opens a sequential file for
> writing, the file zone can always be written by explicitly opening
> the zone and accounting for that state with the s_open_zones counter.
> 
> However, if some zones are already open when mounting, the device open
> zone resource usage status will be larger than the initial s_open_zones
> value of 0. Ensure that this inconsistency does not happen by closing
> any sequential zone that is open when mounting.
> 
> Furthermore, with ZNS drives, closing an explicitly open zone that has
> not been written will change the zone state to "closed", that is, the
> zone will remain in an active state. Since this can then cause failures
> of explicit open operations on other zones if the drive active zone
> resources are exceeded, we need to make sure that the zone is not
> active anymore by resetting it instead of closing it. To address this,
> zonefs_zone_mgmt() is modified to change a REQ_OP_ZONE_CLOSE request
> into a REQ_OP_ZONE_RESET for sequential zones that have not been
> written.
> 
> Fixes: b5c00e975779 ("zonefs: open/close zone on file open/close")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com>
> 
> diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
> index 75d8dabe0807..e20e7c841489 100644
> --- a/fs/zonefs/super.c
> +++ b/fs/zonefs/super.c
> @@ -35,6 +35,17 @@ static inline int zonefs_zone_mgmt(struct inode *inode,
>   
>   	lockdep_assert_held(&zi->i_truncate_mutex);
>   
> +	/*
> +	 * With ZNS drives, closing an explicitly open zone that has not been
> +	 * written will change the zone state to "closed", that is, the zone
> +	 * will remain active. Since this can then cause failure of explicit
> +	 * open operation on other zones if the drive active zone resources
> +	 * are exceeded, make sure that the zone does not remain active by
> +	 * resetting it.
> +	 */
> +	if (op == REQ_OP_ZONE_CLOSE && !zi->i_wpoffset)
> +		op = REQ_OP_ZONE_RESET;
> +
>   	trace_zonefs_zone_mgmt(inode, op);
>   	ret = blkdev_zone_mgmt(inode->i_sb->s_bdev, op, zi->i_zsector,
>   			       zi->i_zone_size >> SECTOR_SHIFT, GFP_NOFS);
> @@ -1294,12 +1305,13 @@ static void zonefs_init_dir_inode(struct inode *parent, struct inode *inode,
>   	inc_nlink(parent);
>   }
>   
> -static void zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone,
> -				   enum zonefs_ztype type)
> +static int zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone,
> +				  enum zonefs_ztype type)
>   {
>   	struct super_block *sb = inode->i_sb;
>   	struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
>   	struct zonefs_inode_info *zi = ZONEFS_I(inode);
> +	int ret = 0;
>   
>   	inode->i_ino = zone->start >> sbi->s_zone_sectors_shift;
>   	inode->i_mode = S_IFREG | sbi->s_perm;
> @@ -1324,6 +1336,22 @@ static void zonefs_init_file_inode(struct inode *inode, struct blk_zone *zone,
>   	sb->s_maxbytes = max(zi->i_max_size, sb->s_maxbytes);
>   	sbi->s_blocks += zi->i_max_size >> sb->s_blocksize_bits;
>   	sbi->s_used_blocks += zi->i_wpoffset >> sb->s_blocksize_bits;
> +
> +	/*
> +	 * For sequential zones, make sure that any open zone is closed first
> +	 * to ensure that the initial number of open zones is 0, in sync with
> +	 * the open zone accounting done when the mount option
> +	 * ZONEFS_MNTOPT_EXPLICIT_OPEN is used.
> +	 */
> +	if (type == ZONEFS_ZTYPE_SEQ &&
> +	    (zone->cond == BLK_ZONE_COND_IMP_OPEN ||
> +	     zone->cond == BLK_ZONE_COND_EXP_OPEN)) {
> +		mutex_lock(&zi->i_truncate_mutex);
> +		ret = zonefs_zone_mgmt(inode, REQ_OP_ZONE_CLOSE);
> +		mutex_unlock(&zi->i_truncate_mutex);
> +	}
> +
> +	return ret;
>   }
>   
>   static struct dentry *zonefs_create_inode(struct dentry *parent,
> @@ -1333,6 +1361,7 @@ static struct dentry *zonefs_create_inode(struct dentry *parent,
>   	struct inode *dir = d_inode(parent);
>   	struct dentry *dentry;
>   	struct inode *inode;
> +	int ret;
>   
>   	dentry = d_alloc_name(parent, name);
>   	if (!dentry)
> @@ -1343,10 +1372,16 @@ static struct dentry *zonefs_create_inode(struct dentry *parent,
>   		goto dput;
>   
>   	inode->i_ctime = inode->i_mtime = inode->i_atime = dir->i_ctime;
> -	if (zone)
> -		zonefs_init_file_inode(inode, zone, type);
> -	else
> +	if (zone) {
> +		ret = zonefs_init_file_inode(inode, zone, type);
> +		if (ret) {
> +			iput(inode);
> +			goto dput;
> +		}
> +	} else {
>   		zonefs_init_dir_inode(dir, inode, type);
> +	}
> +
>   	d_add(dentry, inode);
>   	dir->i_size++;
>   
> 


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-07  5:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-06 12:28 FAILED: patch "[PATCH] zonefs: Fix management of open zones" failed to apply to 5.18-stable tree gregkh
2022-06-07  5:36 ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).