Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4049152ybi; Mon, 3 Jun 2019 05:00:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3oqEtqJF7ydyqjDJBSvRh2n6Igtctaw9Gbo2Y3BA3l62PhBYVv2kdH9z/J4LwOrSg5juk X-Received: by 2002:a17:902:bc8a:: with SMTP id bb10mr29748075plb.310.1559563213262; Mon, 03 Jun 2019 05:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559563213; cv=none; d=google.com; s=arc-20160816; b=Zfo6AieqiZldRp5e3dtLLraJ4QEr142HPB7n8wibbcYdbyi5XrqOQiIK50pZCqq0Zu SRaEx0ULBZWXuXiuBaOVvUO1Ga2ng0/cbyIiQYXk9DUGO4tafI/Kshddydz91XVdeRgV 5le/9Pf61NElN0xOzf67N3DMNVgxDktYgzVtpT1E+v3+K/n8ITY39cIV0NnNGQ/HuPp+ y5lI4yRVIS1bKiHJWFtFttTUsqoQV939BHJw/8YtXWGxG7EilfgVoXbgCPknm3RuacDx h4KTh8dY5s0wed8s1rPy5RtYV6IQFM7qlDd7BLrRhdpiB1ywQommPSyyOnR+kfo0vQa1 mb4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=q8CTbh+ZncNxVUqKUYUg46BtZv9RoOYRt3vZcqsdmbM=; b=zenNiJIgC0ljFT6LRDAvGKMj7lfhHgbq5xS2sn4k2h+8pglmT2y/QTI7V1rPXrm/ye 8N1MYYO1mTPe8V/yH0zq6pmXQ9dCkzaBzKg/b21Gj9/9mb7Cs5WiIWCoHRmm87WUlCww 1y34ADHuoSJxa2PvgiY0A1XL+RvZi0szam2toLIwF2mMA8g6vSo8IhDO/6cK8zu7AXsq mJQx6+d0VI/2NqyNvAAtfORhIbwJ+j+KsNNOHys+EoCeO8O+OcbbF/79604O/c9n3Uvr hQ8OQKcorFgqCkwgR8NCMm2thy/3deJExRiFuN61sInKA9k42W/PjL0YD8ejLya5fet5 mnlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si17002719pgr.22.2019.06.03.04.59.56; Mon, 03 Jun 2019 05:00:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727158AbfFCKk2 (ORCPT + 99 others); Mon, 3 Jun 2019 06:40:28 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:17659 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726520AbfFCKk2 (ORCPT ); Mon, 3 Jun 2019 06:40:28 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E7154A3224CBF0D18B26; Mon, 3 Jun 2019 18:39:33 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 3 Jun 2019 18:39:29 +0800 Subject: Re: [PATCH v3 3/4] f2fs: Fix accounting for unusable blocks To: Daniel Rosenberg , Jaegeuk Kim , Jonathan Corbet , CC: , , , References: <20190530004906.261170-1-drosen@google.com> <20190530004906.261170-4-drosen@google.com> From: Chao Yu Message-ID: Date: Mon, 3 Jun 2019 18:39:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190530004906.261170-4-drosen@google.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/5/30 8:49, Daniel Rosenberg wrote: > Fixes possible underflows when dealing with unusable blocks. > > Signed-off-by: Daniel Rosenberg > --- > fs/f2fs/f2fs.h | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 9b3d9977cd1ef..a39cc4ffeb4b1 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -1769,8 +1769,12 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, > > if (!__allow_reserved_blocks(sbi, inode, true)) > avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; > - if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) > - avail_user_block_count -= sbi->unusable_block_count; > + if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { > + if (avail_user_block_count > sbi->unusable_block_count) > + avail_user_block_count = 0; avail_user_block_count -= sbi->unusable_block_count; > + else > + avail_user_block_count -= sbi->unusable_block_count; avail_user_block_count = 0; Thanks, > + } > if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { > diff = sbi->total_valid_block_count - avail_user_block_count; > if (diff > *count) > @@ -1970,7 +1974,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, > struct inode *inode, bool is_inode) > { > block_t valid_block_count; > - unsigned int valid_node_count; > + unsigned int valid_node_count, user_block_count; > int err; > > if (is_inode) { > @@ -1997,10 +2001,11 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, > > if (!__allow_reserved_blocks(sbi, inode, false)) > valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; > + user_block_count = sbi->user_block_count; > if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) > - valid_block_count += sbi->unusable_block_count; > + user_block_count -= sbi->unusable_block_count; > > - if (unlikely(valid_block_count > sbi->user_block_count)) { > + if (unlikely(valid_block_count > user_block_count)) { > spin_unlock(&sbi->stat_lock); > goto enospc; > } >