Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4579523ybi; Mon, 3 Jun 2019 13:28:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUelyeLMa7uxE6q7OwaoI6tmoB0JZkDCPQna5ChOAruOLXSpHqxUXNay4YX5/WJHuw4rX6 X-Received: by 2002:a17:902:5c2:: with SMTP id f60mr32310123plf.61.1559593730678; Mon, 03 Jun 2019 13:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559593730; cv=none; d=google.com; s=arc-20160816; b=sAwwyeBkYH8FZx74KZ7KNdCk/ayIAK6c3w/uyoyYfhhQSa+3acHW7iMhXFIZL2gyWM AzakGlT9tb5d03tg/t89wdFHrenyNiT1/8sPA9xxd8ZqKw471aLAo3EcAB9xLVDx+OtU 5N5gNgt/7UiHCGpIlwzcAncgJp6TEujOVjDeJH3yzTtuPCfkyuCoYdzz8NioWS+tVNRL iX23dUBbqWpp2hcyMl3tx8RAgIt3pZlxqX6WAPmv6fOnB8X9UGj+Zx7H3U3ltimDpxkt UDNGzjsKQfEpaBGuKfw7p3MNIQhJ9Hgs2qXztJJL5dIeXsnS1uFtOP72z+Jpb2DZ95YI J+GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5q7OaVloZhlB3dEsAB1UmVhZiGElyZ/sQ9zK26UP6KM=; b=oDtAilhezVL36ghXZaUIy01IaPnxqwq/jwSONgiqZ5mTHCsRwjSzszKd0RIEyzX6xh yqWzVKHdSg74OSDOnBJFAuUv0WXTR4rjUZhpbswi4+PR4y/ernRwlTqvjxANC9FAEFkO B34Z69aJwP12dlEZrqeWfYO64Vfoo/Yl0cOe7gvoBbnqSr5yoqbsF+US8UVK2RCSY8AI BlXXotEj0c3KkNWUp6/WljfqGysBXyq9ImiRLbzmVyHEm1KpXIJws5BB+dFDih0nTw3z +tB3lFWWYaIISZWUxYpeiSoEWONb5j2NGHd3m6xUTmRmXbTp09sVVcGPilzITuM1m11b MK/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zSYE0C9l; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si4997482pfx.243.2019.06.03.13.28.34; Mon, 03 Jun 2019 13:28:50 -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; dkim=pass header.i=@kernel.org header.s=default header.b=zSYE0C9l; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726303AbfFCU0c (ORCPT + 99 others); Mon, 3 Jun 2019 16:26:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:59602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726055AbfFCU0c (ORCPT ); Mon, 3 Jun 2019 16:26:32 -0400 Received: from localhost (unknown [104.132.1.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 551A626E5D; Mon, 3 Jun 2019 20:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559593591; bh=v9calqM6PHGdBj4mALXAqgtFc8xx6nsYR8rF3Gxiqq0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=zSYE0C9l3qM676qHbrmOp5NvQJ7w+P/sokWBCGTmaeHzN6QtS0eN38H8ncd3DClcz DjJALXzTzp4c2qWSFZWGgUjssI7sur8d70+9u1UUURc9nWf9sh2sWM8WHjjM+HwVYQ n/S63kQSg7IiUbcB3uM+zCD9Gf6KamrIGCdJ016w= Date: Mon, 3 Jun 2019 13:26:30 -0700 From: Jaegeuk Kim To: Chao Yu Cc: Daniel Rosenberg , Jonathan Corbet , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 3/4] f2fs: Fix accounting for unusable blocks Message-ID: <20190603202630.GB34729@jaegeuk-macbookpro.roam.corp.google.com> References: <20190530004906.261170-1-drosen@google.com> <20190530004906.261170-4-drosen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/03, Chao Yu wrote: > 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; > I fixed this. Thanks, > 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; > > } > >