From patchwork Thu Dec 28 14:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 183737 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2028277dyb; Thu, 28 Dec 2023 06:32:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKe3ZKiKKJqTQSKVuyCagpfX0qmXrBCqa1n0cFK9twYK3r9Thc+tUryvsxBz18+emq5oRn X-Received: by 2002:a05:622a:1043:b0:427:fb2b:8386 with SMTP id f3-20020a05622a104300b00427fb2b8386mr934518qte.99.1703773953038; Thu, 28 Dec 2023 06:32:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703773953; cv=none; d=google.com; s=arc-20160816; b=PpgkWZGcaEjPMEdgLxCItV3dAAccNPHv21S6Bn+vdY+kqPjcYTV7dOarmKOB0c3pix Fb6idy7dlmuDfGTWMsTcMGo31LmdNXZy2UcZXASh2lqrq2nq5x0JZI8VuAeeooY8uZjb gfuEslnPr9ozS6ytxZRupCeX2zkD4xZexbqvi7fb92LOjUTJ8/b823aG7747moDORPDj M4cpjC7Dru4xqI4JoB6hfeXkLxMx3H8OlOc2D8R3L99db1A0w46U0E3Xe/3yis+fEJF0 6U9uRjSisHRmpXtCdNq0jxVop4fE9Acsg1XawvHXVw5RvIqgPQLHfPoq5atsQlXEUDjN 8E+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=vPmh+CaS4FPJva8LA9C/gsUBD6xjJSAL5DH+nN3NUa8=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=DO7hS+hM8n4BZsxo+To9k6eHn4KudB8Qnsenxe3pSYXDOVBPkxwL6yHlMs/ZPagvlk ys0VX7izJYYyZzXZea7uTkA2zN55GwrQpYOF9mbTjHEnu+4WVYJnchkeOw0ROdOx2IEN 3RIPQwW3TWWhL/E4S1QdVO+UApL59FAi34hRZ6baz87ouiGV0F3Xtv+834ZVy0myhXwx iXZ1vpSNAsOgsvHKIuUOCp5fCHYugafZD60ETGhqK6Gl19OjuZqLgHC38xwgYlbstHXI db5VPQOgP3QjRlerv8OMTmrH0jI4VqSlX15SVtI5qae9kcftdmYub8yjXo0ecZqUeUbn IWQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MCLXEq5O; spf=pass (google.com: domain of linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e20-20020ac84e54000000b00427e936d13bsi4360920qtw.558.2023.12.28.06.32.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 06:32:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MCLXEq5O; spf=pass (google.com: domain of linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12702-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BED871C21C74 for ; Thu, 28 Dec 2023 14:32:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 352FAF9D1; Thu, 28 Dec 2023 14:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MCLXEq5O" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D6BAE54C for ; Thu, 28 Dec 2023 14:32:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B96FC433C7; Thu, 28 Dec 2023 14:32:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703773924; bh=9bgjtozDzWABSz5MpQDd5yOqAUr2mxUTvlK3pdYj7L8=; h=From:To:Cc:Subject:Date:From; b=MCLXEq5O89CRbk4jUqbDm2omlafRC6JTlg9vTcyDq6vLRBP3dpI9QgRtGvnIWNG4v 8J0hxmFQC3cSQyR1IIvWWdpCRuWAfa5Vg35cD82kZTumr3EtHIsg3XGjhC5qmWlpk3 bZy5U5nXuqVdB2+7/Kk/FYYDt3EAmJzJluGoupnrvrk2PJRVNlTqO+5aNIKfN0d2wT 2YBb4wcHt7+vtjkA9ihFzlL+JhHT8AbeOJT4blGyuAH2siqJCQPrjKwREbt4g2Xr3o o27PWy9GvTg/OjyqfwJU8cblWTyPOna1+fuzIfacQmVzACfHYBr7dc2T69M1vv3npl PwyTFH5EjzI3g== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v3 1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP Date: Thu, 28 Dec 2023 22:31:47 +0800 Message-Id: <20231228143152.1543509-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785810348376268121 X-GMAIL-MSGID: 1786536476981084621 If data block in compressed cluster is not persisted with metadata during checkpoint, after SPOR, the data may be corrupted, let's guarantee to write compressed page by checkpoint. Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu Reviewed-by: Daeho Jeong --- v3: - treat compressed page as CP guaranteed data explictly. fs/f2fs/compress.c | 4 +++- fs/f2fs/data.c | 17 +++++++++-------- fs/f2fs/f2fs.h | 4 +++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index c5a4364c4482..9940b7886e5d 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1418,6 +1418,8 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) struct f2fs_sb_info *sbi = bio->bi_private; struct compress_io_ctx *cic = (struct compress_io_ctx *)page_private(page); + enum count_type type = WB_DATA_TYPE(page, + f2fs_is_compressed_page(page)); int i; if (unlikely(bio->bi_status)) @@ -1425,7 +1427,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page) f2fs_compress_free_page(page); - dec_page_count(sbi, F2FS_WB_DATA); + dec_page_count(sbi, type); if (atomic_dec_return(&cic->pending_pages)) return; diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index dce8defdf4c7..81f9e2cc49e2 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -48,7 +48,7 @@ void f2fs_destroy_bioset(void) bioset_exit(&f2fs_bioset); } -static bool __is_cp_guaranteed(struct page *page) +bool f2fs_is_cp_guaranteed(struct page *page) { struct address_space *mapping = page->mapping; struct inode *inode; @@ -65,8 +65,6 @@ static bool __is_cp_guaranteed(struct page *page) S_ISDIR(inode->i_mode)) return true; - if (f2fs_is_compressed_page(page)) - return false; if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || page_private_gcing(page)) return true; @@ -338,7 +336,7 @@ static void f2fs_write_end_io(struct bio *bio) bio_for_each_segment_all(bvec, bio, iter_all) { struct page *page = bvec->bv_page; - enum count_type type = WB_DATA_TYPE(page); + enum count_type type = WB_DATA_TYPE(page, false); if (page_private_dummy(page)) { clear_page_private_dummy(page); @@ -762,7 +760,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); inc_page_count(fio->sbi, is_read_io(fio->op) ? - __read_io_type(page) : WB_DATA_TYPE(fio->page)); + __read_io_type(page) : WB_DATA_TYPE(fio->page, false)); if (is_read_io(bio_op(bio))) f2fs_submit_read_bio(fio->sbi, bio, fio->type); @@ -973,7 +971,7 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio) if (fio->io_wbc) wbc_account_cgroup_owner(fio->io_wbc, fio->page, PAGE_SIZE); - inc_page_count(fio->sbi, WB_DATA_TYPE(page)); + inc_page_count(fio->sbi, WB_DATA_TYPE(page, false)); *fio->last_block = fio->new_blkaddr; *fio->bio = bio; @@ -1007,6 +1005,7 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp; struct page *bio_page; + enum count_type type; f2fs_bug_on(sbi, is_read_io(fio->op)); @@ -1046,7 +1045,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) /* set submitted = true as a return value */ fio->submitted = 1; - inc_page_count(sbi, WB_DATA_TYPE(bio_page)); + type = WB_DATA_TYPE(bio_page, fio->compressed_page); + inc_page_count(sbi, type); if (io->bio && (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, @@ -1059,7 +1059,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio) if (F2FS_IO_ALIGNED(sbi) && (fio->type == DATA || fio->type == NODE) && fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { - dec_page_count(sbi, WB_DATA_TYPE(bio_page)); + dec_page_count(sbi, WB_DATA_TYPE(bio_page, + fio->compressed_page)); fio->retry = 1; goto skip; } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 65294e3b0bef..50f3d546ded8 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1080,7 +1080,8 @@ struct f2fs_sm_info { * f2fs monitors the number of several block types such as on-writeback, * dirty dentry blocks, dirty node blocks, and dirty meta blocks. */ -#define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) +#define WB_DATA_TYPE(p, f) \ + (f || f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) enum count_type { F2FS_DIRTY_DENTS, F2FS_DIRTY_DATA, @@ -3804,6 +3805,7 @@ void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); */ int __init f2fs_init_bioset(void); void f2fs_destroy_bioset(void); +bool f2fs_is_cp_guaranteed(struct page *page); int f2fs_init_bio_entry_cache(void); void f2fs_destroy_bio_entry_cache(void); void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio, From patchwork Thu Dec 28 14:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 183738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2028450dyb; Thu, 28 Dec 2023 06:32:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsYX7L2yqYW+HJLEENgi6mFx6yud2+xY4gpCkuwV9DXtRs3xz+fbBZDJztUy9ke+teWWkO X-Received: by 2002:a17:902:7590:b0:1d4:1bcd:6bae with SMTP id j16-20020a170902759000b001d41bcd6baemr10207332pll.31.1703773965394; Thu, 28 Dec 2023 06:32:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703773965; cv=none; d=google.com; s=arc-20160816; b=uwgb43nltgf3w/1fx/0jrzWDUECbQ7xOORLsN81w6Ouz5x5fXwgHM5jLycuwOziLFQ z7Xj/AilZSL3R7rOiPGlvkLHgLUwB8pvvX4/NTq4G6FIkywhlHVa3GMzN8b5jmgh8vcn U2kVi5riHcW+aEqpDCZ1xnOUzKk/lVhJbldtuADMRjvpyFSK8I+nEQHl8VkekS0G8Kx3 t3vtJMBvDvqD+224XSRKxBG5IHPCP72Iuu3dSEaSLBhE1xOawXxj/zNcEJa5/53oLs7Q 20U3lyqkGeP+8dBcZUB3+ops4y4YqnTc2+oTGf3mc25WJ0RIMYNXJio4uOFLgZcaSZq7 BY+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=I7XXUYIr8Q9KF+4scUbYcSJk+NkBf5I8stoKQ5y70L8=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=tJcMiip3JJ0Br8UoefexW0y3sgOFP6UHHMSM00HlvZTL5h0ues9ZfAzXDEue07VOEA YTJ7tDarrKNgP1kxt77Lksj10Dmz/JfAXnfGiWNvsXfWxcVL6Vwk1jyEkGGc6QTXfgWK z9KEPeH7173nFZvyZNOYsKvq9KgdwVDDZRRsyiWCzDs1sYrvtSMieqjdxJBi/bXwwZuh s/CLvTckqOotgVrGszzLQjEutJtFajUKXiRLJk8kDd5yVpDpkqNUHxCdFda+bTm3S1Qi T1fQHPhSp4IB7ye85MkjL6Bm8y2ZnRQfw0GKeqiUUO9C88NtbElOwV+2R0esR+WYXfhI wRNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="KbL/mcEp"; spf=pass (google.com: domain of linux-kernel+bounces-12704-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12704-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u3-20020a17090282c300b001d42ccfc422si9894814plz.50.2023.12.28.06.32.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 06:32:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12704-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="KbL/mcEp"; spf=pass (google.com: domain of linux-kernel+bounces-12704-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12704-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2EC54284E31 for ; Thu, 28 Dec 2023 14:32:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1BD7101DD; Thu, 28 Dec 2023 14:32:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KbL/mcEp" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30050F4E4 for ; Thu, 28 Dec 2023 14:32:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9777DC433C9; Thu, 28 Dec 2023 14:32:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703773926; bh=/uXMDvSOj4ElzaKYgiipftBm0qNMtUebJdjXyJwsNz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KbL/mcEp6TTfyO6ngjT22PS7q4xzi+uVlJnUWiUE6+Lad500sZw+hkyeIF2jx0jMh S3//2yv+6t5dC/rAMejbCiK/h30KLr+9LQgThbN8oyH45LKus/kS5aa/4en7zxybGj 5yR7Sx0HWr5+Iy5MNXeMiARK61DzVOYcay4jXxhlZBZsRHt3qiiG/BmBVUdgk3Rd4Z JZ81dAfN4Lws9PwMTqW+CBzZ8i/dyn1HOT6P07RfzpZ6RxzUspMjSIcrXuKBBB8uiO VRuk+9wdHU+U5AJWsXbJvz+n+/1Iu8epGMprZ7+0ZjJM5r4gGUOmOM6HAlOLhH9Jds rK0j1Kbvw1gFw== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v3 2/6] f2fs: compress: fix to cover normal cluster write with cp_rwsem Date: Thu, 28 Dec 2023 22:31:48 +0800 Message-Id: <20231228143152.1543509-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231228143152.1543509-1-chao@kernel.org> References: <20231228143152.1543509-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786536489779159442 X-GMAIL-MSGID: 1786536489779159442 When we overwrite compressed cluster w/ normal cluster, we should not unlock cp_rwsem during f2fs_write_raw_pages(), otherwise data will be corrupted if partial blocks were persisted before CP & SPOR, due to cluster metadata wasn't updated atomically. Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu --- fs/f2fs/compress.c | 20 ++++++++++++++------ fs/f2fs/data.c | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 9940b7886e5d..bf4cfab67aec 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1448,7 +1448,8 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, enum iostat_type io_type) { struct address_space *mapping = cc->inode->i_mapping; - int _submitted, compr_blocks, ret, i; + struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); + int _submitted, compr_blocks, ret = 0, i; compr_blocks = f2fs_compressed_blocks(cc); @@ -1463,6 +1464,10 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, if (compr_blocks < 0) return compr_blocks; + /* overwrite compressed cluster w/ normal cluster */ + if (compr_blocks > 0) + f2fs_lock_op(sbi); + for (i = 0; i < cc->cluster_size; i++) { if (!cc->rpages[i]) continue; @@ -1495,26 +1500,29 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc, unlock_page(cc->rpages[i]); ret = 0; } else if (ret == -EAGAIN) { + ret = 0; /* * for quota file, just redirty left pages to * avoid deadlock caused by cluster update race * from foreground operation. */ if (IS_NOQUOTA(cc->inode)) - return 0; - ret = 0; + goto out; f2fs_io_schedule_timeout(DEFAULT_IO_TIMEOUT); goto retry_write; } - return ret; + goto out; } *submitted += _submitted; } - f2fs_balance_fs(F2FS_M_SB(mapping), true); +out: + if (compr_blocks > 0) + f2fs_unlock_op(sbi); - return 0; + f2fs_balance_fs(sbi, true); + return ret; } int f2fs_write_multi_pages(struct compress_ctx *cc, diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 81f9e2cc49e2..b171a9980f6a 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2839,7 +2839,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, .encrypted_page = NULL, .submitted = 0, .compr_blocks = compr_blocks, - .need_lock = LOCK_RETRY, + .need_lock = compr_blocks ? LOCK_DONE : LOCK_RETRY, .post_read = f2fs_post_read_required(inode) ? 1 : 0, .io_type = io_type, .io_wbc = wbc, @@ -2920,6 +2920,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, if (err == -EAGAIN) { err = f2fs_do_write_data_page(&fio); if (err == -EAGAIN) { + f2fs_bug_on(sbi, compr_blocks); fio.need_lock = LOCK_REQ; err = f2fs_do_write_data_page(&fio); } From patchwork Thu Dec 28 14:31:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 183739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2028601dyb; Thu, 28 Dec 2023 06:33:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZONq48Y33EHqc+1HXnX8FF1lxF0Zh+/jsq8akJVo8kHb6KVe7WWbW7kEauvm686nzZeGz X-Received: by 2002:ac2:4882:0:b0:50e:39b3:d43e with SMTP id x2-20020ac24882000000b0050e39b3d43emr4027142lfc.66.1703773982307; Thu, 28 Dec 2023 06:33:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703773982; cv=none; d=google.com; s=arc-20160816; b=o9O8XP1IcnL2zJTF4CTOfJo4W6DzZjShpZRra+0l5BiCipsTjdAP9T4j19j2eVuecj UaP0KNJ0qB4Nljl96xG+TT/YBG3lY2rq4NutRXzimlRogLnfr0mV2gSVlCOZt6RXizS5 wtJE+8pgjrNTx6yuev0vPijs7ygBbJYXtJtyNa1WNSn0kQlBWCqX7y4HpnM5jwlW3aC2 zVOWb2LwNnUfglia+Pyp4lHEVzu+96/OW/JphlcqIMnWGM7LMvAvxQoG/mpDKotm9EZ8 SGP3yM+HQz/m4l01c6BIjIGyJ9z9kwxL5UxqaccZY9nDccpSMu3/08Quy++RQviDbB7W 0Vnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KsSgDPeE3D2PWDe+9Cjxa1TXEgtZW4xW4czqHA4SKmM=; fh=2w0/+7CnNSrmHtbae1hR3pLuwOJRubjB5ynbCr7QyGo=; b=TVDOF+JfFmS7lvrMCzBpYkxq+aTdN+x4SUrfDoS58kXaJ6aMe+lP1hRQLZbzSE5o/3 dBi8ByUS7gfyn7QDEvaFXQcG+5DuLSinGVjRBetWpcFgpRyEcDtvPvrR1aErfPpgvohd NIdaBmbxcucIxWX3EQ8ELS4zcCj7N9Mv+B8MpFSw4bJEecxG2e5Q0tiLXeuuWCqC8oxC 6Y3m77rK+6UVLXj9fgqlWkLFUvxr9XhFGiwwvy/Q7A0hV6O6pGSt8lIrADM1CqMZJjtQ 8Kys1EcOOu7kvHMKcVBfIDUqA+m6pt0QudMK11J9DgVORyIjzGDzJV/M7l03oyqLzN1W UlRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r3UmvBck; spf=pass (google.com: domain of linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id vz16-20020a17090704d000b00a234530a56csi6353453ejb.393.2023.12.28.06.33.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 06:33:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r3UmvBck; spf=pass (google.com: domain of linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12705-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E27211F233EB for ; Thu, 28 Dec 2023 14:33:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51D93107B4; Thu, 28 Dec 2023 14:32:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r3UmvBck" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2F69101DE for ; Thu, 28 Dec 2023 14:32:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90591C433C9; Thu, 28 Dec 2023 14:32:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703773928; bh=PlqlUk5bd+3fk4WKcXVwPKIXLZLKGpamNP0JtbEVizc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r3UmvBckldbFBMtcyi3xBTx28VUw1mf8I7YeImoXPWLb1YsrbuwkMEUL8dHxnC/QH tUu+7M+5kN1T0M4IQWEo3M7Y31SJeeLGc4v5jIjFOLbTPH0LcGSA8fbhA57yX4bn2f vaIzuIfnzXCGIZoKJiqwpLSdjxsv86uofKZ6zMVLqFa1II3ycsn+HRNzIc+LI3tY8L PuQR6tWdMqErdbCa9J1nfYVRfE9OTooB4PYZO8hoXRRvie7f3FIJxJJcBH7hR+ANRD v2/3CMDmlDZy4h6wHZhIa73FxBCl0vCtSSQV8y6ppQlUyHejH+382f2nMTCExoHAhP inT/5EXcK82aA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Sheng Yong , Chao Yu Subject: [PATCH v3 3/6] f2fs: compress: fix to check unreleased compressed cluster Date: Thu, 28 Dec 2023 22:31:49 +0800 Message-Id: <20231228143152.1543509-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231228143152.1543509-1-chao@kernel.org> References: <20231228143152.1543509-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786536507444678393 X-GMAIL-MSGID: 1786536507444678393 From: Sheng Yong Compressed cluster may not be released due to we can fail in release_compress_blocks(), fix to handle reserved compressed cluster correctly in reserve_compress_blocks(). Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Sheng Yong Signed-off-by: Chao Yu --- fs/f2fs/file.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 026d05a7edd8..782ae3be48f6 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3624,6 +3624,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) goto next; } + /* + * compressed cluster was not released due to + * it fails in release_compress_blocks(). + */ + if (blkaddr == NEW_ADDR) { + compr_blocks++; + continue; + } + if (__is_valid_data_blkaddr(blkaddr)) { compr_blocks++; continue; @@ -3633,6 +3642,9 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) } reserved = cluster_size - compr_blocks; + if (!reserved) + goto next; + ret = inc_valid_block_count(sbi, dn->inode, &reserved); if (ret) return ret; From patchwork Thu Dec 28 14:31:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 183740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2028705dyb; Thu, 28 Dec 2023 06:33:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4zSsv7exfXHAI1+UbCNaqzJ5PIa0Gpjo5ihwlQ8LeN9mk84INDspP9l5gc3MEPYx2ld8O X-Received: by 2002:a05:6602:2749:b0:7bb:720:3860 with SMTP id b9-20020a056602274900b007bb07203860mr3549404ioe.26.1703773993752; Thu, 28 Dec 2023 06:33:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703773993; cv=none; d=google.com; s=arc-20160816; b=ndNrKzS//s+4I9d05mMgiz9vqIdYld4JtUo6gM9eQh27c+tQv9jTodvei59DAMnZF5 viuF0JCA9JxbunqfDPOJSNewFn2a/YHkr4DVwQIhZqP+b/kOLhzvNa1QGJSC5gbu4DdE xziy7eSVIwSXmre6q3LutfLsUICUQC+YR+DCuH8zjzJaegR17cfLJSkG0FrYIeAkKP1T qUB0JCQz6eMNJh+Gm9uM/JP2T76Sz5MVoMuPgWm68ASJ6Wx4YWPUtYXl9oa3fX8H86bz mH/0urV/9Temwvu48pTCa1jc9+8v51+lPX4CrhHeAV2g/XDhQ9mvEsVL0wdjawpDUEiv yiTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=jb13lTI2jO540ZxGI73v57QF49I8wKdfwf41/Lmdnms=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=oFjLNjmG8uDLtLQ9orWrN77xBMTwVZbMutvu+a9Zh/1tzX1iDrOpQcgVO+f4HVd2uJ Z97v771C3+u7lqdW9KpMOPXYl5n9GgXFR0xHpk6hdJP1AUIcMQCSbOvpq664QVSWfwSX SmMxTrLoNnpCN3Cufy8pZIFGu7NsQjVtqhFRpkXW7pB+kpHObVkg5P0bFpA8zLfZhH2L WNdHeFRGc4nqlQ00DALOs806ASROFzVPZD8RBH+h6HkPsfyxsJ2amS5z4xXxpqKxEIme yF6hXIuhvKnVAjZXIxibUu9kEcUYCnK/9ajbWkHc8HBci6IUjHtONUyBauWDfhu+sZIS 4Pvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UNoxEVhr; spf=pass (google.com: domain of linux-kernel+bounces-12706-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12706-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j36-20020a635964000000b005cd9600a04fsi12813486pgm.215.2023.12.28.06.33.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 06:33:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12706-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UNoxEVhr; spf=pass (google.com: domain of linux-kernel+bounces-12706-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12706-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6C591283C11 for ; Thu, 28 Dec 2023 14:33:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31F1610964; Thu, 28 Dec 2023 14:32:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UNoxEVhr" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A40B210799 for ; Thu, 28 Dec 2023 14:32:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C46BAC433CB; Thu, 28 Dec 2023 14:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703773930; bh=LUmVUzlEgho8rblT2MQAj6/QwwZ/toOy2wW11JTIlIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UNoxEVhr6Da6imq6OlKiSiY/Azz3SqVS+G47a6/fEo8B0lxuxy0utjoSHI6Ei35Jk dWQE2x/cXWzkTmPy7uSzHTnvrfOJC7sZlG5JB8/FYdiOM6QhK0mA9P03qPmVIPcZl2 5bVN9I6UX0njDIhNmV8cXROWezFNjfRLcsP2fiGhQdkMOzomZbJldVO5FwmDOLrUvv KDe4MRr54puqH1HDUd0oJtaZuRAZgDYa7q7dxyhaix/qheQ5Wx45zzBc0OaPtWFo6a n8Hyr3GNiX9n0XpDmGGVEEj61/dxxND/6+b5t7h1Jfl6hi/9gI6mALWXuN7OfasH// 50xlSXCmPbpgg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v3 4/6] f2fs: compress: fix to avoid inconsistent bewteen i_blocks and dnode Date: Thu, 28 Dec 2023 22:31:50 +0800 Message-Id: <20231228143152.1543509-4-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231228143152.1543509-1-chao@kernel.org> References: <20231228143152.1543509-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786536519230430966 X-GMAIL-MSGID: 1786536519230430966 In reserve_compress_blocks(), we update blkaddrs of dnode in prior to inc_valid_block_count(), it may cause inconsistent status bewteen i_blocks and blkaddrs once inc_valid_block_count() fails. To fix this issue, it needs to reverse their invoking order. Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS") Signed-off-by: Chao Yu --- fs/f2fs/data.c | 5 +++-- fs/f2fs/f2fs.h | 7 ++++++- fs/f2fs/file.c | 26 ++++++++++++++------------ fs/f2fs/segment.c | 2 +- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b171a9980f6a..8d2ace723310 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1219,7 +1219,8 @@ int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count) if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) return -EPERM; - if (unlikely((err = inc_valid_block_count(sbi, dn->inode, &count)))) + err = inc_valid_block_count(sbi, dn->inode, &count, true); + if (unlikely(err)) return err; trace_f2fs_reserve_new_blocks(dn->inode, dn->nid, @@ -1476,7 +1477,7 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type) dn->data_blkaddr = f2fs_data_blkaddr(dn); if (dn->data_blkaddr == NULL_ADDR) { - err = inc_valid_block_count(sbi, dn->inode, &count); + err = inc_valid_block_count(sbi, dn->inode, &count, true); if (unlikely(err)) return err; } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 50f3d546ded8..69e71460a950 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2252,7 +2252,7 @@ static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, - struct inode *inode, blkcnt_t *count) + struct inode *inode, blkcnt_t *count, bool partial) { blkcnt_t diff = 0, release = 0; block_t avail_user_block_count; @@ -2292,6 +2292,11 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, avail_user_block_count = 0; } if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { + if (!partial) { + spin_unlock(&sbi->stat_lock); + goto enospc; + } + diff = sbi->total_valid_block_count - avail_user_block_count; if (diff > *count) diff = *count; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 782ae3be48f6..9f4e21b5916c 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3614,14 +3614,16 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) blkcnt_t reserved; int ret; - for (i = 0; i < cluster_size; i++, dn->ofs_in_node++) { - blkaddr = f2fs_data_blkaddr(dn); + for (i = 0; i < cluster_size; i++) { + blkaddr = data_blkaddr(dn->inode, dn->node_page, + dn->ofs_in_node + i); if (i == 0) { - if (blkaddr == COMPRESS_ADDR) - continue; - dn->ofs_in_node += cluster_size; - goto next; + if (blkaddr != COMPRESS_ADDR) { + dn->ofs_in_node += cluster_size; + goto next; + } + continue; } /* @@ -3637,20 +3639,20 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) compr_blocks++; continue; } - - f2fs_set_data_blkaddr(dn, NEW_ADDR); } reserved = cluster_size - compr_blocks; if (!reserved) goto next; - ret = inc_valid_block_count(sbi, dn->inode, &reserved); - if (ret) + ret = inc_valid_block_count(sbi, dn->inode, &reserved, false); + if (unlikely(ret)) return ret; - if (reserved != cluster_size - compr_blocks) - return -ENOSPC; + for (i = 0; i < cluster_size; i++, dn->ofs_in_node++) { + if (f2fs_data_blkaddr(dn) == NULL_ADDR) + f2fs_set_data_blkaddr(dn, NEW_ADDR); + } f2fs_i_compr_blocks_update(dn->inode, compr_blocks, true); diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 61da26eb61cc..9632e9977c90 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -248,7 +248,7 @@ static int __replace_atomic_write_block(struct inode *inode, pgoff_t index, } else { blkcnt_t count = 1; - err = inc_valid_block_count(sbi, inode, &count); + err = inc_valid_block_count(sbi, inode, &count, true); if (err) { f2fs_put_dnode(&dn); return err; From patchwork Thu Dec 28 14:31:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 183741 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2028863dyb; Thu, 28 Dec 2023 06:33:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXbslBjvFdEvvJF4IhrE+mrCSk/ASJa/di8qMDHG9NLdnbLTOsYG/AUJ55oVFeF0XNPbY0 X-Received: by 2002:a50:9514:0:b0:554:236b:d391 with SMTP id u20-20020a509514000000b00554236bd391mr5236433eda.9.1703774007591; Thu, 28 Dec 2023 06:33:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703774007; cv=none; d=google.com; s=arc-20160816; b=H22fZc0DWbsTvzRt1haEtDRG/ju75qW7vTakNsJZHJg6mde2x3FeWxAsSmG2ynmh/3 QOxP98ylv9VMkYTBoTh2xAvupLlPu5FvpC26gawgVDLx7WJBS01PHLqUT6h7JUEz+vRc Y73M2+uCtMEuQvYNmOfoNfbjJ/5F3RPwigt/d25kLqCxzLJFOvupuuMdagyr2/qdA+QE IxGt7uuKYDxjvi+onx9/Ibc2k0bebXtp/o3ETyScxHox+CHCXHfPg14nVySAhRVje6eE YmyD0zZ60efoAKJxgCbw6bybYJH5cHaALsxEaftuhdyrkV3yIZKFaTh/EayD+TP3jSjZ gj3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gbqBjB9dGO5DNoWz4hJSaL4wOc8782Hf6wNDj7ZMkLo=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=D4ViRjoworZK2RriLi2TQw2uZ37aEBBlAnTf7VSkfseuqxLg/vqPs41JhvxV56PM1b fjdhbW37/xLejByAOsbn15ItKnXqH0D6sO3AiTug56uL0tXNmyF4SUY7OHocKyyIyfxe NzAYI54zgtS6HigyDh9W5gKb0FFSjjORJc22HqoFRSYxljCLOfAJI5A9/w/0IoV1wZTb +M6KT+wTfMh0tFL3m8G6/OLx3jQrkNt3eQ13y4/HDxFLNx4DSSzWoPIWA1vHP1197QSR oNxXmrgOCdrb1I0EE9m6e1XdLM/VlUVaLuAxgdVAIUXe4iTchCsVTH84RM3153zttaAS V8EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fu+2B5Sq; spf=pass (google.com: domain of linux-kernel+bounces-12707-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12707-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p19-20020a50cd93000000b0055425c7f7adsi6798188edi.441.2023.12.28.06.33.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 06:33:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12707-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fu+2B5Sq; spf=pass (google.com: domain of linux-kernel+bounces-12707-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12707-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 3C4E91F2356A for ; Thu, 28 Dec 2023 14:33:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3039210A10; Thu, 28 Dec 2023 14:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fu+2B5Sq" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5E5A10950 for ; Thu, 28 Dec 2023 14:32:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE7F4C433CB; Thu, 28 Dec 2023 14:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703773932; bh=gbX4YWfRwjVnF49sDXj1O3cCSmmOzMm5S1M/X7oiEXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fu+2B5Sq02Xg1h4uTwh2tBRcfPL99jE72HLiZkQA49ZS7hwV6im12C6h5G2Ztxyy6 /AXp5YbuBLvEPyB7GOrM47fnIZlPSkhMDvC5DJDl6G9a08tlDRY3q5tNWfS2WSp2FH vhP+0obirrQqsexCUkyd7/cNLNKzH636PdPyjQuklPqa9kvQobqAgrCKViaUXAiz3l LW9Y1qbs2ns/qqTz2KJCZD2WuUq+C035C7jB/6hRLyZb8z7ynQFSONQSXZXpGFWXqN qzI155cPbVZHwPcwKVmpPvPH+R8Lhd56vrQKUzrrfm+Yrn1LBWhyUVwLmIoqWTTrm0 pPxC0ghvG1XxA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v3 5/6] f2fs: fix to remove unnecessary f2fs_bug_on() to avoid panic Date: Thu, 28 Dec 2023 22:31:51 +0800 Message-Id: <20231228143152.1543509-5-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231228143152.1543509-1-chao@kernel.org> References: <20231228143152.1543509-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786536533889022002 X-GMAIL-MSGID: 1786536533889022002 verify_blkaddr() will trigger panic once we inject fault into f2fs_is_valid_blkaddr(), fix to remove this unnecessary f2fs_bug_on(). Fixes: 18792e64c86d ("f2fs: support fault injection for f2fs_is_valid_blkaddr()") Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 69e71460a950..ab710bb6d8b3 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3470,11 +3470,9 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, static inline void verify_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type) { - if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { + if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", blkaddr, type); - f2fs_bug_on(sbi, 1); - } } static inline bool __is_valid_data_blkaddr(block_t blkaddr) From patchwork Thu Dec 28 14:31:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 183742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp2029000dyb; Thu, 28 Dec 2023 06:33:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzQPpsBY5Y+bQAN6QvzXRwrzCmTOszVh3Nd5ngkz1RCGoYc6Y6PO8KW47X3TK6tqiO4imx X-Received: by 2002:a2e:9787:0:b0:2cc:b51b:23a6 with SMTP id y7-20020a2e9787000000b002ccb51b23a6mr3659957lji.71.1703774020070; Thu, 28 Dec 2023 06:33:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703774020; cv=none; d=google.com; s=arc-20160816; b=ChPDQdUf0VEqKDA4FWvkwpfW2F3D7DPB0nYIL20KjjyoEtUGaQpOW6SO7hQYY5gGxe ZPNhvjuzH8GTKCtt/GYVT0EGvzljNzwOgDpZKpjcSGoNz3I0Vm/A6ZPYq0tpPDlut979 4TsmfQcO/tsfgenpfoIXZgVjeOU6iUWhstZLpUabKcggLnk4czwayxvXv68tulQvDTKA HSFbjTEglSWZjwWRaQqswS6flxuPXJTwd1EG8kVQyU6LH+ogCy7JChFKppTmCsAlD7AK kQ5Yb+SqwWXM0PAbOnGaCIE8SrhsWeRzTeH+zy2iFzxhWZnGP0GrBa6THdKSwv6GQyAD kT2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=mwTiU3rkV/uv6LRL9iNBxohQbvi6zCwNuezX2gdYoTA=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=aHNJkRhZVziAcW3NhokZ2vwQYWlQHzjJ87OwqugVHxgb19uE50L5OQq8yeW3RCvZCs 0mqZefDgovoxyJo4g6Xgkq9OSEWBA3Kun3YOfzPMa0JmOCmU4lwTv6akwWbOk5kAREgD 28NN556TuFZnGL9l2v0L864xkQXmwcxisGe+n8sBBBCU+RmCJkwE+8eg+103EB19ALU8 xZX1jeQ2+OtCYIHMRQ0HTG1/pNK2zJOWMxknMBnbsnnSqprooMRKGYpeDD8IwiYSTpev BEFveAR/QwVdo1qJxUP3F6oSbV4wVnhtBCbz7jJNgQ6Hvpie70hZzfIcLFI4+L2GM+m4 8zVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bmSofWjk; spf=pass (google.com: domain of linux-kernel+bounces-12708-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12708-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cz17-20020a0564021cb100b005514bcc4070si7065601edb.299.2023.12.28.06.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 06:33:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12708-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bmSofWjk; spf=pass (google.com: domain of linux-kernel+bounces-12708-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12708-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 808FF1F234A3 for ; Thu, 28 Dec 2023 14:33:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6489C10A33; Thu, 28 Dec 2023 14:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bmSofWjk" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D214A10A05 for ; Thu, 28 Dec 2023 14:32:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3D12C433C7; Thu, 28 Dec 2023 14:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703773934; bh=DMeS2vfzkUxcLbmEcA5uRENvkQrQiVn9mfOWnIMYifg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bmSofWjk0tLqQQ+T/uhhNBEC6ty3d+LAw22mvhDfzpzvKQP57gUXHJYINWjxXLHfi OdV50N7uOKFuJ/CeavgeraTtHuEpfQPgpU85U3wBKYkj77N3uwVUBa757YBPIB82ZJ d+cj9/Tr3jkWLTgK3eliYkSwiOQQW88+4E7sU7twC75256VNtxSIAyr1toQVo8zCuD eIeT/p0sylF6om9W4XI9cN+L0kZ6ZKyfLtP0ccT4Y1DTzAzJvIetU5snF8pzNQBE5J ASJx60lx8Td8hIZsIWLAXg4yUekJ93KDjGCA1smBPUF2mSiMuzq5utz9n9H0Y6w6VL 6wbb4xsA8lZrA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH v3 6/6] f2fs: introduce FAULT_BLKADDR_INCONSISTENCE Date: Thu, 28 Dec 2023 22:31:52 +0800 Message-Id: <20231228143152.1543509-6-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231228143152.1543509-1-chao@kernel.org> References: <20231228143152.1543509-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786536546664227689 X-GMAIL-MSGID: 1786536546664227689 We will encounter below inconsistent status when FAULT_BLKADDR type fault injection is on. Info: checkpoint state = d6 : nat_bits crc fsck compacted_summary orphan_inodes sudden-power-off [ASSERT] (fsck_chk_inode_blk:1254) --> ino: 0x1c100 has i_blocks: 000000c0, but has 191 blocks [FIX] (fsck_chk_inode_blk:1260) --> [0x1c100] i_blocks=0x000000c0 -> 0xbf [FIX] (fsck_chk_inode_blk:1269) --> [0x1c100] i_compr_blocks=0x00000026 -> 0x27 [ASSERT] (fsck_chk_inode_blk:1254) --> ino: 0x1cadb has i_blocks: 0000002f, but has 46 blocks [FIX] (fsck_chk_inode_blk:1260) --> [0x1cadb] i_blocks=0x0000002f -> 0x2e [FIX] (fsck_chk_inode_blk:1269) --> [0x1cadb] i_compr_blocks=0x00000011 -> 0x12 [ASSERT] (fsck_chk_inode_blk:1254) --> ino: 0x1c62c has i_blocks: 00000002, but has 1 blocks [FIX] (fsck_chk_inode_blk:1260) --> [0x1c62c] i_blocks=0x00000002 -> 0x1 After we inject fault into f2fs_is_valid_blkaddr() during truncation, a) it missed to increase @nr_free or @valid_blocks b) it can cause in blkaddr leak in truncated dnode Which may cause inconsistent status. This patch separates FAULT_BLKADDR_INCONSISTENCE from FAULT_BLKADDR, so that we can: a) use FAULT_BLKADDR_INCONSISTENCE in f2fs_truncate_data_blocks_range() to simulate inconsistent issue independently, b) FAULT_BLKADDR fault will not cause any inconsistent status, we can just use it to check error path handling in kernel side. Signed-off-by: Chao Yu --- v3: - rename FAULT_INCONSISTENCE as Jaegeuk's suggestion. Documentation/ABI/testing/sysfs-fs-f2fs | 47 +++++++++++++------------ Documentation/filesystems/f2fs.rst | 47 +++++++++++++------------ fs/f2fs/checkpoint.c | 19 +++++++--- fs/f2fs/f2fs.h | 3 ++ fs/f2fs/file.c | 8 +++-- fs/f2fs/super.c | 37 +++++++++---------- 6 files changed, 91 insertions(+), 70 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 4f1d4e636d67..039a16ebaaaf 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -686,29 +686,30 @@ Description: Support configuring fault injection type, should be enabled with fault_injection option, fault type value is shown below, it supports single or combined type. - =================== =========== - Type_Name Type_Value - =================== =========== - FAULT_KMALLOC 0x000000001 - FAULT_KVMALLOC 0x000000002 - FAULT_PAGE_ALLOC 0x000000004 - FAULT_PAGE_GET 0x000000008 - FAULT_ALLOC_BIO 0x000000010 (obsolete) - FAULT_ALLOC_NID 0x000000020 - FAULT_ORPHAN 0x000000040 - FAULT_BLOCK 0x000000080 - FAULT_DIR_DEPTH 0x000000100 - FAULT_EVICT_INODE 0x000000200 - FAULT_TRUNCATE 0x000000400 - FAULT_READ_IO 0x000000800 - FAULT_CHECKPOINT 0x000001000 - FAULT_DISCARD 0x000002000 - FAULT_WRITE_IO 0x000004000 - FAULT_SLAB_ALLOC 0x000008000 - FAULT_DQUOT_INIT 0x000010000 - FAULT_LOCK_OP 0x000020000 - FAULT_BLKADDR 0x000040000 - =================== =========== + =========================== =========== + Type_Name Type_Value + =========================== =========== + FAULT_KMALLOC 0x000000001 + FAULT_KVMALLOC 0x000000002 + FAULT_PAGE_ALLOC 0x000000004 + FAULT_PAGE_GET 0x000000008 + FAULT_ALLOC_BIO 0x000000010 (obsolete) + FAULT_ALLOC_NID 0x000000020 + FAULT_ORPHAN 0x000000040 + FAULT_BLOCK 0x000000080 + FAULT_DIR_DEPTH 0x000000100 + FAULT_EVICT_INODE 0x000000200 + FAULT_TRUNCATE 0x000000400 + FAULT_READ_IO 0x000000800 + FAULT_CHECKPOINT 0x000001000 + FAULT_DISCARD 0x000002000 + FAULT_WRITE_IO 0x000004000 + FAULT_SLAB_ALLOC 0x000008000 + FAULT_DQUOT_INIT 0x000010000 + FAULT_LOCK_OP 0x000020000 + FAULT_BLKADDR 0x000040000 + FAULT_BLKADDR_INCONSISTENCE 0x000080000 + =========================== =========== What: /sys/fs/f2fs//discard_io_aware_gran Date: January 2023 diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst index d32c6209685d..b7c5c3f6df1c 100644 --- a/Documentation/filesystems/f2fs.rst +++ b/Documentation/filesystems/f2fs.rst @@ -184,29 +184,30 @@ fault_type=%d Support configuring fault injection type, should be enabled with fault_injection option, fault type value is shown below, it supports single or combined type. - =================== =========== - Type_Name Type_Value - =================== =========== - FAULT_KMALLOC 0x000000001 - FAULT_KVMALLOC 0x000000002 - FAULT_PAGE_ALLOC 0x000000004 - FAULT_PAGE_GET 0x000000008 - FAULT_ALLOC_BIO 0x000000010 (obsolete) - FAULT_ALLOC_NID 0x000000020 - FAULT_ORPHAN 0x000000040 - FAULT_BLOCK 0x000000080 - FAULT_DIR_DEPTH 0x000000100 - FAULT_EVICT_INODE 0x000000200 - FAULT_TRUNCATE 0x000000400 - FAULT_READ_IO 0x000000800 - FAULT_CHECKPOINT 0x000001000 - FAULT_DISCARD 0x000002000 - FAULT_WRITE_IO 0x000004000 - FAULT_SLAB_ALLOC 0x000008000 - FAULT_DQUOT_INIT 0x000010000 - FAULT_LOCK_OP 0x000020000 - FAULT_BLKADDR 0x000040000 - =================== =========== + =========================== =========== + Type_Name Type_Value + =========================== =========== + FAULT_KMALLOC 0x000000001 + FAULT_KVMALLOC 0x000000002 + FAULT_PAGE_ALLOC 0x000000004 + FAULT_PAGE_GET 0x000000008 + FAULT_ALLOC_BIO 0x000000010 (obsolete) + FAULT_ALLOC_NID 0x000000020 + FAULT_ORPHAN 0x000000040 + FAULT_BLOCK 0x000000080 + FAULT_DIR_DEPTH 0x000000100 + FAULT_EVICT_INODE 0x000000200 + FAULT_TRUNCATE 0x000000400 + FAULT_READ_IO 0x000000800 + FAULT_CHECKPOINT 0x000001000 + FAULT_DISCARD 0x000002000 + FAULT_WRITE_IO 0x000004000 + FAULT_SLAB_ALLOC 0x000008000 + FAULT_DQUOT_INIT 0x000010000 + FAULT_LOCK_OP 0x000020000 + FAULT_BLKADDR 0x000040000 + FAULT_BLKADDR_INCONSISTENCE 0x000080000 + =========================== =========== mode=%s Control block allocation mode which supports "adaptive" and "lfs". In "lfs" mode, there should be no random writes towards main area. diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index b0597a539fc5..84546f529cf0 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -170,12 +170,9 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr, return exist; } -bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, +static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type) { - if (time_to_inject(sbi, FAULT_BLKADDR)) - return false; - switch (type) { case META_NAT: break; @@ -230,6 +227,20 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, return true; } +bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, + block_t blkaddr, int type) +{ + if (time_to_inject(sbi, FAULT_BLKADDR)) + return false; + return __f2fs_is_valid_blkaddr(sbi, blkaddr, type); +} + +bool f2fs_is_valid_blkaddr_raw(struct f2fs_sb_info *sbi, + block_t blkaddr, int type) +{ + return __f2fs_is_valid_blkaddr(sbi, blkaddr, type); +} + /* * Readahead CP/NAT/SIT/SSA/POR pages */ diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index ab710bb6d8b3..e0acfec0558d 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -61,6 +61,7 @@ enum { FAULT_DQUOT_INIT, FAULT_LOCK_OP, FAULT_BLKADDR, + FAULT_BLKADDR_INCONSISTENCE, FAULT_MAX, }; @@ -3768,6 +3769,8 @@ struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index); struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); +bool f2fs_is_valid_blkaddr_raw(struct f2fs_sb_info *sbi, + block_t blkaddr, int type); int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, int type, bool sync); void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 9f4e21b5916c..32a7a413584b 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -590,9 +590,13 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) f2fs_set_data_blkaddr(dn, NULL_ADDR); if (__is_valid_data_blkaddr(blkaddr)) { - if (!f2fs_is_valid_blkaddr(sbi, blkaddr, - DATA_GENERIC_ENHANCE)) + if (time_to_inject(sbi, FAULT_BLKADDR_INCONSISTENCE)) + continue; + if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr, + DATA_GENERIC_ENHANCE)) { + f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); continue; + } if (compressed_cluster) valid_blocks++; } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 206d03c82d96..87a803f36a50 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -44,24 +44,25 @@ static struct kmem_cache *f2fs_inode_cachep; #ifdef CONFIG_F2FS_FAULT_INJECTION const char *f2fs_fault_name[FAULT_MAX] = { - [FAULT_KMALLOC] = "kmalloc", - [FAULT_KVMALLOC] = "kvmalloc", - [FAULT_PAGE_ALLOC] = "page alloc", - [FAULT_PAGE_GET] = "page get", - [FAULT_ALLOC_NID] = "alloc nid", - [FAULT_ORPHAN] = "orphan", - [FAULT_BLOCK] = "no more block", - [FAULT_DIR_DEPTH] = "too big dir depth", - [FAULT_EVICT_INODE] = "evict_inode fail", - [FAULT_TRUNCATE] = "truncate fail", - [FAULT_READ_IO] = "read IO error", - [FAULT_CHECKPOINT] = "checkpoint error", - [FAULT_DISCARD] = "discard error", - [FAULT_WRITE_IO] = "write IO error", - [FAULT_SLAB_ALLOC] = "slab alloc", - [FAULT_DQUOT_INIT] = "dquot initialize", - [FAULT_LOCK_OP] = "lock_op", - [FAULT_BLKADDR] = "invalid blkaddr", + [FAULT_KMALLOC] = "kmalloc", + [FAULT_KVMALLOC] = "kvmalloc", + [FAULT_PAGE_ALLOC] = "page alloc", + [FAULT_PAGE_GET] = "page get", + [FAULT_ALLOC_NID] = "alloc nid", + [FAULT_ORPHAN] = "orphan", + [FAULT_BLOCK] = "no more block", + [FAULT_DIR_DEPTH] = "too big dir depth", + [FAULT_EVICT_INODE] = "evict_inode fail", + [FAULT_TRUNCATE] = "truncate fail", + [FAULT_READ_IO] = "read IO error", + [FAULT_CHECKPOINT] = "checkpoint error", + [FAULT_DISCARD] = "discard error", + [FAULT_WRITE_IO] = "write IO error", + [FAULT_SLAB_ALLOC] = "slab alloc", + [FAULT_DQUOT_INIT] = "dquot initialize", + [FAULT_LOCK_OP] = "lock_op", + [FAULT_BLKADDR] = "invalid blkaddr", + [FAULT_BLKADDR_INCONSISTENCE] = "inconsistent blkaddr", }; void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,