diff mbox series

[v4,2/4] zonefs: provide zonefs_io_error variant that can be called with i_truncate_mutex held

Message ID 20200910143744.17295-3-johannes.thumshirn@wdc.com (mailing list archive)
State New, archived
Headers show
Series zonefs: introduce helper for zone management | expand

Commit Message

Johannes Thumshirn Sept. 10, 2020, 2:37 p.m. UTC
Subsequent patches need to call zonefs_io_error() with the i_truncate_mutex
already held, so factor out the body of zonefs_io_error() into
__zonefs_io_error() which can be called from with the i_truncate_mutex
held.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 fs/zonefs/super.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

Comments

Damien Le Moal Sept. 11, 2020, 5:05 a.m. UTC | #1
On 2020/09/10 23:37, Johannes Thumshirn wrote:
> Subsequent patches need to call zonefs_io_error() with the i_truncate_mutex
> already held, so factor out the body of zonefs_io_error() into
> __zonefs_io_error() which can be called from with the i_truncate_mutex
> held.
> 
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>  fs/zonefs/super.c | 25 +++++++++++++++----------
>  1 file changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
> index 6e13a5127b01..3db28a06e1a2 100644
> --- a/fs/zonefs/super.c
> +++ b/fs/zonefs/super.c
> @@ -341,14 +341,7 @@ static int zonefs_io_error_cb(struct blk_zone *zone, unsigned int idx,
>  	return 0;
>  }
>  
> -/*
> - * When an file IO error occurs, check the file zone to see if there is a change
> - * in the zone condition (e.g. offline or read-only). For a failed write to a
> - * sequential zone, the zone write pointer position must also be checked to
> - * eventually correct the file size and zonefs inode write pointer offset
> - * (which can be out of sync with the drive due to partial write failures).
> - */
> -static void zonefs_io_error(struct inode *inode, bool write)
> +static void __zonefs_io_error(struct inode *inode, bool write)
>  {
>  	struct zonefs_inode_info *zi = ZONEFS_I(inode);
>  	struct super_block *sb = inode->i_sb;
> @@ -362,8 +355,6 @@ static void zonefs_io_error(struct inode *inode, bool write)
>  	};
>  	int ret;
>  
> -	mutex_lock(&zi->i_truncate_mutex);
> -
>  	/*
>  	 * Memory allocations in blkdev_report_zones() can trigger a memory
>  	 * reclaim which may in turn cause a recursion into zonefs as well as
> @@ -379,7 +370,21 @@ static void zonefs_io_error(struct inode *inode, bool write)
>  		zonefs_err(sb, "Get inode %lu zone information failed %d\n",
>  			   inode->i_ino, ret);
>  	memalloc_noio_restore(noio_flag);
> +}
>  
> +/*
> + * When an file IO error occurs, check the file zone to see if there is a change
> + * in the zone condition (e.g. offline or read-only). For a failed write to a
> + * sequential zone, the zone write pointer position must also be checked to
> + * eventually correct the file size and zonefs inode write pointer offset
> + * (which can be out of sync with the drive due to partial write failures).
> + */

I would prefer to leave this comment attached to the function body, so
__zonefs_io_error() now.

> +static void zonefs_io_error(struct inode *inode, bool write)
> +{
> +	struct zonefs_inode_info *zi = ZONEFS_I(inode);
> +
> +	mutex_lock(&zi->i_truncate_mutex);
> +	__zonefs_io_error(inode, write);
>  	mutex_unlock(&zi->i_truncate_mutex);
>  }
>  
> 

Apart from this nit, looks good.
Johannes Thumshirn Sept. 11, 2020, 7:52 a.m. UTC | #2
On 11/09/2020 07:05, Damien Le Moal wrote:
> I would prefer to leave this comment attached to the function body, so
> __zonefs_io_error() now.

Also fixed.

Last test run is running and then I'm sending out the new version.
diff mbox series

Patch

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index 6e13a5127b01..3db28a06e1a2 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -341,14 +341,7 @@  static int zonefs_io_error_cb(struct blk_zone *zone, unsigned int idx,
 	return 0;
 }
 
-/*
- * When an file IO error occurs, check the file zone to see if there is a change
- * in the zone condition (e.g. offline or read-only). For a failed write to a
- * sequential zone, the zone write pointer position must also be checked to
- * eventually correct the file size and zonefs inode write pointer offset
- * (which can be out of sync with the drive due to partial write failures).
- */
-static void zonefs_io_error(struct inode *inode, bool write)
+static void __zonefs_io_error(struct inode *inode, bool write)
 {
 	struct zonefs_inode_info *zi = ZONEFS_I(inode);
 	struct super_block *sb = inode->i_sb;
@@ -362,8 +355,6 @@  static void zonefs_io_error(struct inode *inode, bool write)
 	};
 	int ret;
 
-	mutex_lock(&zi->i_truncate_mutex);
-
 	/*
 	 * Memory allocations in blkdev_report_zones() can trigger a memory
 	 * reclaim which may in turn cause a recursion into zonefs as well as
@@ -379,7 +370,21 @@  static void zonefs_io_error(struct inode *inode, bool write)
 		zonefs_err(sb, "Get inode %lu zone information failed %d\n",
 			   inode->i_ino, ret);
 	memalloc_noio_restore(noio_flag);
+}
 
+/*
+ * When an file IO error occurs, check the file zone to see if there is a change
+ * in the zone condition (e.g. offline or read-only). For a failed write to a
+ * sequential zone, the zone write pointer position must also be checked to
+ * eventually correct the file size and zonefs inode write pointer offset
+ * (which can be out of sync with the drive due to partial write failures).
+ */
+static void zonefs_io_error(struct inode *inode, bool write)
+{
+	struct zonefs_inode_info *zi = ZONEFS_I(inode);
+
+	mutex_lock(&zi->i_truncate_mutex);
+	__zonefs_io_error(inode, write);
 	mutex_unlock(&zi->i_truncate_mutex);
 }