Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1301144lqh; Mon, 6 May 2024 03:42:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNYPWvGT7E+9QcV7GZdv9P3lCFChhmDhZkQhyH/LvsQR2FYt8SOAd1RS7/bx+lIVDHQIIOzmzoJKSKWUpfLMBJte8tLOQzRdOSpF5yRw== X-Google-Smtp-Source: AGHT+IE7hXIORYp/juFGZAyPeYDV5sc0RcSWlrlWnHROOZHvLb8c9b32hm0yLHziYNiSVk/dap5Q X-Received: by 2002:a05:6a21:9206:b0:1af:a4bc:1f71 with SMTP id tl6-20020a056a21920600b001afa4bc1f71mr4911453pzb.26.1714992142530; Mon, 06 May 2024 03:42:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714992142; cv=pass; d=google.com; s=arc-20160816; b=SxgolZXcmqyAXrQf4LBd++XCPygor+7pdrprP9yjQ4DY/Dmf9beL/lHPUikvIFUAJQ 6Y6J5TBEhhPPUrtULY3GX3eBzznk3qX1iaO7cOa7iHYDJ7u1pGD/QV3+T50L9m4Mq5xB lUL2r8zlIhzof7vXXKE0W1EqhYIEc7k9x/I5xnBJ5KV9t1OW1R1dQZj/bsv2+YTf3uim 4UYQncY7CFvl9OalOpQrndlNVJmKr7gvrij0Oo26404psXe/FRJUI1HCJfgLgztQd3VY 9xHofaIjPSCJIbpygEpq7894ECvnmQ6pjxORu0FOepYekn0pBuqq2AIfBy7/kY+vi8V4 pq/A== ARC-Message-Signature: i=2; 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=BxArMdgJXALH7kX7KC1uLNCx8j7YG3n6T1DTG2HPg1I=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=pYgY2a71uVqQIyEftjeQdy/v6pHenFTKFWvwZ5uTq0Pqp9HqINR8if7QOjAHFlmywc O/LA7aFk2xvg4CFyMFjMN64cdBdKDs9WQwqdm4eA3JvQeYxZ7B7QLugjXxvYejAAPRX5 ax6JFAYsagKVfITFKeR/AhLdElWejwPOqduIgsynYVkeiXXN1XRy8D7D5Em5H/qfG39T Rn/SvPJCW42FJ9PbFRuyYNH6FOR19iiTIMQiyzCxoF5uUYiCRq7Kl+nyo2VuH0g7xC6D NR790ITbJlm+q15Ik8nv7lugl6ZbH9B8j1iJ8tkrFkekCUt3Gyd86aiYzZuTDnR1ALQ1 /3Bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=boV2IkvT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-169683-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169683-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u14-20020a17090a3fce00b002b4e4d2b722si3300109pjm.147.2024.05.06.03.42.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 03:42:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-169683-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=boV2IkvT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-169683-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-169683-linux.lists.archive=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 2688C28433D for ; Mon, 6 May 2024 10:42:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 175A21428F5; Mon, 6 May 2024 10:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="boV2IkvT" 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 4532C762EF for ; Mon, 6 May 2024 10:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714992131; cv=none; b=jRsk0A5bXFZIYBt1zpcF5njt33En4lU0CjwDY3K4qmaqrVC5HBzcQ/xLpIBJ8yqHBag7aKOZq/sdKRF+/7/Ro1X+KoPn/YGWwIllrkgJ0/d+hB8BM4zMvBSVTQOQtx0sd+YRS742HYcLoWWVvO/OOP1thmQNVj6QfEtRhR3LjwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714992131; c=relaxed/simple; bh=v82z/f0v3qlNA/pUTvtaHNQodyv569B9p8AX3nujvZk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P9uWTc/9hbUhAM/YroqsnPD6Iqo1fNGZZy6TYfIAFkRIe49OviaHi+InhTb/CNFrPq6jwJIGKwZgzCh1ZjRuA+UW1gLLW4e/HbeUxb5NEMFvO3sEzMDzYHExnW1K14UDO9nIkOv5MssgsjA18Fdl/8K73PPpOxZCpkhJ9IpUCWA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=boV2IkvT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C3AEC4AF63; Mon, 6 May 2024 10:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714992130; bh=v82z/f0v3qlNA/pUTvtaHNQodyv569B9p8AX3nujvZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=boV2IkvTKAOy7YPAYJ/6WZNNps3mLpo5SdXeM5EZN8FpPP/Pn2RRUM9tUTbEATUXm dbAD+zMropII+XZY7MDHJKFVUtIJFrKCKE5AgpkikNdBWiIZROAqGbLw2nlZk1XQNs EuM/c+V/LZ9XIc11EEdYIzN/vVH7mB+bOqVgqbnKLvGlAx96IwZ3CB6FZHT8S+Hiuj 7w0t7yz40dvcdJpECFuvBYgbEKu80LrGLP5nGwJYyX6a+gEUXNfeaZYfOY7n3Y00BN sHwWbLWKzCU4zKlgQkyLaXjIz0kmbQ/5BMnCCGASy8bm5n86zB4xDZ8sCCda3MmIdl gPh/QD7CnAD2A== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 2/5] f2fs: compress: fix error path of inc_valid_block_count() Date: Mon, 6 May 2024 18:41:37 +0800 Message-Id: <20240506104140.776986-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240506104140.776986-1-chao@kernel.org> References: <20240506104140.776986-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If inc_valid_block_count() can not allocate all requested blocks, it needs to release block count in .total_valid_block_count and resevation blocks in inode. Fixes: 54607494875e ("f2fs: compress: fix to avoid inconsistence bewteen i_blocks and dnode") Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index c876813b5532..95a40d4f778f 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2309,7 +2309,7 @@ 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, bool partial) { - blkcnt_t diff = 0, release = 0; + long long diff = 0, release = 0; block_t avail_user_block_count; int ret; @@ -2329,26 +2329,27 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); spin_lock(&sbi->stat_lock); - sbi->total_valid_block_count += (block_t)(*count); - avail_user_block_count = get_available_block_count(sbi, inode, true); - if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { + avail_user_block_count = get_available_block_count(sbi, inode, true); + diff = (long long)sbi->total_valid_block_count + *count - + avail_user_block_count; + if (unlikely(diff > 0)) { if (!partial) { spin_unlock(&sbi->stat_lock); + release = *count; goto enospc; } - - diff = sbi->total_valid_block_count - avail_user_block_count; if (diff > *count) diff = *count; *count -= diff; release = diff; - sbi->total_valid_block_count -= diff; if (!*count) { spin_unlock(&sbi->stat_lock); goto enospc; } } + sbi->total_valid_block_count += (block_t)(*count); + spin_unlock(&sbi->stat_lock); if (unlikely(release)) { -- 2.40.1