Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3218384pxv; Sun, 25 Jul 2021 21:20:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+IXcRoY48ZmF3kspw59N27smcaYszQjS2YZtrOnmxI/vDmRAml7citzmpKD1fXN2LBc/X X-Received: by 2002:a92:cc85:: with SMTP id x5mr12262942ilo.266.1627273219162; Sun, 25 Jul 2021 21:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627273219; cv=none; d=google.com; s=arc-20160816; b=QiwBBcgS1/ab2Yj1qvYLJr+GR75MUdb9XBUIAPGRb/Ps4uHXwXVQJt937VFbvO5gjK KN4i0nqsLappbvwVpSauyufAwU0eECCaGN5wEmbphnmnhiBFhFJHzmRNNj//im2S/Vof 6isJGDZoQL6GsqO7GiE3FWKuKPoLpCuwjzHNOGk0irIPQfySarUafsZ4MT63yZdkav+o CCLCVaHJ2pq32SQTJh8sGfu1nU3RTs9tUELjzcf+iTAv0vIygo6wvDai3zRhiHdjLh8V h0OjNltqNj77sjW1tD2uiGFfW5UPHrYeiLnkvKVn1p/8mefYIQhdSkTXyFb1MfumKmto e0eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=2thOxj6ctqmCSeGKTO0PklZgYjLXVrYMprKtsyIwFdQ=; b=jDo72pJh668tfkey58W7w+M5Pfgktb2i+vPUTzzgAIskM/ad9RxDwRz2U1hzRSFXCW lqsLeV7UmAXURJOp9LG3g04xPb+RbmCcTTHJsGyBcIh3vzvwjKAAXn0c1RytchwqYWLP yShIB5vCgxRnjbtbeiGhdVvUI/pWZTzOuv/PLaxaxUpTMlTH6ymSJdFKcM4WEws51uFz HS9FBRlQty9I0K0UeZPhD/r10JeRjDHHS2ffecbMdPmYBdPOyACL7cFvGD5L7iP/a1Fj JrQxqzv1Z1vg3pBQVEx11q8s0yhZpijkbWQrcLhmeOengujCbSlOV7QN+UXvZnCQZ43t FvFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="E6YnqwG/"; 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 u15si45785868iot.89.2021.07.25.21.20.08; Sun, 25 Jul 2021 21:20:19 -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="E6YnqwG/"; 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 S231219AbhGZDh5 (ORCPT + 99 others); Sun, 25 Jul 2021 23:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230321AbhGZDhz (ORCPT ); Sun, 25 Jul 2021 23:37:55 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91309C061757 for ; Sun, 25 Jul 2021 21:18:24 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id m2-20020a17090a71c2b0290175cf22899cso12490282pjs.2 for ; Sun, 25 Jul 2021 21:18:24 -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=2thOxj6ctqmCSeGKTO0PklZgYjLXVrYMprKtsyIwFdQ=; b=E6YnqwG/l7j6GsLDG5sI85c1f8k6puuOIXFTKw6dDIyNb62iLh9Z33ha1+QyWqGuP/ kKX4DRToWTQLcXCA2vST3jgzUTJe1lfUTYduJzTCKGokXH9RmW0LVG8Weaz4FO3zBE5B 3gxFQ/Zuv0Ig8h4hcKdqNEnZgMIEX6ytdTPEXIZC2ysnIcjzbMn/Jl1X+IZYgNB3ZOMZ LOokuS9jPRZ+8bCGwQhxeeCMpn93OqBherjNZgmwWXuK6MoauqGmVICkZmqSR+4lc1Xd AbF+hglHjbEwEtf5rI8/6KuKK5lCOTifjKVjSM7E3YxOwc92kqzDqEhOPG6igezBArQG IczA== 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=2thOxj6ctqmCSeGKTO0PklZgYjLXVrYMprKtsyIwFdQ=; b=s5AgtEFyvAo1l96eNk2U1Vnzvsucc2b1hDFaFyFdfyaDmpSp4CB1CzZ6aB1M2exFCP Hs7iGM0Bek5SwgrssqcFpeGA7sluvc1NvdcoWnDDaWVHJXKQ+Ik+85dQjEMV/EivoIix egL/5wLBn1vi2NFvchEBytq7Wm4z3oJMN4F77Oz5b157Fc6coNx156C6Iz0VJKS+x2/I 8SHoEkzPqH4Lgtgg/pGVIi5Psv21gawVbi19OprVNcjFgClOc/OL6O0QDGZOUZzZOEY1 C8xs9GeCWQiHEqidffNDl59entu2Qn5d2V9b3BDXaooI6PUZDPMh4Qji8eUTZi7Vvy8w GDGg== X-Gm-Message-State: AOAM531t+D5Xxa/pEyuCFBtwH18jg51LnuES/AhVSTyEtJn3Dmld6cPp ygld4P5BFm9OmTgGph1DH+QSRy47InY= X-Received: by 2002:a17:90b:1194:: with SMTP id gk20mr24693980pjb.181.1627273103758; Sun, 25 Jul 2021 21:18:23 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2620:15c:211:201:cb45:e631:40f9:6a6]) by smtp.gmail.com with ESMTPSA id d2sm12147861pjd.24.2021.07.25.21.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jul 2021 21:18:23 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong , Eric Biggers Subject: [PATCH v4] f2fs: change fiemap way in printing compression chunk Date: Sun, 25 Jul 2021 21:18:19 -0700 Message-Id: <20210726041819.2059593-1-daeho43@gmail.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daeho Jeong When we print out a discontinuous compression chunk, it shows like a continuous chunk now. To show it more correctly, I've changed the way of printing fiemap info like below. Plus, eliminated NEW_ADDR(-1) in fiemap info, since it is not in fiemap user api manual. Let's assume 16KB compression cluster. Logical Physical Length Flags 0: 0000000000000000 00000002c091f000 0000000000004000 1008 1: 0000000000004000 00000002c0920000 0000000000004000 1008 ... 9: 0000000000034000 0000000f8c623000 0000000000004000 1008 10: 0000000000038000 000000101a6eb000 0000000000004000 1008 0: 0000000000000000 00000002c091f000 0000000000004000 1008 1: 0000000000004000 00000002c0920000 0000000000004000 1008 ... 9: 0000000000034000 0000000f8c623000 0000000000001000 1008 10: 0000000000035000 000000101a6ea000 0000000000003000 1008 11: 0000000000038000 000000101a6eb000 0000000000002000 1008 12: 000000000003a000 00000002c3544000 0000000000002000 1008 Flags 0x1000 => FIEMAP_EXTENT_MERGED 0x0008 => FIEMAP_EXTENT_ENCODED Signed-off-by: Daeho Jeong Tested-by: Eric Biggers --- v4: initialized count_in_cluster v3: fix the missing last extent flag issue v2: changed the print format --- fs/f2fs/data.c | 75 ++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 3a01a1b50104..1a716c3b5457 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1843,8 +1843,9 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 logical = 0, phys = 0, size = 0; u32 flags = 0; int ret = 0; - bool compr_cluster = false; + bool compr_cluster = false, compr_appended; unsigned int cluster_size = F2FS_I(inode)->i_cluster_size; + unsigned int count_in_cluster = 0; loff_t maxbytes; if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) { @@ -1892,15 +1893,17 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, map.m_next_pgofs = &next_pgofs; map.m_seg_type = NO_CHECK_TYPE; - if (compr_cluster) - map.m_len = cluster_size - 1; + if (compr_cluster) { + map.m_lblk += 1; + map.m_len = cluster_size - count_in_cluster; + } ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP); if (ret) goto out; /* HOLE */ - if (!(map.m_flags & F2FS_MAP_FLAGS)) { + if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) { start_blk = next_pgofs; if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode, @@ -1910,6 +1913,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, flags |= FIEMAP_EXTENT_LAST; } + compr_appended = false; + /* In a case of compressed cluster, append this to the last extent */ + if (compr_cluster && ((map.m_flags & F2FS_MAP_UNWRITTEN) || + !(map.m_flags & F2FS_MAP_FLAGS))) { + compr_appended = true; + goto skip_fill; + } + if (size) { flags |= FIEMAP_EXTENT_MERGED; if (IS_ENCRYPTED(inode)) @@ -1926,38 +1937,36 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, if (start_blk > last_blk) goto out; - if (compr_cluster) { - compr_cluster = false; - - - logical = blks_to_bytes(inode, start_blk - 1); - phys = blks_to_bytes(inode, map.m_pblk); - size = blks_to_bytes(inode, cluster_size); - - flags |= FIEMAP_EXTENT_ENCODED; - - start_blk += cluster_size - 1; - - if (start_blk > last_blk) - goto out; - - goto prep_next; - } - +skip_fill: if (map.m_pblk == COMPRESS_ADDR) { compr_cluster = true; - start_blk++; - goto prep_next; - } - - logical = blks_to_bytes(inode, start_blk); - phys = blks_to_bytes(inode, map.m_pblk); - size = blks_to_bytes(inode, map.m_len); - flags = 0; - if (map.m_flags & F2FS_MAP_UNWRITTEN) - flags = FIEMAP_EXTENT_UNWRITTEN; + count_in_cluster = 1; + } else if (compr_appended) { + unsigned int appended_blks = cluster_size - + count_in_cluster + 1; + size += blks_to_bytes(inode, appended_blks); + start_blk += appended_blks; + compr_cluster = false; + } else { + logical = blks_to_bytes(inode, start_blk); + phys = __is_valid_data_blkaddr(map.m_pblk) ? + blks_to_bytes(inode, map.m_pblk) : 0; + size = blks_to_bytes(inode, map.m_len); + flags = 0; + + if (compr_cluster) { + flags = FIEMAP_EXTENT_ENCODED; + count_in_cluster += map.m_len; + if (count_in_cluster == cluster_size) { + compr_cluster = false; + size += blks_to_bytes(inode, 1); + } + } else if (map.m_flags & F2FS_MAP_UNWRITTEN) { + flags = FIEMAP_EXTENT_UNWRITTEN; + } - start_blk += bytes_to_blks(inode, size); + start_blk += bytes_to_blks(inode, size); + } prep_next: cond_resched(); -- 2.32.0.432.gabb21c7263-goog