Commit a5298969 authored by Yu Kuai's avatar Yu Kuai Committed by Wentao Guan
Browse files

md/md-bitmap: factor behind write counters out from bitmap_{start/end}write()

stable inclusion
from stable-v6.6.79
commit 3b666dad382876f3bb741a62508d20fb94e58631
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBXANC

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=3b666dad382876f3bb741a62508d20fb94e58631



--------------------------------

commit 08c50142a128dcb2d7060aa3b4c5db8837f7a46a upstream.

behind_write is only used in raid1, prepare to refactor
bitmap_{start/end}write(), there are no functional changes.

Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Reviewed-by: default avatarXiao Ni <xni@redhat.com>
Link: https://lore.kernel.org/r/20250109015145.158868-2-yukuai1@huaweicloud.com


Signed-off-by: default avatarSong Liu <song@kernel.org>
[There is no bitmap_operations, resolve conflicts by exporting new api
md_bitmap_{start,end}_behind_write]
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 3b666dad382876f3bb741a62508d20fb94e58631)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent e264ac48
Loading
Loading
Loading
Loading
+38 −22
Original line number Diff line number Diff line
@@ -1465,22 +1465,12 @@ __acquires(bitmap->lock)
			&(bitmap->bp[page].map[pageoff]);
}

int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind)
int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset,
			 unsigned long sectors)
{
	if (!bitmap)
		return 0;

	if (behind) {
		int bw;
		atomic_inc(&bitmap->behind_writes);
		bw = atomic_read(&bitmap->behind_writes);
		if (bw > bitmap->behind_writes_used)
			bitmap->behind_writes_used = bw;

		pr_debug("inc write-behind count %d/%lu\n",
			 bw, bitmap->mddev->bitmap_info.max_write_behind);
	}

	while (sectors) {
		sector_t blocks;
		bitmap_counter_t *bmc;
@@ -1527,20 +1517,13 @@ int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long s
	}
	return 0;
}
EXPORT_SYMBOL(md_bitmap_startwrite);
EXPORT_SYMBOL_GPL(md_bitmap_startwrite);

void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
			unsigned long sectors, int success, int behind)
			unsigned long sectors, int success)
{
	if (!bitmap)
		return;
	if (behind) {
		if (atomic_dec_and_test(&bitmap->behind_writes))
			wake_up(&bitmap->behind_wait);
		pr_debug("dec write-behind count %d/%lu\n",
			 atomic_read(&bitmap->behind_writes),
			 bitmap->mddev->bitmap_info.max_write_behind);
	}

	while (sectors) {
		sector_t blocks;
@@ -1580,7 +1563,7 @@ void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
			sectors = 0;
	}
}
EXPORT_SYMBOL(md_bitmap_endwrite);
EXPORT_SYMBOL_GPL(md_bitmap_endwrite);

static int __bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks,
			       int degraded)
@@ -1842,6 +1825,39 @@ void md_bitmap_free(struct bitmap *bitmap)
}
EXPORT_SYMBOL(md_bitmap_free);

void md_bitmap_start_behind_write(struct mddev *mddev)
{
	struct bitmap *bitmap = mddev->bitmap;
	int bw;

	if (!bitmap)
		return;

	atomic_inc(&bitmap->behind_writes);
	bw = atomic_read(&bitmap->behind_writes);
	if (bw > bitmap->behind_writes_used)
		bitmap->behind_writes_used = bw;

	pr_debug("inc write-behind count %d/%lu\n",
		 bw, bitmap->mddev->bitmap_info.max_write_behind);
}
EXPORT_SYMBOL_GPL(md_bitmap_start_behind_write);

void md_bitmap_end_behind_write(struct mddev *mddev)
{
	struct bitmap *bitmap = mddev->bitmap;

	if (!bitmap)
		return;

	if (atomic_dec_and_test(&bitmap->behind_writes))
		wake_up(&bitmap->behind_wait);
	pr_debug("dec write-behind count %d/%lu\n",
		 atomic_read(&bitmap->behind_writes),
		 bitmap->mddev->bitmap_info.max_write_behind);
}
EXPORT_SYMBOL_GPL(md_bitmap_end_behind_write);

void md_bitmap_wait_behind_writes(struct mddev *mddev)
{
	struct bitmap *bitmap = mddev->bitmap;
+4 −2
Original line number Diff line number Diff line
@@ -253,9 +253,11 @@ void md_bitmap_dirty_bits(struct bitmap *bitmap, unsigned long s, unsigned long

/* these are exported */
int md_bitmap_startwrite(struct bitmap *bitmap, sector_t offset,
			 unsigned long sectors, int behind);
			 unsigned long sectors);
void md_bitmap_endwrite(struct bitmap *bitmap, sector_t offset,
			unsigned long sectors, int success, int behind);
			unsigned long sectors, int success);
void md_bitmap_start_behind_write(struct mddev *mddev);
void md_bitmap_end_behind_write(struct mddev *mddev);
int md_bitmap_start_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int degraded);
void md_bitmap_end_sync(struct bitmap *bitmap, sector_t offset, sector_t *blocks, int aborted);
void md_bitmap_close_sync(struct bitmap *bitmap);
+7 −4
Original line number Diff line number Diff line
@@ -420,11 +420,12 @@ static void close_write(struct r1bio *r1_bio)
		bio_put(r1_bio->behind_master_bio);
		r1_bio->behind_master_bio = NULL;
	}
	if (test_bit(R1BIO_BehindIO, &r1_bio->state))
		md_bitmap_end_behind_write(r1_bio->mddev);
	/* clear the bitmap if all writes complete successfully */
	md_bitmap_endwrite(r1_bio->mddev->bitmap, r1_bio->sector,
			   r1_bio->sectors,
			   !test_bit(R1BIO_Degraded, &r1_bio->state),
			   test_bit(R1BIO_BehindIO, &r1_bio->state));
			   !test_bit(R1BIO_Degraded, &r1_bio->state));
	md_write_end(r1_bio->mddev);
}

@@ -1524,8 +1525,10 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
				alloc_behind_master_bio(r1_bio, bio);
			}

			md_bitmap_startwrite(bitmap, r1_bio->sector, r1_bio->sectors,
					     test_bit(R1BIO_BehindIO, &r1_bio->state));
			if (test_bit(R1BIO_BehindIO, &r1_bio->state))
				md_bitmap_start_behind_write(mddev);
			md_bitmap_startwrite(bitmap, r1_bio->sector,
					     r1_bio->sectors);
			first_clone = 0;
		}

+2 −3
Original line number Diff line number Diff line
@@ -432,8 +432,7 @@ static void close_write(struct r10bio *r10_bio)
	/* clear the bitmap if all writes complete successfully */
	md_bitmap_endwrite(r10_bio->mddev->bitmap, r10_bio->sector,
			   r10_bio->sectors,
			   !test_bit(R10BIO_Degraded, &r10_bio->state),
			   0);
			   !test_bit(R10BIO_Degraded, &r10_bio->state));
	md_write_end(r10_bio->mddev);
}

@@ -1517,7 +1516,7 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
	md_account_bio(mddev, &bio);
	r10_bio->master_bio = bio;
	atomic_set(&r10_bio->remaining, 1);
	md_bitmap_startwrite(mddev->bitmap, r10_bio->sector, r10_bio->sectors, 0);
	md_bitmap_startwrite(mddev->bitmap, r10_bio->sector, r10_bio->sectors);

	for (i = 0; i < conf->copies; i++) {
		if (r10_bio->devs[i].bio)
+2 −2
Original line number Diff line number Diff line
@@ -315,8 +315,8 @@ void r5c_handle_cached_data_endio(struct r5conf *conf,
			r5c_return_dev_pending_writes(conf, &sh->dev[i]);
			md_bitmap_endwrite(conf->mddev->bitmap, sh->sector,
					   RAID5_STRIPE_SECTORS(conf),
					   !test_bit(STRIPE_DEGRADED, &sh->state),
					   0);
					   !test_bit(STRIPE_DEGRADED,
						     &sh->state));
		}
	}
}
Loading