diff mbox series

[04/11] md-bitmap: split file writes into a separate helper

Message ID 20230615064840.629492-5-hch@lst.de (mailing list archive)
State Accepted, archived
Headers show
Series [01/11] md-bitmap: set BITMAP_WRITE_ERROR in write_sb_page | expand

Commit Message

Christoph Hellwig June 15, 2023, 6:48 a.m. UTC
Split the file write code out of write_page into a separate helper.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/md/md-bitmap.c | 48 +++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

Comments

Hannes Reinecke June 15, 2023, 6:59 a.m. UTC | #1
On 6/15/23 08:48, Christoph Hellwig wrote:
> Split the file write code out of write_page into a separate helper.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   drivers/md/md-bitmap.c | 48 +++++++++++++++++++++---------------------
>   1 file changed, 24 insertions(+), 24 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Johannes Thumshirn June 15, 2023, 2:26 p.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Himanshu Madhani June 15, 2023, 6:13 p.m. UTC | #3
> On Jun 14, 2023, at 11:48 PM, Christoph Hellwig <hch@lst.de> wrote:
> 
> Split the file write code out of write_page into a separate helper.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/md/md-bitmap.c | 48 +++++++++++++++++++++---------------------
> 1 file changed, 24 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index e4b466522d4e74..46fbcfc9d1fcac 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -296,33 +296,22 @@ static void write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
> }
> 
> static void md_bitmap_file_kick(struct bitmap *bitmap);
> -/*
> - * write out a page to a file
> - */
> -static void write_page(struct bitmap *bitmap, struct page *page, int wait)
> -{
> - struct buffer_head *bh;
> 
> - if (bitmap->storage.file == NULL) {
> - write_sb_page(bitmap, page, wait);
> - } else {
> -
> - bh = page_buffers(page);
> -
> - while (bh && bh->b_blocknr) {
> - atomic_inc(&bitmap->pending_writes);
> - set_buffer_locked(bh);
> - set_buffer_mapped(bh);
> - submit_bh(REQ_OP_WRITE | REQ_SYNC, bh);
> - bh = bh->b_this_page;
> - }
> +static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
> +{
> + struct buffer_head *bh = page_buffers(page);
> 
> - if (wait)
> - wait_event(bitmap->write_wait,
> -   atomic_read(&bitmap->pending_writes)==0);
> + while (bh && bh->b_blocknr) {
> + atomic_inc(&bitmap->pending_writes);
> + set_buffer_locked(bh);
> + set_buffer_mapped(bh);
> + submit_bh(REQ_OP_WRITE | REQ_SYNC, bh);
> + bh = bh->b_this_page;
> }
> - if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
> - md_bitmap_file_kick(bitmap);
> +
> + if (wait)
> + wait_event(bitmap->write_wait,
> +   atomic_read(&bitmap->pending_writes) == 0);
> }
> 
> static void end_bitmap_write(struct buffer_head *bh, int uptodate)
> @@ -429,6 +418,17 @@ static int read_page(struct file *file, unsigned long index,
>  * bitmap file superblock operations
>  */
> 
> +/*
> + * write out a page to a file
> + */
> +static void write_page(struct bitmap *bitmap, struct page *page, int wait)
> +{
> + if (bitmap->storage.file)
> + write_file_page(bitmap, page, wait);
> + else
> + write_sb_page(bitmap, page, wait);
> +}
> +
> /*
>  * md_bitmap_wait_writes() should be called before writing any bitmap
>  * blocks, to ensure previous writes, particularly from
> -- 
> 2.39.2
> 

Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
diff mbox series

Patch

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index e4b466522d4e74..46fbcfc9d1fcac 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -296,33 +296,22 @@  static void write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
 }
 
 static void md_bitmap_file_kick(struct bitmap *bitmap);
-/*
- * write out a page to a file
- */
-static void write_page(struct bitmap *bitmap, struct page *page, int wait)
-{
-	struct buffer_head *bh;
 
-	if (bitmap->storage.file == NULL) {
-		write_sb_page(bitmap, page, wait);
-	} else {
-
-		bh = page_buffers(page);
-
-		while (bh && bh->b_blocknr) {
-			atomic_inc(&bitmap->pending_writes);
-			set_buffer_locked(bh);
-			set_buffer_mapped(bh);
-			submit_bh(REQ_OP_WRITE | REQ_SYNC, bh);
-			bh = bh->b_this_page;
-		}
+static void write_file_page(struct bitmap *bitmap, struct page *page, int wait)
+{
+	struct buffer_head *bh = page_buffers(page);
 
-		if (wait)
-			wait_event(bitmap->write_wait,
-				   atomic_read(&bitmap->pending_writes)==0);
+	while (bh && bh->b_blocknr) {
+		atomic_inc(&bitmap->pending_writes);
+		set_buffer_locked(bh);
+		set_buffer_mapped(bh);
+		submit_bh(REQ_OP_WRITE | REQ_SYNC, bh);
+		bh = bh->b_this_page;
 	}
-	if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))
-		md_bitmap_file_kick(bitmap);
+
+	if (wait)
+		wait_event(bitmap->write_wait,
+			   atomic_read(&bitmap->pending_writes) == 0);
 }
 
 static void end_bitmap_write(struct buffer_head *bh, int uptodate)
@@ -429,6 +418,17 @@  static int read_page(struct file *file, unsigned long index,
  * bitmap file superblock operations
  */
 
+/*
+ * write out a page to a file
+ */
+static void write_page(struct bitmap *bitmap, struct page *page, int wait)
+{
+	if (bitmap->storage.file)
+		write_file_page(bitmap, page, wait);
+	else
+		write_sb_page(bitmap, page, wait);
+}
+
 /*
  * md_bitmap_wait_writes() should be called before writing any bitmap
  * blocks, to ensure previous writes, particularly from