From patchwork Mon Nov 4 01:56:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiguo Niu X-Patchwork-Id: 13860784 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9BB04D1119A for ; Mon, 4 Nov 2024 01:57:26 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1t7mLN-00009G-Lm; Mon, 04 Nov 2024 01:57:25 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1t7mLM-00008q-Bf for linux-f2fs-devel@lists.sourceforge.net; Mon, 04 Nov 2024 01:57:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject: CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=EsdreCfoE9LgMfGejzqBICVW7CgGMNl3u6P+nKUvx+Q=; b=er681qATwABGayqozWbUL5hjQs 8sOaqUVbDfBC2DHdlFRyf2vvSWoceqlQLFA0/JotdkA+/40feKtRfexnze+fSwYfVw2sWFSNjQsob hQ9PL06+AMw2TLIE/TKal9426YZu6qzNOh4+VbwIvOErFFNXQ/cxZryq3wV5Gvr1SdEs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=EsdreCfoE9LgMfGejzqBICVW7CgGMNl3u6P+nKUvx+Q=; b=C pDyXi6mhyzTlEH2Gpr0xYsPq4ZVscuJfD/Nch7wQwzqDLKhfdbCEUwufn/MKBhF7t956H2gFwxsJ8 y5bkUpfogrJNxrGM46EWIIuTiUJQcgsuHFeoareoMKuC6rXa+JRBKZ/YqgepTo6kzwKUdecfDWJVE ZzpqAeoez89KAXM8=; Received: from mx1.unisoc.com ([222.66.158.135] helo=SHSQR01.spreadtrum.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1t7mLJ-0008G9-U0 for linux-f2fs-devel@lists.sourceforge.net; Mon, 04 Nov 2024 01:57:24 +0000 Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 4A41uebh050500; Mon, 4 Nov 2024 09:56:40 +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 4XhZLc4QLHz2KKmRb; Mon, 4 Nov 2024 09:55:52 +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; Mon, 4 Nov 2024 09:56:37 +0800 From: Zhiguo Niu To: , Date: Mon, 4 Nov 2024 09:56:12 +0800 Message-ID: <1730685372-2995-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.87] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 4A41uebh050500 X-Headers-End: 1t7mLJ-0008G9-U0 Subject: [f2fs-dev] [PATCH V2] f2fs: fix to adjust appropriate length for fiemap X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ke.wang@unisoc.com, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, zhiguo.niu@unisoc.com, Hao_hao.Wang@unisoc.com Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net If user give a file size as "length" parameter for fiemap operations, but if this size is non-block size aligned, it will show 2 segments fiemap results even this whole file is contiguous on disk, such as the following results: ./f2fs_io fiemap 0 19034 ylog/analyzer.py Fiemap: offset = 0 len = 19034 logical addr. physical addr. length flags 0 0000000000000000 0000000020baa000 0000000000004000 00001000 1 0000000000004000 0000000020bae000 0000000000001000 00001001 after this patch: ./f2fs_io fiemap 0 19034 ylog/analyzer.py Fiemap: offset = 0 len = 19034 logical addr. physical addr. length flags 0 0000000000000000 00000000315f3000 0000000000005000 00001001 Signed-off-by: Zhiguo Niu Reported-by: Zhiguo Niu Signed-off-by: Chao Yu --- V2: correct commit msg according to Chao's questions f2fs_io has been modified for testing, the length for fiemap is real file size, not block number --- fs/f2fs/data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 306b86b0..9fc229d 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1966,8 +1966,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto out; } - if (bytes_to_blks(inode, len) == 0) - len = blks_to_bytes(inode, 1); + if (len & (blks_to_bytes(inode, 1) - 1)) + len = round_up(len, blks_to_bytes(inode, 1)); start_blk = bytes_to_blks(inode, start); last_blk = bytes_to_blks(inode, start + len - 1);