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

Commit 3d6a650f authored by Yunlei He's avatar Yunlei He Committed by Jaegeuk Kim
Browse files

f2fs: add a punch discard command function



This patch add a function to punch discard command if one segment
reuse before discard. Split this segment from multi-segments discard
range, and discard the left bigger range.

Signed-off-by: default avatarYunlei He <heyunlei@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent c81abe34
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -759,6 +759,25 @@ static int __queue_discard_cmd(struct f2fs_sb_info *sbi,
	return 0;
}

static void __punch_discard_cmd(struct f2fs_sb_info *sbi,
				struct discard_cmd *dc, block_t blkaddr)
{
	block_t end_block = START_BLOCK(sbi, GET_SEGNO(sbi, blkaddr) + 1);

	if (dc->state == D_DONE || dc->lstart + dc->len <= end_block) {
		__remove_discard_cmd(sbi, dc);
		return;
	}

	if (blkaddr - dc->lstart < dc->lstart + dc->len - end_block) {
		dc->start += (end_block - dc->lstart);
		dc->len -= (end_block - dc->lstart);
		dc->lstart = end_block;
	} else {
		dc->len = blkaddr - dc->lstart;
	}
}

/* This should be covered by global mutex, &sit_i->sentry_lock */
void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
{
@@ -781,8 +800,7 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
		if (dc->lstart <= blkaddr && blkaddr < dc->lstart + dc->len) {
			if (dc->state == D_SUBMIT)
				wait_for_completion_io(&dc->wait);
			else
				__remove_discard_cmd(sbi, dc);
			__punch_discard_cmd(sbi, dc, blkaddr);
		}
	}
	blk_finish_plug(&plug);