Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp163084lqe; Wed, 27 Mar 2024 01:56:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVwogSzejKQgTfRx+yQk15qXZjxRH5Af08WbtKjyxxe1niQCuhaESyZ74uRa+6I08lE2eOnP58PULk/iXgyFzrjD/YLqZukMcHr/6xdsw== X-Google-Smtp-Source: AGHT+IELIyrmnu4IJQf6VClao8ZnnGPapNl5c3Yk2KfHjwagrkC916v6tWNStYjvcT/Q10N9n1sm X-Received: by 2002:a50:d685:0:b0:568:9ba8:8f1a with SMTP id r5-20020a50d685000000b005689ba88f1amr1347505edi.7.1711529763420; Wed, 27 Mar 2024 01:56:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711529763; cv=pass; d=google.com; s=arc-20160816; b=qGh2DOg/IsIQeqhGYuKciWivUY6OyfKwHAhKsll/66Zow9+3docauvP+DsXgsJbZv0 9O7AE5solY1un9hjZZY0COzu1TM5mGA3p3JVpOVZk90DtWRPu7ZDOHPsyQF39GL/acDc g7HlV/WjVTMNMPF6og33Ir2rHm6Y9XM0ub6ltAC4ETixmyrMqIHhedoUD+14Nq5u18I3 v2KvQ3gaEOZrfYDLh4FbjG1shgH0z33L/Jpd5nz375GrFo3CQfhOWzL0BevdSp+kcpHz Ol/nRAJoYys0Ks2CerLqrohOZeNFTX1kPuJCFV0Kek7cTQFbmb7gWD+uAUUdcBw7aGOC HMgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=YdtKCLnPzFGUm/lK9M7TwZ51+33mb1qxQgEIbr6UDWk=; fh=r88ULmOhzmh3DE8RgcUXK+PF5Q+3czCYkx5yGhGfkR0=; b=F/C2HyYPrimvq3knNZdyTiFh3+n7KGdQPLADSTjM+Q9HilYN30vxdGSLwScUKbxbsR v+C69B1mpsKBT44iFh6zw8Iz01Qo2rCTvADm7IlCWYU1SJ4fDyKdp5Q5888PXX7VUrhx QWErQgNAao0MLPMYsrVU5sVCZbBb5BEyTcmWpisL0myBc7QhXDjAP4xf7zAjVfDmF72Z HzOmJlW6uX/pjBwAOsn5JxEeqRGw8wXSi2ueQvRbFaB5Pgqg/Ozb8nzgWtwVON4ionT9 Aw6YCnVCckVo3GnEHtb0D8Gg+uS5fmjV1JPpYYX+JHNUf4oMq9IuiAg6RlIHDmpYVmdb 9DXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-120581-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120581-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ev9-20020a056402540900b0056c05442c16si3689487edb.670.2024.03.27.01.56.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 01:56:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120581-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-120581-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120581-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 287FE1F2E265 for ; Wed, 27 Mar 2024 08:56:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F2DE3B18D; Wed, 27 Mar 2024 08:54:38 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09C2F4DA11 for ; Wed, 27 Mar 2024 08:54:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529678; cv=none; b=uxMykUqZtN2kyrJD4MXHYJEdH765Qk2ahWnH6E6lLM9WDv8eW8zrnYeYdQmYTl/j3iAvJeVXo73I9koZVOig3AXJ6bTelhj1Uz6TfDu3rUToh7sCYKBEHX7NVrA/kNICc9lnSnMMck79bN+M+/mrpW+bEKn5uoW5i+JB9Ote6OM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711529678; c=relaxed/simple; bh=8qeOhLgDp4B6NSdcFUTzjGxs/APrSCobmWoiOp9La28=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Gsx7MKawyPs1PtQ+nX37c9H0YuHJ0bv4kDFhjZ7ilIZwCAAVGywzmhlCyq2m/i1PMj271QeupD66BTjTMSSZeQSbTQwHYHbA6G7dapuGDrXfwIxelEAfAo+0fxyZeBK7rwqEUJw75++wuSmMo89l9VSdwFTnNjRaEpVoPr3YL/A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 42R8rtpk037904; Wed, 27 Mar 2024 16:53:55 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4V4L5S56V1z2Lt7c3; Wed, 27 Mar 2024 16:52:12 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 27 Mar 2024 16:53:53 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH V3] f2fs: fix to adjust appropirate defragment pg_end Date: Wed, 27 Mar 2024 16:53:40 +0800 Message-ID: <1711529620-17576-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 42R8rtpk037904 A length that exceeds the real size of the inode may be specified from user, although these out-of-range areas are not mapped, but they still need to be check in while loop, which is unnecessary. Signed-off-by: Zhiguo Niu --- v3: adjust code positions according to Chao's suggestions v2: check i_size within inode lock according to Chao's suggestions --- --- fs/f2fs/file.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index bc190d5..9908017 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2627,12 +2627,13 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, bool fragmented = false; int err; - pg_start = range->start >> PAGE_SHIFT; - pg_end = (range->start + range->len) >> PAGE_SHIFT; - f2fs_balance_fs(sbi, true); inode_lock(inode); + pg_start = range->start >> PAGE_SHIFT; + pg_end = min_t(pgoff_t, + (range->start + range->len) >> PAGE_SHIFT, + DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE)); if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { err = -EINVAL; @@ -2647,8 +2648,9 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, } /* writeback all dirty pages in the range */ - err = filemap_write_and_wait_range(inode->i_mapping, range->start, - range->start + range->len - 1); + err = filemap_write_and_wait_range(inode->i_mapping, + pg_start << PAGE_SHIFT, + pg_end << PAGE_SHIFT - 1); if (err) goto out; -- 1.9.1