Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp226597ybt; Thu, 9 Jul 2020 20:52:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzq8RCa4Ep6kaoVwWfLxfX9AJ06yMdZxu/3dOh1mgmU41CNBp+eCgv8RrF3C0hRGqswIk+R X-Received: by 2002:a05:6402:b0d:: with SMTP id bm13mr1753987edb.301.1594353169322; Thu, 09 Jul 2020 20:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594353169; cv=none; d=google.com; s=arc-20160816; b=x49YtMPR9oZ9nEW2AHQlhx4YxqY2YaxElWqo0ix7soFRWKGkfa0LxOpZt6lYkb2PLA NRhisRy2tPbBxIrH5U4oYueCQN46pjDTJaAoRZltbD601UYrQmI6g+wYQSCXSbEacg+l UQxSbn8cadeaEIDUPsWTV0EY3x+yggfHtob06hRDOM4spk7lDVgCTkPzESdOEnvp+R25 r/4LcXQDeTvTVSUAAGQmGPdPvRAbSHGYe3aRiR4G6knLYkSPhOsYRWSAAbrvX6G49/Ij 3LEwCe1Gta+fMJ0wlRDoVCXR364zGXHcXDEaCaImonIjTf6vnVMFe9g9RlkQnhdWSB9g bTZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=7kOPHG5CsJz/WkTAWCEDGx6alIrJJYvgLulhhg/HZLg=; b=nbTPy/3ffxZChAqp4jjO5p4Z/FWtiugZiz3i1W4r7jSa5q8U1wQ9JbM9GBk0aEu4yD QQ+nvO0J9UZh4wow9s5Sjq70PwK7XCsqun7jb7YA1aQWDCDEowZq/XEkNXwwIQWEkQVa h/cUgVVWpsgBHYeW9GZEPIWqOGYhAJWBF4FOPlyJ2ETLf4BzZqoeap0nwjAfesyPLF7J iyC02gFRLi/y+CI0a43yZrSeIMtdXk3s/neYN1jf2CJrn7H+nHVBcS0b8g5T2SGsiKQg WAKpxMNX5lkQQF8Mbp4DIw+Qs3w1ZRPYLtCZp3nZQI1Ytgd6dVDu7M7XXNMXVxlw6FmH SluQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LRUJV3hP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id m8si3074145ejq.294.2020.07.09.20.52.26; Thu, 09 Jul 2020 20:52:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LRUJV3hP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726832AbgGJDwR (ORCPT + 99 others); Thu, 9 Jul 2020 23:52:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:59494 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726509AbgGJDwR (ORCPT ); Thu, 9 Jul 2020 23:52:17 -0400 Received: from localhost (unknown [104.132.1.66]) (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 3EEC12072E; Fri, 10 Jul 2020 03:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594353136; bh=xLvKF2sWDcGdNloTJLpeuSq/KhHOkOtOuMlIFvINFr8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LRUJV3hPsaC5eC2jDa4m2VO6wXQ533lEQU80iGsTlYYbaqYNMSvP6brBtcbxFuhcc x0NOGXCxuW0R+O8F9fOMVCP0vV94um/7aBKonAWbgBj6g62PIkGQRPtWXSMB9TVlkv DSv6R3fqXapSYwfxwYflnXu740Ivry6+HBR3vTF8= Date: Thu, 9 Jul 2020 20:52:15 -0700 From: Jaegeuk Kim To: Chao Yu Cc: Daeho Jeong , Daeho Jeong , kernel-team@android.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH] f2fs: change the way of handling range.len in F2FS_IOC_SEC_TRIM_FILE Message-ID: <20200710035215.GI545837@google.com> References: <20200710021505.2405872-1-daeho43@gmail.com> <20200710030246.GA545837@google.com> <62c9dd7a-5d18-8bb6-8e43-c055fcff51cc@huawei.com> <20200710033100.GE545837@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/10, Chao Yu wrote: > On 2020/7/10 11:31, Jaegeuk Kim wrote: > > On 07/10, Chao Yu wrote: > >> On 2020/7/10 11:02, Jaegeuk Kim wrote: > >>> On 07/10, Daeho Jeong wrote: > >>>> From: Daeho Jeong > >>>> > >>>> Changed the way of handling range.len of F2FS_IOC_SEC_TRIM_FILE. > >>>> 1. Added -1 value support for range.len to signify the end of file. > >>>> 2. If the end of the range passes over the end of file, it means until > >>>> the end of file. > >>>> 3. ignored the case of that range.len is zero to prevent the function > >>>> from making end_addr zero and triggering different behaviour of > >>>> the function. > >>>> > >>>> Signed-off-by: Daeho Jeong > >>>> --- > >>>> fs/f2fs/file.c | 16 +++++++--------- > >>>> 1 file changed, 7 insertions(+), 9 deletions(-) > >>>> > >>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > >>>> index 368c80f8e2a1..1c4601f99326 100644 > >>>> --- a/fs/f2fs/file.c > >>>> +++ b/fs/f2fs/file.c > >>>> @@ -3813,21 +3813,19 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) > >>>> file_start_write(filp); > >>>> inode_lock(inode); > >>>> > >>>> - if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode)) { > >>>> + if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) || > >>>> + range.start >= inode->i_size) { > >>>> ret = -EINVAL; > >>>> goto err; > >>>> } > >>>> > >>>> - if (range.start >= inode->i_size) { > >>>> - ret = -EINVAL; > >>>> + if (range.len == 0) > >>>> goto err; > >>>> - } > >>>> > >>>> - if (inode->i_size - range.start < range.len) { > >>>> - ret = -E2BIG; > >>>> - goto err; > >>>> - } > >>>> - end_addr = range.start + range.len; > >>>> + if (range.len == (u64)-1 || inode->i_size - range.start < range.len) > >>>> + end_addr = inode->i_size; > >> > >> We can remove 'range.len == (u64)-1' condition since later condition can cover > >> this? > >> > >>> > >>> Hmm, what if there are blocks beyond i_size? Do we need to check i_blocks for > >> > >> The blocks beyond i_size will never be written, there won't be any valid message > >> there, so we don't need to worry about that. > > > > I don't think we have a way to guarantee the order of i_size and block > > allocation in f2fs. See f2fs_write_begin and f2fs_write_end. > > However, write_begin & write_end are covered by inode_lock, it could not be > racy with inode size check in f2fs_sec_trim_file() as it hold inode_lock as > well? Like Daeho said, write_begin -> checkpoint -> power-cut can give bigger i_blocks than i_size. > > > > >> > >> Thanks, > >> > >>> ending criteria? > >>> > >>>> + else > >>>> + end_addr = range.start + range.len; > >>>> > >>>> to_end = (end_addr == inode->i_size); > >>>> if (!IS_ALIGNED(range.start, F2FS_BLKSIZE) || > >>>> -- > >>>> 2.27.0.383.g050319c2ae-goog > >>>> > >>>> > >>>> > >>>> _______________________________________________ > >>>> Linux-f2fs-devel mailing list > >>>> Linux-f2fs-devel@lists.sourceforge.net > >>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > >>> > >>> > >>> _______________________________________________ > >>> Linux-f2fs-devel mailing list > >>> Linux-f2fs-devel@lists.sourceforge.net > >>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel > >>> . > >>> > > . > >