Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0dd59de authored by Zhao Lei's avatar Zhao Lei Committed by Chris Mason
Browse files

btrfs: Fix calculate typo caused by ambiguous meaning of logic_end



For example, in scrub_raid56_parity(), following lines are used
to judge is all data processed:
 place1: if (key.objectid > logic_end) ...
 place2: if (logic_start >= logic_end) ...
 ...
 (place2 is typo, is should be ">", it is copied from other
  place, where logic_end's meaning is different, long story...)

We can fix above typo directly, but the root reason is ambiguous
meaning of logic_end in scrub raid56 parity.

In other place, XXX_end is pointed to data which is not included,
and we need to process segment of [XXX_start, XXX_end).

But for scrub raid56 parity, logic_end is pointed to lattest data
need to process, and introduced many "+ 1" and "- 1" in code as
below:
 length = sparity->logic_end - sparity->logic_start + 1
 logic_end - logic_start + 1
 stripe_logical + increment - 1

This patch changed logic_end's meaning to make it in normal understanding
in raid56 parity functions and data struct alone with above bugfix.

Signed-off-by: default avatarZhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 6fa96d72
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -2702,7 +2702,7 @@ static void scrub_parity_check_and_repair(struct scrub_parity *sparity)
			   sparity->nsectors))
			   sparity->nsectors))
		goto out;
		goto out;


	length = sparity->logic_end - sparity->logic_start + 1;
	length = sparity->logic_end - sparity->logic_start;
	ret = btrfs_map_sblock(sctx->dev_root->fs_info, WRITE,
	ret = btrfs_map_sblock(sctx->dev_root->fs_info, WRITE,
			       sparity->logic_start,
			       sparity->logic_start,
			       &length, &bbio, 0, 1);
			       &length, &bbio, 0, 1);
@@ -2868,7 +2868,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
			    key.type != BTRFS_METADATA_ITEM_KEY)
			    key.type != BTRFS_METADATA_ITEM_KEY)
				goto next;
				goto next;


			if (key.objectid > logic_end) {
			if (key.objectid >= logic_end) {
				stop_loop = 1;
				stop_loop = 1;
				break;
				break;
			}
			}
@@ -2958,7 +2958,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
out:
out:
	if (ret < 0)
	if (ret < 0)
		scrub_parity_mark_sectors_error(sparity, logic_start,
		scrub_parity_mark_sectors_error(sparity, logic_start,
						logic_end - logic_start + 1);
						logic_end - logic_start);
	scrub_parity_put(sparity);
	scrub_parity_put(sparity);
	scrub_submit(sctx);
	scrub_submit(sctx);
	mutex_lock(&sctx->wr_ctx.wr_lock);
	mutex_lock(&sctx->wr_ctx.wr_lock);
@@ -3139,7 +3139,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
			logical += base;
			logical += base;
			if (ret) {
			if (ret) {
				stripe_logical += base;
				stripe_logical += base;
				stripe_end = stripe_logical + increment - 1;
				stripe_end = stripe_logical + increment;
				ret = scrub_raid56_parity(sctx, map, scrub_dev,
				ret = scrub_raid56_parity(sctx, map, scrub_dev,
							  ppath, stripe_logical,
							  ppath, stripe_logical,
							  stripe_end);
							  stripe_end);
@@ -3287,7 +3287,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
					if (ret && physical < physical_end) {
					if (ret && physical < physical_end) {
						stripe_logical += base;
						stripe_logical += base;
						stripe_end = stripe_logical +
						stripe_end = stripe_logical +
								increment - 1;
								increment;
						ret = scrub_raid56_parity(sctx,
						ret = scrub_raid56_parity(sctx,
							map, scrub_dev, ppath,
							map, scrub_dev, ppath,
							stripe_logical,
							stripe_logical,