Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp674834ybh; Sun, 12 Jul 2020 20:14:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh0MWTnFBts20u6V0AzzyiK21cSEp0XW1uNiteS1HBoltOuUZWdCyZpInHFGtmhRDSk289 X-Received: by 2002:aa7:cfc8:: with SMTP id r8mr55239002edy.125.1594610053582; Sun, 12 Jul 2020 20:14:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594610053; cv=none; d=google.com; s=arc-20160816; b=rIAK61+9ey098nB9c3SiSECqFMCryECtS3gEa9fWRh5PBsG6jMZFS08xQwAvH+CwoW ZYVnXRXIfuKoIZzxEijvCaf5t9AGcvnWNBJbTN598XR3zySoHdH643lk5p6sIDr+cpjr 2pIVEAZZ29DTgwiAw3RiWDWDGv1WGocZcKZmrTmZHPYte3hEsb4NHmG3Cqh0lwG9FsMc ycYf5+bLTnMGOR3SiC+gjN9wBzuWNYE8u79EFSYHN0cm5nQ+gEgdv0t4qBkZtfTZS3Xp ZZKDBpr0cVrR3M7MxsUfZMNL+3H3diqwp8zrZw9kJdaYmIynKUxMuZOD7GCJIJ+qRMNd A4Pw== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=psxzbrOp99J5mngwlPoMiQAT+alHBEBXUBDoOJ1/0T0=; b=nKNR31Wnu7VO6KVpAHPd+NxqhA/2C6FNPLMcCEK9Em3YX86uUZw13Y+IaRHmtUJs80 DPZE4EGmoNyUfJeqnWLkdLNESoFAHoL9kRpM4eAVsPcs0fq6XF4xk02NbK+1tnt328ow drFeoFWN0iKN+5V4xM6GgCbek67ITYrtSEHVeuivNK0qrWEv2FNTLtNR1MUL/fok08rM ux5uk2tyDTvDi0JWFFHzgVsrpXjC2IJS1w1snU0I3HtzIcQoxUsO5sa/dtSP51Bi5GnW 8gw4NzMsVHeGBO+itepPVf/zS9Qeru5r5+8qQce5Io/GinJw42ejHBCKgnP2KnrR7DKQ NfVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bMkxg68p; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si8784445eds.485.2020.07.12.20.13.49; Sun, 12 Jul 2020 20:14:13 -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=@gmail.com header.s=20161025 header.b=bMkxg68p; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbgGMDNC (ORCPT + 99 others); Sun, 12 Jul 2020 23:13:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbgGMDNB (ORCPT ); Sun, 12 Jul 2020 23:13:01 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E18DC061794 for ; Sun, 12 Jul 2020 20:13:01 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id k4so4876778pld.12 for ; Sun, 12 Jul 2020 20:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=psxzbrOp99J5mngwlPoMiQAT+alHBEBXUBDoOJ1/0T0=; b=bMkxg68pIh+RvX2AC4XXKe6pe1QOex4aB1n7ujCqFRZd69+OnuEEgrE4tbSiQHzr2w HUONe3Rz9kqrSbjvW1EW7ygCDQ/aWO1wdWhs3MyPk8wX/x/ejLAIA2GGvf5BPpEdxpUK xboFHzonjwMPK3n9xEddAHBnE6DMrvun0X5PBgA59sAi87sum89ri+yl19ri98UFYIrz RhmOZAmNgecT2cwN+1+yJWn5QLeyeeBvAe85s+moYqIXda9vTBgiueAIHIYf70nqgLGB ABFcbyIbOa6l2P83EU6Ak68QAD2KGHrHF/zaKiPrPHqgGBnSirLubl0ZLyJMl4w+YAVF 4oXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=psxzbrOp99J5mngwlPoMiQAT+alHBEBXUBDoOJ1/0T0=; b=mwiNdhgBBwyedhQfQ82Y6xVOJIC/22/WOYAQcAoQWshxC9T4dVEoRMDrMWK40OcFWg CYsFgksl3D6+at5QOvTH6a/AUYY5BHi+CKRWhx0a72t84O5JbZ0XPi3Ugmkxppbsjm3P /FiS8bil4EUGkz6oGFAKpt+Nuifr8Vqe5yc9jkxoc/cAAp/mRZoqKp+RnZk5qPeNpkGN 4VzgADtozoBldktjBsjtU9zUGJuhzYlgxDmqGR88jdhLbyFfpzx1giPE0OI2MZbZuRv4 oX3bPtydkr3heSLibD1Pu7JefAlgM8HsdlvH1F3RE+kkolWg5LoyKpMTrVN7V14DoYa+ aMDQ== X-Gm-Message-State: AOAM533pi3eBplZJAzEEymbPJaosWfieLtV3oyA1BZfXh+3J/LzJiNbS b5Ddr08fHD9IJc513YuAd52wUmCy X-Received: by 2002:a17:902:b905:: with SMTP id bf5mr37221828plb.250.1594609980408; Sun, 12 Jul 2020 20:13:00 -0700 (PDT) Received: from daehojeong1.seo.corp.google.com ([172.30.115.29]) by smtp.gmail.com with ESMTPSA id cl17sm12635508pjb.50.2020.07.12.20.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jul 2020 20:12:59 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH v2] f2fs: change the way of handling range.len in F2FS_IOC_SEC_TRIM_FILE Date: Mon, 13 Jul 2020 12:12:52 +0900 Message-Id: <20200713031252.3873546-1-daeho43@gmail.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 secure trim the whole blocks starting from range.start regardless of i_size. 2. If the end of the range passes over the end of file, it means until the end of file (i_size). 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 --- Changes in v2: - Changed -1 range.len option to mean the whole blocks starting from range.start regardless of i_size --- fs/f2fs/file.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 368c80f8e2a1..2485841e3b2d 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3792,7 +3792,7 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) pgoff_t index, pg_end; block_t prev_block = 0, len = 0; loff_t end_addr; - bool to_end; + bool to_end = false; int ret = 0; if (!(filp->f_mode & FMODE_WRITE)) @@ -3813,23 +3813,23 @@ 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; + if (inode->i_size - range.start > range.len) { + end_addr = range.start + range.len; + } else { + end_addr = range.len == (u64)-1 ? + sbi->sb->s_maxbytes : inode->i_size; + to_end = true; } - end_addr = range.start + range.len; - to_end = (end_addr == inode->i_size); if (!IS_ALIGNED(range.start, F2FS_BLKSIZE) || (!to_end && !IS_ALIGNED(end_addr, F2FS_BLKSIZE))) { ret = -EINVAL; @@ -3846,7 +3846,8 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); down_write(&F2FS_I(inode)->i_mmap_sem); - ret = filemap_write_and_wait_range(mapping, range.start, end_addr - 1); + ret = filemap_write_and_wait_range(mapping, range.start, + to_end ? LLONG_MAX : end_addr - 1); if (ret) goto out; -- 2.27.0.383.g050319c2ae-goog