From patchwork Wed Dec 20 13:59:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 181658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2662723dyi; Wed, 20 Dec 2023 06:11:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0PYDJppmQU9KaVAsAZuVBoOpMERPtNxVyQRCWcUSuHmoPvu4cj4QI6zYe/AketkVEtuzt X-Received: by 2002:ac2:4211:0:b0:50e:54be:150b with SMTP id y17-20020ac24211000000b0050e54be150bmr390846lfh.122.1703081463270; Wed, 20 Dec 2023 06:11:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703081463; cv=none; d=google.com; s=arc-20160816; b=DQ//4j0TqeNVCF2qDZ0jXHwESMBpfIvIpFmQwFSgtohesU1cSZObscOVq//Uw/rgE8 KY4Pt4K3h5pBgYhdVjgPzb6kR1s+h4OZ7tdd+w/xlHa2zA0BW/dTTRsmOlZQkg/U1+WF Y3bz+6GWpWtRgwmuSoesphtfzLBIW/NCdMcTiBi2dKKp8kDVyEBd6XJzjPVTOGOBdIfx 6NfTjUH9qKotZjTvIeFStTZBUHNhUTkSYJGk6KOsJgXtuJwvY8CIpJAIwfHAeJ6m3cnF dX/LumRxfPOVI2QlWhx8OLvLLyGLYUFGFVOd/cSoF1NZoUngxbr+HBFhLuobPylA497W XkXw== 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=xscjI8hRCqb0TVF/ZPOmL17Fu99hTNWTrn2y8jLUfpo=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=HsENtSWLdhiTJa3SvISRobq6d3yjRU8kNd0IeDbC6ONTYR8HwyxnnhFwZpO3aTJgop ldSgPL87Sh2duzG6EOLgTLfa412EwUjWCpj0wmHX9xgJNGeeWfLUvK7YkW7x64WZ+grP ilOkfqeHYHXDENXSkZZl0QtTpFSFuZFf1qBEWQDgRd4xqmz2Jmo6fmRDvKGdYN/6n9VO Fkk8jADS0VRQt0bR53wktplRqzijfP8QgYRyQeNve8RIRbOVNtWiCf7LGVytkpvK8V7a D25sUNeb8yub3LRY3u6iZcayC+32itCFytkjRjE4oiTmO+nJcuT8RSDonC6pda3vF7jg L+Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="LsflaQn/"; spf=pass (google.com: domain of linux-kernel+bounces-7011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7011-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 lr8-20020a170906fb8800b00a2353445209si3058673ejb.686.2023.12.20.06.11.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:11:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7011-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="LsflaQn/"; spf=pass (google.com: domain of linux-kernel+bounces-7011-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7011-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 D53FF1F220C5 for ; Wed, 20 Dec 2023 14:01:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 105173B7B5; Wed, 20 Dec 2023 13:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LsflaQn/" 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 765A53A1B3 for ; Wed, 20 Dec 2023 13:59:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C1FAC433C9; Wed, 20 Dec 2023 13:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080781; bh=1NoN4vHX+F5B0WJZK8QqQakY9pc1N432/Yr899L6umA=; h=From:To:Cc:Subject:Date:From; b=LsflaQn/Rpi1r63bTcKQzLAw6EfRwK9cBsHYh2in+KK6g6cuNWDLwdAppjiihuRPE DUh1q6tb8kH/p+aNjHZGtKNGSH47k8IPkYzKP1KYu9+0v6RJW9cTl6gIw36PkVv7lw VcsmWYBHfZG++2ANDm7PwM6g65zOvG4hJTdrQnghgTb9b4WYEfLk3Qu0OhvwA43clV Av9IjNnnAYkKuVB9Mrhv/RPZ1MisWBUU3Mqe2X18y/hrGur6vgPHhJLLSAqG4yf/fk mAlr/bWMlcn5tyW61vmyqOfPqRrpT4HS2QuDhkI1ZzpaIhtg/qFQ/3qogGw6ItMCVg QFUKONcK8dPLA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 1/6] f2fs: compress: fix to guarantee persisting compressed blocks by CP Date: Wed, 20 Dec 2023 21:59:29 +0800 Message-Id: <20231220135934.3471407-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: 1785810348376268121 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 --- fs/f2fs/compress.c | 3 ++- fs/f2fs/data.c | 12 +++++++++--- fs/f2fs/f2fs.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index 5b076329e9bf..1122db8cc0b0 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1442,6 +1442,7 @@ 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); int i; if (unlikely(bio->bi_status)) @@ -1449,7 +1450,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 d28c97282e68..6c72a6e86ba8 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; @@ -66,7 +66,7 @@ static bool __is_cp_guaranteed(struct page *page) return true; if (f2fs_is_compressed_page(page)) - return false; + return true; if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) || page_private_gcing(page)) return true; @@ -1007,6 +1007,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 +1047,12 @@ 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); + /* override count type if page is compressed one */ + if (fio->compressed_page) + type = WB_DATA_TYPE(fio->compressed_page); + + inc_page_count(sbi, type); if (io->bio && (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio, diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 76e9a8682e38..bcb3940ab5ba 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1092,7 +1092,7 @@ 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) (f2fs_is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) enum count_type { F2FS_DIRTY_DENTS, F2FS_DIRTY_DATA, @@ -3824,6 +3824,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 Wed Dec 20 13:59:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 181651 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2653469dyi; Wed, 20 Dec 2023 06:01:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFulk0O2sX+MUSAXsdgYLRB8rKkhZAt1jV9RE0HWFjLyqAvBPFzjq1PhGlUBz2XdPL4KFcB X-Received: by 2002:a05:6214:2486:b0:67f:3bd4:3770 with SMTP id gi6-20020a056214248600b0067f3bd43770mr5284378qvb.25.1703080878937; Wed, 20 Dec 2023 06:01:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703080878; cv=none; d=google.com; s=arc-20160816; b=DLe78SdSuStv0XJ1C6glcxblqZQRn8IUxEvHDcEE9v8x6OzxCrebekzKhzGIB2/CKY cPq9Cl4LF8e5Zc0aROac0vmHHoo1il84cptrtEownMVBa1VjKbJGCXauulATdo7ACErA DL1e0KUAV7tMi/2H+ktDzH2tVxAQfy4zQvYPHjOCfdDyqfdMfzgAuGXJwa5TFeu5lNnd wWnXZjKeb7JLmW5S0BY7XOChSjDoUKd11WhsN+opgO/1Ui5cEAq/Hna9LFArmwK9Xhfm B6uOtPisNOKo0V9uJUMVbcYGEAjyJN+hM3KAoyWLX9m/GlYkdsrGS5EUhNmS8H7zouIl Bs6g== 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=c4fyeCY1wp5FzjpWoC3wK9/lThvHooCDuVfznyQFUsA=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=UHPOF4hkeP8WzoYbluIba82T2TvE+k7pYWk+9+lj07dYeIZV87Os0rckewJ/VCus5U 4bnv8/jIj1+H9GoZOa7IRRPvLXfZN7GKaDG2FaPE8Hg3xGJuKda9du7H95L0HMG+EGm5 maxdH7fx/C8AlhhBZEEIU/wHwcifI+RIu7DZVCjCHVQcsphctGcZnrfY/PXbdyjAWqNw 2r/dJYx3SvNsj1sRzefn3rawwUjm9R12zSYLZTuISZfZ510hgZBcgqzbE/uY7sIvG1HP RAeILrr2nA+2wfj+xewsohVD5HQJex0lsyXm67r0zXD20l4ALU+AZohf1ktoZhRRsdXZ 5Gfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VAx8QlLM; spf=pass (google.com: domain of linux-kernel+bounces-7013-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7013-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. [147.75.199.223]) by mx.google.com with ESMTPS id s11-20020a0ce30b000000b0067f77714e1esi414961qvl.283.2023.12.20.06.01.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:01:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7013-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VAx8QlLM; spf=pass (google.com: domain of linux-kernel+bounces-7013-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7013-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 A83031C210E4 for ; Wed, 20 Dec 2023 14:01:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 002C43D0A6; Wed, 20 Dec 2023 13:59:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VAx8QlLM" 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 6F3C13B2B2 for ; Wed, 20 Dec 2023 13:59:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A60EC433CC; Wed, 20 Dec 2023 13:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080783; bh=HlIylD6IwGlkcvAcDhSn7XsD9KaF9Cn4cGLKY52iKZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VAx8QlLM9/SAVXDNxAz7Vm0DbGUGFuklAUi9oWrXB2siqcfYl9r8e7XOChcN4D/Qt xYOXSp7QxrttGDBWDLva4C/KR4QUc1uVnnB3taBjsdab4tRRz9aoM6eOn8KHhUSRik yoI1q/DaZ6Rv6lxN854d+RSSfV6XwtjZuKMsK5veySxq7mflzYcUwhBxKHMi4jqYmX yJHnbh4DQqEp3u57DtS2hcfwgTmo8WaZFLQPO2C1UE7qlbZBgy8xQKwrtfvailz4xi u6VpYHaTbn/olibbEvjwuTOfzOEJU+wehVd/hMyg+dYY6ZF/GPdoNGGiiF7L37IXvs kKXTwkHTljw3A== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 2/6] f2fs: compress: fix to cover normal cluster write with cp_rwsem Date: Wed, 20 Dec 2023 21:59:30 +0800 Message-Id: <20231220135934.3471407-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-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: 1785809735354936545 X-GMAIL-MSGID: 1785809735354936545 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 1122db8cc0b0..a1426c3eadcc 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1471,7 +1471,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); @@ -1486,6 +1487,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; @@ -1518,26 +1523,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 6c72a6e86ba8..ceed5ac6c66b 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2848,7 +2848,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, @@ -2929,6 +2929,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 Wed Dec 20 13:59:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 181652 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2653790dyi; Wed, 20 Dec 2023 06:01:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGaQDdj/iORdrdQJzWjVdfAnbiXIcu0lt8be7jlYgY8N5VOlf6w86/uLrZQ/ZWqNx4oxzu X-Received: by 2002:a05:6214:2a89:b0:67f:2fde:1678 with SMTP id jr9-20020a0562142a8900b0067f2fde1678mr6882546qvb.42.1703080896335; Wed, 20 Dec 2023 06:01:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703080896; cv=none; d=google.com; s=arc-20160816; b=uvsAAqWHFenW8m9ZB2JeJPsxAhLP2ssqFrkeolTe1sce/Thy6BS9BOBd/EkUkdiTag rsIJSZIirQM3gk1q75l+AvHGudWiBEr2BdPZwLcIQTB5u6G6FaMoPABHxPZl6dwaq1BO Gi9TonpFsD+fyGg+uFkhIrS9TIikebcbcdu39BXcgGifDBBgRxfbNEMoqIe4Sy7gQ2HD SFe2SbZqeWP20rW4CPkvw86XxzBUpJg+SPV/sUw4nOZklbvXU1oydYBHKj4BskiX7DtE 82IQena+43ShrEhrKtQucnoa3ZoDfsIXv2kBs/WtiLCCMh2QUPR18sbk1eGMGi2IlY4w 4dRw== 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=PG5vzWF2/Zst7Rv4M9EAEkwmGP1h2Y/muDmldfhvo/c=; fh=2w0/+7CnNSrmHtbae1hR3pLuwOJRubjB5ynbCr7QyGo=; b=k9JMhwBLWUuGW6qBti03WMCfqt6/Dwp2bJvKGHf6V22jeINpu9tY1jR1Th8ziBQfr7 bh70UyRx6+Kh9CDjv5JnHD1S8bT6FMULBW3UZab2BphrZiSyHzr6ojheVF6QdwfMoSvn l/No8pDL1cocmuYmiM6WPPzGFblJk/152+ollgO4rksyLR48h8tK1G7NfMaPCj1v/ZWM 3t5I+pJvqjcfXP08OY2O8SgqZCHZniHobdcUCm6CqJeAWOJ/4OExCu4/tqnQkbmnlP3+ ihFZYm7V+4NgmzM2YUpMJ2z9mwZW4snIMHlP3dGt+uHaQdzO9yHWtQBZDJxpe9GxSWh0 01Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OL7AZ7SR; spf=pass (google.com: domain of linux-kernel+bounces-7014-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7014-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. [147.75.199.223]) by mx.google.com with ESMTPS id z5-20020a0cda85000000b0067f79fc97f1si209081qvj.397.2023.12.20.06.01.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:01:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7014-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OL7AZ7SR; spf=pass (google.com: domain of linux-kernel+bounces-7014-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7014-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 6B0091C228BE for ; Wed, 20 Dec 2023 14:01:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32A433D3BA; Wed, 20 Dec 2023 13:59:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OL7AZ7SR" 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 A343E3B2B3 for ; Wed, 20 Dec 2023 13:59:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8229AC433C9; Wed, 20 Dec 2023 13:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080786; bh=v4LG7qKqe/M+w+R9MpQa9X4bJKEDltOmx7SXeOQu0+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OL7AZ7SRexIAReodySDXML3iH2ENLvevRKCZBxFla/XCSj4J9zJLC1wtYmtdpbRlk gw89uKyBFqkPsyV4hoNrqupk4BsEgh5LsguNh4j3c2o21x/mEzvpCvKSmmqQdwl0B1 xvVuzC23KncXqWNCUTWuY1Qa9RzkARpusQnqsCPKN1dYS4LT/8CzWncLobPQYMEfMJ 54ptx4MbXrSvaUFIXL6OZoAkmy/1YRQYAYX5vKtZxl87pWshX/cXjQsdNxZhlQblsB BuKQ+8HAbPp+PHB/iQ9snsIiVZLFvg45E3XPIGxrhOlpVOS6tjB7aqL9aMNHS9phbn 50aZGm6QlwLDA== 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 3/6] f2fs: compress: fix to check unreleased compressed cluster Date: Wed, 20 Dec 2023 21:59:31 +0800 Message-Id: <20231220135934.3471407-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-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: 1785809753812201365 X-GMAIL-MSGID: 1785809753812201365 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 c5e681fc1d58..c200b4c81baf 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3643,6 +3643,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; @@ -3652,6 +3661,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 Wed Dec 20 13:59:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 181653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2653971dyi; Wed, 20 Dec 2023 06:01:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWcVR03rbYW7z3B5ZTpRZCJvdjxYCk/vFiGsraYutmGgdxbOOFhgc8HLYhJKKYtzFz7Vte X-Received: by 2002:a05:6808:320d:b0:3b9:e80b:709f with SMTP id cb13-20020a056808320d00b003b9e80b709fmr24787387oib.83.1703080908286; Wed, 20 Dec 2023 06:01:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703080908; cv=none; d=google.com; s=arc-20160816; b=Ir0zBMLyE43c5iMrSTfu5GNP39fC7O99ncEc+4p1oiamSKLggymDdjVjWZl9mIKmJ4 3cf94gkA/av8hQS6LfGEjF3zXX9B4Tz1qskwJw2tQ/CZ9vVs9JH6Ejtu18Z9y/+QyH2v 5QsmQ8dfjGTLrBD94SLsmkYt8dh+EZcaFpwZN0IHl3yeRsP2Kr/uq2gQc14hYYG7QPD+ En6Ec+rcaAYegTgrkUY2IBypgpCjafm3jwWazwdFOlv8QQCbEGkuc5/bagSUDCS18Cl7 iJDPwA4xw2mBFGwpGtRfeCdYHKfxEjOaNeSdJC0oZAr7wTLdtSMQ78NjFTdHu+nRoili JkJA== 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=32GlP9vHEqARMVaEpjyRz2ivgY/q1Q1PAMgFqPrgVs8=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=UFhEtwLbgrrmh5fUqdbRxbXXqjCBCuNMjl5tY4yCZCQL28JCNvukac6hYdZaqQMypi uk3om9rdYoKiKHjjXLwGLbf4chjnFyE2Y50LxqKvYOSBHL7SfNF287to9pJj1vDLg2PG 0CZbxsdMrvlLErcaPexGL81rOc6pLPw6/ZY1gwdCh1jLG56JQeQ7VeJ76/bDDLdnJIDL LDmZI/4/u3nkIpAYpujyIKEzXqeyoYkRtRAmNfE9cldV+kLz/jBrixGmkQw5VokV1b19 pjTx/xTEUO3n8kKd2JgTEgZEWyz68w1bHvRJVYFEuCsWDlW/BlKyTdb6HGyv4btk6BSB PdUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f+Xem3SD; spf=pass (google.com: domain of linux-kernel+bounces-7015-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7015-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. [147.75.199.223]) by mx.google.com with ESMTPS id n4-20020a0ce484000000b0067f6386b3d4si3149661qvl.345.2023.12.20.06.01.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:01:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7015-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f+Xem3SD; spf=pass (google.com: domain of linux-kernel+bounces-7015-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7015-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 2A47D1C20B8D for ; Wed, 20 Dec 2023 14:01:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E212B3D988; Wed, 20 Dec 2023 13:59:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f+Xem3SD" 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 5A3303D38D for ; Wed, 20 Dec 2023 13:59:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBDFAC433C7; Wed, 20 Dec 2023 13:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080788; bh=syTLTyQL0h6bm/dVO7pwCM9/CV4AN46/r4l6pfWHOsk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f+Xem3SDh/g99pjEVufXEyyYTplXClv9zD6wXfHQwb+grX1vfInCbK0xd+jGB3NWr sN92ub7zMqSpU6mGrNFx3TeQIYR3xngeYKtLy8zt6xGgWDU4RwAGi5j5Yyv63Kv6rO k7oX8GeZFKZF0dwOt0BxtO3EFM6aAvk3hxGX3iqHcmTI7vHmtTVePS8HEGQjxKLpDP Ihg1Wf/yOH3qLzMeu0NTd9/aECTj2+HT5FtVD8MW2wAadyp/IgN9BAAsh4hdSv5bA4 Zb/YkGlt+TTHnO54zERz6Sk1nHQaLxXFVVtzGlktNXYFwNOj4UH0W4wRDMxP5aNDut NH+gV9zHyPH5Q== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 4/6] f2fs: compress: fix to avoid inconsistent bewteen i_blocks and dnode Date: Wed, 20 Dec 2023 21:59:32 +0800 Message-Id: <20231220135934.3471407-4-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-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: 1785809766078718409 X-GMAIL-MSGID: 1785809766078718409 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 ceed5ac6c66b..cc4cb9099db6 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1224,7 +1224,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, @@ -1481,7 +1482,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 bcb3940ab5ba..541c52fe2872 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2294,7 +2294,7 @@ static inline unsigned int get_available_block_count(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; @@ -2320,6 +2320,11 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, avail_user_block_count = get_available_block_count(sbi, inode, true); 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 c200b4c81baf..4f3ed627f6a1 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3633,14 +3633,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; } /* @@ -3656,20 +3658,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 bafdd2295957..f95a2e914baf 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 Wed Dec 20 13:59:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 181654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2654232dyi; Wed, 20 Dec 2023 06:02:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IEnQJOzih8iPpGPu4ZkKOlaELYw7qMHioxy0+ovCuAJv/ZTy0shTYFlgTXb2mE49dP0k1qW X-Received: by 2002:a05:622a:509:b0:423:6fca:66f1 with SMTP id l9-20020a05622a050900b004236fca66f1mr26423735qtx.0.1703080922319; Wed, 20 Dec 2023 06:02:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703080922; cv=none; d=google.com; s=arc-20160816; b=eOIG6xlPqX/f6AH5oPDpVPA6PgaqiQINmND/YUzeF9UA5IObNk3RPjqw5KrOpCUq82 a48VX2aZEc/Q1TvySoYxqje1cmVLTQutNLDpyRh2SPHyJI5aJ//7DjQyjRhXSr4zySKg 3KxYvNskhV28Au9UVzk7qJMUwRiQ83YpHbeUAKdqjzjJeotbOBjDglf2uCAeDWi/euEY Jtdj2CwmUGjtgOsHxsgM7S3aGj434vgyPEnnJ0i1cE0/U9epCR+Ynp5ayyTHteHmT+3A r25Z4ahnE2pzjfrTT682CG3CBEpk8sDNkUNgXHJTUlcE8L/QWGw2aaAz7FiKDEJFbDvm vcAA== 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=jG1xYjeQFCncjaAKEpZbGnvc9Orum4R/wVy+dZd+s5k=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=zmbxoKEA+AU+iBJbTXClHh8yi9RD2Jem0htbsxN1eQs63EQAWqks6dpUmGJvZgAbdG eNRf/PKtI5h729PrLDpXe9aApe/kcjFLBnuQaet9mzxRiHi/xBT0iBVlURm0tvp36EqI vNKWbiBgvYdImBj/e37nNyWYcKfSbwwgOLMvl3Me6rVyOUPiNnELlo4CqADoULmkHtrh sWf29ReTxQ7CHXmH1dEpmCEUL5/FSaiFJ9db6Y9uPbx0RYtiAHN4KUEbNaQ7wgQ28EL6 UNSK9O/QzP7/2/aDVBl8J/3FqXNsp0CpUyoiG7XTKk3BeTLNb/6yfylNtQAWTnnuFg+S zhbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p7AP1VMH; spf=pass (google.com: domain of linux-kernel+bounces-7016-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7016-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. [147.75.199.223]) by mx.google.com with ESMTPS id t2-20020ac87602000000b004254f6371b0si26482541qtq.250.2023.12.20.06.02.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:02:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7016-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=p7AP1VMH; spf=pass (google.com: domain of linux-kernel+bounces-7016-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7016-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 045021C20C67 for ; Wed, 20 Dec 2023 14:02:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25D453EA92; Wed, 20 Dec 2023 13:59:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p7AP1VMH" 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 9542F3D97A for ; Wed, 20 Dec 2023 13:59:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF137C433C7; Wed, 20 Dec 2023 13:59:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080790; bh=a+Zr5UnD9JUAPNdpT3P1rGDjRu5/Oz4DN3bx1yho9co=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p7AP1VMH72ySxKDNYPwmOKGF7q51vqQMEB1+DXpAwpCyC6g85zy8oN8ik0NtuGECt fw5/oI6jiG4jODCmtW47jZNlF0pSs44rma9TnkTgz4+Rn9VKUA0XdZCAbjTTqWg01s 1Qe/SnxCpB7xpntmDxOOGwId82y/UnScwUQW/JoHkbw/UZ9V0qRiIdGRM0eexxPq+2 YwSJkO5n7pQeyvWeF7tgDH+FLyXYB7cbJ3Xdx7yRW9PwI8Ss8zqIZLy96dglx3O8+0 c/34qbSGUVjWs7wAi2hgltZ7HqAb6Ok3MFqvnR6HgZolU06+U4Vu5Pxk3uEynOOqL8 M10J8RnmP5IDg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 5/6] f2fs: fix to remove unnecessary f2fs_bug_on() to avoid panic Date: Wed, 20 Dec 2023 21:59:33 +0800 Message-Id: <20231220135934.3471407-5-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-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: 1785809781085105941 X-GMAIL-MSGID: 1785809781085105941 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 541c52fe2872..9487581db08a 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3489,11 +3489,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 Wed Dec 20 13:59:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 181659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2663282dyi; Wed, 20 Dec 2023 06:11:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWuJVoLcIucGh2EclvDo/rgtZO+7flNYgLgjbyBLNMu3oZYfESL4gnMLZ3Sg9J/wwQOAhL X-Received: by 2002:a17:906:a84e:b0:a23:4b6c:7dff with SMTP id dx14-20020a170906a84e00b00a234b6c7dffmr3123001ejb.115.1703081505457; Wed, 20 Dec 2023 06:11:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703081505; cv=none; d=google.com; s=arc-20160816; b=JWxrnFYW8wOMKXKn0uQPJrbIJFcmuZ9FQ7inFyLP0ozLfzBlamZkVEz+oGizbbhaYo KY2DqsgGDpXuhxD//+GvomptojWTws+qkguj6OxGR7Im4PC+PMb/szniZ8/KSxRStYDL gOzJgl6cMXU7S6z80ifqRgNgrPlq+3ZY6Ls2n4bfdL+UDYzYozsS9TwQ8ww3c3G+Trjr tFzx9yp6i6yjrNAccbHJJxG5FodtEbKcKXdNZo+aWcfn/tuxxCP17GC0Ivy7j6q1urx5 h1Eb9Z7maUaE+jkY5sN3NWosaDpug2HPdEDfXCHmH/A/8U8ZD+v6/R1+v3PkyzJQi3R4 BYCw== 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=ADmk9SW4UgZx1Gt8dfBrDImUmmYFyOX+V1ThXwqp8CA=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=TTdf6yG5WWWCFjYJykO7wg2MgnHPO2Gpew73oVBxCZMbPhUDNcrP5wMwPWhYEWvyHT HMSEBkcST5BN/AGiRZsrLKWr5fJfiJfksMKwUYl+Helv3hLyLrNQn3jTFkZNNoBbpKoK 9qtdwg83E+5k2DStsFkrAdw3oYBf32KIBvzcsEWD8fP8B9odOtfoH950wvZFnOP4hVpo RrFEgvinigksIZAfSHegwQjcsdLCGQYHnNx18tLgpFX93yl6RcQCI4O2mUh+lAHZ/3wn qLFS4Dm9BnerUjorTZ/QbpwkFtd7IkUuaO5R76erYiRm/U2CGZWMV0r17/SPrXn7IAQl e69w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="rA/+TbY9"; spf=pass (google.com: domain of linux-kernel+bounces-7017-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7017-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 ci19-20020a170906c35300b00a23526d2e53si2931191ejb.175.2023.12.20.06.11.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 06:11:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7017-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="rA/+TbY9"; spf=pass (google.com: domain of linux-kernel+bounces-7017-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7017-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 E71CA1F28016 for ; Wed, 20 Dec 2023 14:02:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A6843FE29; Wed, 20 Dec 2023 13:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rA/+TbY9" 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 CD88E3E494 for ; Wed, 20 Dec 2023 13:59:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCAC2C433CB; Wed, 20 Dec 2023 13:59:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703080792; bh=W2roxFRnwD7OFBUoZGhnWeFociodl3+VYdCaqAo2V0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rA/+TbY9/3iHsCkeDwv3DGjklnUjcgF96veKb4IYxEeTOefB7KB+7XvuI8qB5jT/h 3cbxpx5O7v+qc0fzfLQ9FTnTSkx3IJ+851v7UHN0SFcKkFmExcWdFrohLiLEZKDEgH rZckz4T6zWbNAU6HrsBZbaotesOY1v3lPOBrgwI/LRdbF4CPv83r9fI3V2YwIR781f K4CWRsiy61oSa8uIwRQkStY2nm3F5aKG6WN4tZxnXute+XP3dpkLxbDMkWjS+CxkzV ZAtr44wtznR3668+oZvk3VCHLSfI8mEMznTB4ZgFl/X3fsaqN+Cx7JF14MA/V/Ex+1 HWtB6HauAfwHg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 6/6] f2fs: introduce FAULT_INCONSISTENCE Date: Wed, 20 Dec 2023 21:59:34 +0800 Message-Id: <20231220135934.3471407-6-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231220135934.3471407-1-chao@kernel.org> References: <20231220135934.3471407-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: 1785810392520453532 X-GMAIL-MSGID: 1785810392520453532 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_INCONSISTENCE from FAULT_BLKADDR, so that we can: a) use FAULT_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 --- Documentation/ABI/testing/sysfs-fs-f2fs | 1 + Documentation/filesystems/f2fs.rst | 1 + fs/f2fs/checkpoint.c | 19 +++++++++++++++---- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/file.c | 8 ++++++-- fs/f2fs/super.c | 1 + 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 4f1d4e636d67..649aabac16c2 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -708,6 +708,7 @@ Description: Support configuring fault injection type, should be FAULT_DQUOT_INIT 0x000010000 FAULT_LOCK_OP 0x000020000 FAULT_BLKADDR 0x000040000 + FAULT_INCONSISTENCE 0x000080000 =================== =========== What: /sys/fs/f2fs//discard_io_aware_gran diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst index 5a1686cdd6b4..dfc1e73b17d9 100644 --- a/Documentation/filesystems/f2fs.rst +++ b/Documentation/filesystems/f2fs.rst @@ -209,6 +209,7 @@ fault_type=%d Support configuring fault injection type, should be FAULT_DQUOT_INIT 0x000010000 FAULT_LOCK_OP 0x000020000 FAULT_BLKADDR 0x000040000 + FAULT_INCONSISTENCE 0x000080000 =================== =========== mode=%s Control block allocation mode which supports "adaptive" and "lfs". In "lfs" mode, there should be no random diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index f3f3e98fd6b0..b59db6c1932c 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, +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 9487581db08a..49e4de324841 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_INCONSISTENCE, FAULT_MAX, }; @@ -3787,6 +3788,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 4f3ed627f6a1..6c4c739d73b3 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -593,9 +593,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_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 29b9e6e3eb5f..5659166b3918 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -62,6 +62,7 @@ const char *f2fs_fault_name[FAULT_MAX] = { [FAULT_DQUOT_INIT] = "dquot initialize", [FAULT_LOCK_OP] = "lock_op", [FAULT_BLKADDR] = "invalid blkaddr", + [FAULT_INCONSISTENCE] = "inconsistence", }; void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,