Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp308204ybt; Thu, 9 Jul 2020 23:48:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0/Wh69FJrph70PGshZ7uz++pFFFVGdmgK56bGPZv4lhIOo+ypUZd6nJzwT5Ibr82lXpwJ X-Received: by 2002:a17:907:9484:: with SMTP id dm4mr62860788ejc.56.1594363723467; Thu, 09 Jul 2020 23:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594363723; cv=none; d=google.com; s=arc-20160816; b=pnZPUNaa1eAW7pc5M1QeypFTdIKOSzu3iXgt1s8ubRyYs+EkgYO7ucXFl/f/dZmcBw 7D8Zd8VNwT7PMuXykKfxsSpCylXiAK6nreoXDisIHZ+VHASS83gwPoRR9tKWYQJiYn++ TB/xTCb2tS2e3emfoHrrCF5L4lg6mfmr4Q53eL8u0Y6FoTwoLG0JFsenWgt7rLhyx8gV qxRrPWpJKSYpjZsV8LRkwUHer0N57HeJeANd+ANqOs39bEDg4hoA+FB14JimdBBiXCD1 oSrC/jIBKsCEC1mgFlYgvgmO9bPscGLvMIzFY6yygaVmXL5h8+nMXlE3XCTUHQ6e5M7I dzgQ== 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=mhrgJ3FRiZjO0xkSqdB1rYc0g6soW7SuqCMENCfj2aQ=; b=womHr0FX6/UjXTh1WEal6k0U6JMw2g2ZpJl48vR7gEZq1fp5EBo1VoqG0imTjz5IYY m5gX+k4Z/MQeD0U9LGXi96w3Z6lHwAt24XiEXZie6IfiOY4Geawaysa3zxZVMfuGixKg DSKLpr7aybTSCDNJfYwzfmunZHLgCgS3+QU7yGl4ndtp3YUJndIKsYBGYA/2BCpvONmj R6Wf31eiVoe9bLq0nj1cG170ZUIQu3vUTgUT2X1QDZ2Ex5Z7CXE2ol4YGovQhB3JsmGb FJwAFK5yCZ+6GFvtp0iGPqmNkDqqpSx6dQ+Y9FDxH6VyPWH1M7erfxpK7uy1VdZG1nxq qc5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2GlAy5uj; 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 dg2si3879514edb.326.2020.07.09.23.48.20; Thu, 09 Jul 2020 23:48:43 -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=2GlAy5uj; 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 S1727919AbgGJGqG (ORCPT + 99 others); Fri, 10 Jul 2020 02:46:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:47440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725943AbgGJGqF (ORCPT ); Fri, 10 Jul 2020 02:46:05 -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 308D5207DF; Fri, 10 Jul 2020 06:46:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594363564; bh=4hA4Pkh1IVhGVJIJ1bNCGgYAfcOIFM+f/AjmG0yu4gI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=2GlAy5uj37xFyGWJcs4dYwhUtXTbe2t7VOc5/uc3lVnlVUJDEtLQXxt2w3duVxseQ yPN0SMxN19fjUFvr44nNS52tn/9/qEv8HC9AL2peeWQG+V9VfvL9MNhmXpQIUneVvk yIBEWUTO3xZURAsYSaU0H7M5Tx60V+eaXFduug7Y= Date: Thu, 9 Jul 2020 23:46:03 -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: <20200710064603.GA1656368@google.com> References: <20200710021505.2405872-1-daeho43@gmail.com> <20200710030246.GA545837@google.com> <62c9dd7a-5d18-8bb6-8e43-c055fcff51cc@huawei.com> <20200710033100.GE545837@google.com> <20200710035215.GI545837@google.com> <34cad197-75eb-d7c2-4465-261d5debfd3b@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <34cad197-75eb-d7c2-4465-261d5debfd3b@huawei.com> 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:52, Jaegeuk Kim wrote: > > 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. > > The path won't, cp only persists reserved block in dnode rather than written > data block in segment, because data will be copied to page cache after write_begin. Ah, you're talking about data validity, while I was doing block allocation in this case. In either cases, I'd say secure_trim needs to trim whatever data in valid block *address*. > > I think truncation path could as Daeho said: > > 1. truncate -> i_size update however blocks wasn't truncated yet -> checkpoint -> recovery > 2. truncate failed -> i_size update however partial blocks was truncated -> fsync > > > > >> > >>> > >>>> > >>>> 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 > >>>>> . > >>>>> > >>> . > >>> > > . > >