platform/upstream/f2fs-tools.git
5 months agopackaging: Add spec file for F2FS utilities accepted/tizen_unified tizen accepted/tizen/unified/20231122.072847
Junghoon Kim [Fri, 13 Nov 2020 07:04:21 +0000 (16:04 +0900)]
packaging: Add spec file for F2FS utilities

This adds the spec file for f2fs-tools rpm packaging.

Change-Id: I6ffad0fed05e49e9b976854613f21d112de50ceb
Signed-off-by: Junghoon Kim <jhoon20.kim@samsung.com>
6 months agof2fs-tools: ensure that unused xattr space is zeroized
Eric Biggers [Thu, 26 Oct 2023 02:57:36 +0000 (02:57 +0000)]
f2fs-tools: ensure that unused xattr space is zeroized

Make fsck.f2fs zeroize the unused xattr space, i.e. the space after the
end of the zero-terminated xattr list, if it isn't already zeroized.

This is important because the kernel currently does not explicitly
zero-terminate the list when writing xattrs.  So, the kernel relies on
the unused space containing zeroes.

Also, add a missing free() to fix a memory leak.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 months agof2fs-tools: fix corrupted xattr entry
Daeho Jeong [Sat, 21 Oct 2023 00:29:06 +0000 (17:29 -0700)]
f2fs-tools: fix corrupted xattr entry

Detect and fix a corrupted xattr entry.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 months agof2fs-tools: do not reuse corrupted quota inodes
Daeho Jeong [Fri, 20 Oct 2023 01:04:01 +0000 (18:04 -0700)]
f2fs-tools: do not reuse corrupted quota inodes

When we detect quota inode corruption, we better deallocate the current
space and allocate new ones for a clean start.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 months agof2fs_io: add list/set/removexattr command
Jaegeuk Kim [Wed, 18 Oct 2023 23:22:44 +0000 (16:22 -0700)]
f2fs_io: add list/set/removexattr command

Let's add list/set/removexattrs commands.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 months agofsck.f2fs: recognize ERROR_INCONSISTENT_NAT
Chao Yu [Tue, 17 Oct 2023 03:11:58 +0000 (11:11 +0800)]
fsck.f2fs: recognize ERROR_INCONSISTENT_NAT

Teach fsck.f2fs to recognize newly introduced error type
ERROR_INCONSISTENT_NAT.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 months agofsck.f2fs: fix cache offset for multiple partitions
Jaegeuk Kim [Mon, 16 Oct 2023 18:09:02 +0000 (11:09 -0700)]
fsck.f2fs: fix cache offset for multiple partitions

The cache offset should have been considered multiple partitions per fd.
Let's fix.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 months agoRevert "f2fs-tools: do not support user-space cache"
Jaegeuk Kim [Mon, 16 Oct 2023 16:33:45 +0000 (09:33 -0700)]
Revert "f2fs-tools: do not support user-space cache"

This reverts commit 2835107ae3908576b41ff5f6a4e63ba7ec9a6246.

There's a report that the impact was true.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
6 months agof2fs-tools: use proper address entry count for direct nodes
Daeho Jeong [Mon, 9 Oct 2023 20:29:17 +0000 (13:29 -0700)]
f2fs-tools: use proper address entry count for direct nodes

For direct nodes, we have to use DEF_ADDRS_PER_BLOCK.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: make checked node progress correct
Daeho Jeong [Tue, 3 Oct 2023 21:07:54 +0000 (14:07 -0700)]
f2fs-tools: make checked node progress correct

Let's say we have 100 nodes to be checked. With post-increment of
checked_node_cnt, when we reach the last node, we cannot print out 100%
progress. So, go with pre-increment.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs_io: add fadvise support
Jaegeuk Kim [Tue, 3 Oct 2023 20:08:04 +0000 (13:08 -0700)]
f2fs_io: add fadvise support

f2fs_io fadvise [advice] [offset] [length] [file]

advice can be "willneed" and "sequential".

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: cache free segments count to improve perfmance
Wu Bo [Thu, 28 Sep 2023 09:20:51 +0000 (03:20 -0600)]
f2fs-tools: cache free segments count to improve perfmance

'get_free_segments()' is implemented by traversing all segments to
calculate the total free segments. It cosume much time.

Every time when call 'find_next_free_block()' this calculation will
do it again. So if we cache the free segments count, it will greatly
improve performance of dfrag & resize & sload.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: skip not matched segment when finding free block
Wu Bo [Thu, 28 Sep 2023 09:20:50 +0000 (03:20 -0600)]
f2fs-tools: skip not matched segment when finding free block

If the segment type is not matched, goto next segment to save time.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment
Wu Bo [Thu, 28 Sep 2023 09:20:49 +0000 (03:20 -0600)]
f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment

Use IS_CUR_SEGNO() here can make code more concise and readable.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: avoid build warning
Jaegeuk Kim [Fri, 29 Sep 2023 22:46:45 +0000 (15:46 -0700)]
f2fs-tools: avoid build warning

In function ‘update_extent_info’,
    inlined from ‘update_largest_extent’ at segment.c:559:3,
    inlined from ‘f2fs_build_file’ at segment.c:714:3:
segment.c:484:29: warning: ‘cur_ext.fofs’ may be used uninitialized [-Wmaybe-uninitialized]
  484 |         inode->i.i_ext.fofs = cpu_to_le32(ext->fofs);
segment.c: In function ‘f2fs_build_file’:
segment.c:495:41: note: ‘cur_ext.fofs’ was declared here
  495 |         struct extent_info largest_ext, cur_ext;
      |                                         ^~~~~~~
In function ‘update_extent_info’,
    inlined from ‘update_largest_extent’ at segment.c:559:3,
    inlined from ‘f2fs_build_file’ at segment.c:714:3:
segment.c:485:33: warning: ‘cur_ext.blk’ may be used uninitialized [-Wmaybe-uninitialized]
  485 |         inode->i.i_ext.blk_addr = cpu_to_le32(ext->blk);
segment.c: In function ‘f2fs_build_file’:
segment.c:495:41: note: ‘cur_ext.blk’ was declared here
  495 |         struct extent_info largest_ext, cur_ext;
      |                                         ^~~~~~~

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: do not support user-space cache
Daeho Jeong [Thu, 28 Sep 2023 17:51:13 +0000 (10:51 -0700)]
f2fs-tools: do not support user-space cache

We don't have lots of benefits from this, since block devices already
have page caches in the kernel. Moreover, this feature has some
stability issues corrupting metadata. So, we better make this deprecated.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: Support different block sizes
Daniel Rosenberg [Tue, 29 Aug 2023 01:05:36 +0000 (18:05 -0700)]
f2fs-tools: Support different block sizes

This adds support for 4K and 16K block size using the same binary.
mkfs can choose block size via the -b option, with other tools getting
the blocksize from the superblock.

On mount time, we can't rely on block size for the location for the
superblock, since that information is in the superblock. If the first
superblock is corrupt, we will attempt to find the second superblock at
a 4K block offset, and then a 16K block offset if that fails.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: Refactor f2fs_dentry_block struct
Daniel Rosenberg [Tue, 29 Aug 2023 01:05:35 +0000 (18:05 -0700)]
f2fs-tools: Refactor f2fs_dentry_block struct

This moves access to f2fs_dentry_block's dentry list and filename list
behind a macro, as their locations depend on block size.

Since struct f2fs_dentry_block no longer represents the full block, use
F2FS_BLKSIZE instead of sizeof(struct f2fs_dentry_block)

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: Refactor Summary block struct and friends
Daniel Rosenberg [Tue, 29 Aug 2023 01:05:34 +0000 (18:05 -0700)]
f2fs-tools: Refactor Summary block struct and friends

This splits off access to the summary block's journal and footer into a
macro call, as their location is dependent on block size. Because of
this you should use F2FS_BLKSIZE instead of sizeof(struct summary_block)

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: Refactor SIT/NAT block structs
Daniel Rosenberg [Tue, 29 Aug 2023 01:05:33 +0000 (18:05 -0700)]
f2fs-tools: Refactor SIT/NAT block structs

This converts f2fs_nat_block and f2fs_sit_block to be variable length
arrays. This does not change the way they are accessed, but removes a
misleading statment that these sizes are fixed, as opposed to deriving
from F2FS_BLKSIZE

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: Refactor f2fs_node struct and friends
Daniel Rosenberg [Tue, 29 Aug 2023 01:05:32 +0000 (18:05 -0700)]
f2fs-tools: Refactor f2fs_node struct and friends

This converts inodes, direct nodes, and indirect nodes over to not being
based on a 4K page size. f2fs_inode's i_nids field should now be
accessed via a macro, as it's location depends on block size.

Access to direct nodes and indirect nodes is unchanged.

The node footer's location is also based on block sized, and accessed
via a macro. With these changes, you should use F2FS_BLKSIZE in place of
sizeof(struct f2fs_node)

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: Refactor Orphan Block struct
Daniel Rosenberg [Tue, 29 Aug 2023 01:05:31 +0000 (18:05 -0700)]
f2fs-tools: Refactor Orphan Block struct

This splits off access to the orphan block's footer into a macro call
as its location is dependent on block size. Because of this, you should
use F2FS_BLKSIZE instead of sizeof(struct f2fs_orphan_block)

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agof2fs-tools: Define constants in terms of BLKSIZE
Daniel Rosenberg [Tue, 29 Aug 2023 01:05:30 +0000 (18:05 -0700)]
f2fs-tools: Define constants in terms of BLKSIZE

This converts the various block size based constants to be defined in
terms of the block size. This makes it possible to change the block size
by changing only F2FS_BLKSIZE_BITS in f2fs_fs.h

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agofsck.f2fs: use INFO_MSG() to print i_gc_failure reset info
Chao Yu [Mon, 4 Sep 2023 15:10:07 +0000 (23:10 +0800)]
fsck.f2fs: use INFO_MSG() to print i_gc_failure reset info

fsck.f2fs prints i_gc_failures reset message w/ [FIX] tags, it's not
appropriate due to reset i_gc_failures is not a fix.

Let's add INFO_MSG() macro to print such important non-fix message.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
7 months agofsck.f2fs: use clearer info message for -a option
Eric Biggers [Tue, 5 Sep 2023 00:38:02 +0000 (17:38 -0700)]
fsck.f2fs: use clearer info message for -a option

The message "Info: Fix the reported corruption" makes people think that
fsck has detected filesystem corruption.  Replace this message with
"Info: Automatic fix mode enabled" which is more accurate.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 months agof2fs-tools: convert to lseek() and kill lseek64
Waldemar Brodkorb [Wed, 23 Aug 2023 13:41:28 +0000 (15:41 +0200)]
f2fs-tools: convert to lseek() and kill lseek64

This patch replaces lseek64 with lseek() having #define _FILE_OFFSET_BITS 64.

Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 months agof2fs_io: add do_clearflags to clear nocompress/compress flag
Qi Han [Fri, 18 Aug 2023 02:03:03 +0000 (10:03 +0800)]
f2fs_io: add do_clearflags to clear nocompress/compress flag

To align f2fs_io functionality with chattr +/-c and +/-m, the
do_clearflags function has been added to clear the FS_COMPR_FL and
FS_NOCOMP_FL flags.

Signed-off-by: Qi Han <hanqi@vivo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
8 months agof2fs-tools: f2fs_io: no memcpy for mmap read
Jaegeuk Kim [Fri, 11 Aug 2023 22:04:08 +0000 (15:04 -0700)]
f2fs-tools: f2fs_io: no memcpy for mmap read

This replaces the mmmap read flow to get the maximum performance.

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
9 months agodump.f2fs: support to dump fsverity xattr info in print_xattr_entry()
Chao Yu [Tue, 18 Jul 2023 04:05:00 +0000 (12:05 +0800)]
dump.f2fs: support to dump fsverity xattr info in print_xattr_entry()

This patch adds to support dumping fsverity xattr info in print_xattr_entry().

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
9 months agof2fs-tools: do sanity check on xattr entry
Chao Yu [Tue, 18 Jul 2023 04:05:23 +0000 (12:05 +0800)]
f2fs-tools: do sanity check on xattr entry

If there are corrupted xattr entries in xattr space, it may cause
traversing across end of xattr space issue, this patch adds sanity
check during xattr traverse to avoid such issue.

This patch synchronizes kernel commits:

2777e654371d ("f2fs: fix to avoid accessing xattr across the boundary")
688078e7f36c ("f2fs: fix to avoid memory leakage in f2fs_listxattr")

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
9 months agof2fs-tools: support to show fscrypt_context_v2 in print_xattr_entry
Weichao Guo [Mon, 17 Jul 2023 10:52:18 +0000 (18:52 +0800)]
f2fs-tools: support to show fscrypt_context_v2 in print_xattr_entry

As the fscrypt context has two versions now, this patch adds the
support of fscrypt_context_v2 for print_xattr_entry.

Signed-off-by: Weichao Guo <guoweichao@oppo.com>
Signed-off-by: Sheng Yong <shengyong@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
9 months agodump.f2fs: remove redundant check condition in dump_node()
Chao Yu [Wed, 19 Jul 2023 07:01:22 +0000 (15:01 +0800)]
dump.f2fs: remove redundant check condition in dump_node()

In dump_node(), f2fs_is_valid_blkaddr() has checked ni.blk_addr's
validity and dump_node() will bail up if ni.blk_addr is invalid,
so let's remove redundant check condition and print below:

if (ni.blk_addr == 0x0)
MSG(force, "Invalid nat entry\n\n");

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
9 months agof2fs_io: fix build warning
Jaegeuk Kim [Tue, 18 Jul 2023 03:37:12 +0000 (20:37 -0700)]
f2fs_io: fix build warning

external/f2fs-tools/tools/f2fs_io/f2fs_io.c:1452:3: error: format specifies type 'unsigned long' but the argument has type 'u64' (aka 'unsigned long long') [-Werror,-Wformat]
                range.start, range.len, ret);
                ^~~~~~~~~~~
external/f2fs-tools/tools/f2fs_io/f2fs_io.c:1452:16: error: format specifies type 'unsigned long' but the argument has type 'u64' (aka 'unsigned long long') [-Werror,-Wformat]
                range.start, range.len, ret);
                             ^~~~~~~~~
2 errors generated.
20:35:27 ninja failed with: exit status 1

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
9 months agof2fs-tools: quick fix for Android build
Jaegeuk Kim [Mon, 17 Jul 2023 18:16:38 +0000 (11:16 -0700)]
f2fs-tools: quick fix for Android build

In file included from external/f2fs-tools/lib/nls_utf8.c:29:
external/f2fs-tools/include/f2fs_fs.h:1781:44: error: call to undeclared function 'S_ISDIR'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        raw_node->i.i_current_depth = cpu_to_le32(S_ISDIR(mode) ? 1 : 0);

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
9 months agof2fs: should use inode when updating file offset
Jaegeuk Kim [Wed, 12 Jul 2023 10:08:58 +0000 (03:08 -0700)]
f2fs: should use inode when updating file offset

In indirect or double indirect node blocks, we should use parent inode
information to check the offset.

This fixes the below complaint with a reproducer.

$ mount -t f2fs -o discard,compress_extension=* /dev/$DEV $TESTDIR
$ f2fs_io write 1 3944 4 zero buffered $TESTDIR/a
$ umount /dev/$DEV
$ fsck.f2fs /dev/$DEV
Info: MKFS version
  "Linux version 6.5.0-rc1-custom (root@file) (gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.37) #19 SMP PREEMPT_DYNAMIC Mon Jul 10 19:18:40 UTC 2023"
Info: FSCK version
  from "Linux version 6.5.0-rc1-custom (root@file) (gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.37) #19 SMP PREEMPT_DYNAMIC Mon Jul 10 19:18:40 UTC 2023"
    to "Linux version 6.5.0-rc1-custom (root@file) (gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0, GNU ld (GNU Binutils for Ubuntu) 2.37) #19 SMP PREEMPT_DYNAMIC Mon Jul 10 19:18:40 UTC 2023"
Info: superblock features = 3088 :  extra_attr quota casefold compression
Info: superblock encrypt level = 0, salt = 00000000000000000000000000000000
Info: Segments per section = 1
Info: Sections per zone = 1
Info: total FS sectors = 134217728 (65536 MB)
Info: CKPT version = 284f1e2f
Info: Checked valid nat_bits in checkpoint
Info: checkpoint state = c5 :  nat_bits crc compacted_summary unmount
[ASSERT] (fsck_chk_inode_blk:1189)  --> ino: 0x6 has i_blocks: 00000007, but has 6 blocks

[FSCK] Max image size: 378 MB, Free space: 65158 MB
[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0x0]
[FSCK] valid_block_count matching with CP             [Fail] [0xf, 0xe]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x6]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x6]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x4]
[FSCK] free segment_count matched with CP             [Ok..] [0x7f3f]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Fail]
Do you want to fix this partition? [Y/N]

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
10 months agofsck.f2fs: recognize ERROR_INVALID_NODE_REFERENCE
Chao Yu [Thu, 29 Jun 2023 11:12:20 +0000 (19:12 +0800)]
fsck.f2fs: recognize ERROR_INVALID_NODE_REFERENCE

This patch supports to recognize ERROR_INVALID_NODE_REFERENCE error
recorded in superblock during fsck, and force fsck to fix related
issue.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
10 months agofsck.f2fs: fix to call ASSERT_MSG() in is_valid_ssa_{data,node}_blk()
Chao Yu [Sun, 25 Jun 2023 09:28:32 +0000 (17:28 +0800)]
fsck.f2fs: fix to call ASSERT_MSG() in is_valid_ssa_{data,node}_blk()

Previously, fsck fixes summary entry and writeback last summary block into
SSA area, however, it missed to flush summary cache in CP area, result in
repair failure.

This patch fixes to call ASSERT_MSG() for such case, in order to trigger
additional checkpoint during fsck_verify(), so that last fixed summary
entry can be persisted correctly.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
10 months agofsck.f2fs: Detect and fix looped node chain efficiently
Chunhai Guo [Mon, 26 Jun 2023 09:30:46 +0000 (17:30 +0800)]
fsck.f2fs: Detect and fix looped node chain efficiently

find_fsync_inode() detect the looped node chain by comparing the loop
counter with free blocks. While it may take tens of seconds to quit when
the free blocks are large enough. We can use Floyd's cycle detection
algorithm to make the detection more efficient, and fix the issue by
filling a NULL address in the last node of the chain.

Below is the log we encounter on a 256GB UFS storage and it takes about
25 seconds to detect looped node chain. After changing the algorithm, it
takes about 20ms to finish the same job.

    [   10.822904] fsck.f2fs: Info: version timestamp cur: 17, prev: 430
    [   10.822949] fsck.f2fs: [update_superblock: 762] Info: Done to
update superblock
    [   10.822953] fsck.f2fs: Info: superblock features = 1499 :
encrypt verity extra_attr project_quota quota_ino casefold
    [   10.822956] fsck.f2fs: Info: superblock encrypt level = 0, salt =
00000000000000000000000000000000
    [   10.822960] fsck.f2fs: Info: total FS sectors = 59249811 (231444
MB)
    [   35.852827] fsck.f2fs:detect looped node chain,
blkaddr:1114802, next:1114803
    [   35.852842] fsck.f2fs: [f2fs_do_mount:3846] record_fsync_data
failed
    [   35.856106] fsck.f2fs: fsck.f2fs terminated by exit(255)

Suggested-by: Chao Yu <chao@kernel.org>
Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
10 months agof2fs_io: expend fallocate command
Yangtao Li [Tue, 13 Jun 2023 06:59:10 +0000 (14:59 +0800)]
f2fs_io: expend fallocate command

Expend fallocate command to support more flags.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
10 months agof2fs-tools: fix to call assert() if f2fs_dentry_hash() fails
Chao Yu [Thu, 8 Jun 2023 10:12:30 +0000 (18:12 +0800)]
f2fs-tools: fix to call assert() if f2fs_dentry_hash() fails

f2fs_dentry_hash() may return -ENOMEM due to malloc() failure, however
caller won't check validaty of return value, result assign or check
wrong hash value, fix to call assert() for such case.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
10 months agof2fs-tools: fix wrong write pointer check for non-zoned areas
Daeho Jeong [Tue, 6 Jun 2023 17:39:48 +0000 (10:39 -0700)]
f2fs-tools: fix wrong write pointer check for non-zoned areas

Do not check F2FS_ZONED_HM for the whole device. We need to do this for
each area of devices.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agofsck.f2fs: fix memleak in f2fs_create()
Maxim Korotkov [Mon, 5 Jun 2023 06:08:53 +0000 (09:08 +0300)]
fsck.f2fs: fix memleak in f2fs_create()

In error handling cases, exiting a function without releasing memory

Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agofsck.f2fs: fix potential NULL dereference
Maxim Korotkov [Fri, 2 Jun 2023 10:26:07 +0000 (13:26 +0300)]
fsck.f2fs: fix potential NULL dereference

The input pointer "parent" was used unsafely
before checking against NULL

Found by RASU JSC with Svace static analyzer
Fixes: 603f8f9d3(sload.f2fs: support loading files into partition directly)
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Maxim Korotkov <maskorotkov@rasu.ru>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs_io: support gc_range command
Chao Yu [Thu, 1 Jun 2023 10:30:54 +0000 (18:30 +0800)]
f2fs_io: support gc_range command

This patch supports a new sub-command 'gc_range' in f2fs_io to trigger
gc to move blocks in specified range via F2FS_IOC_GARBAGE_COLLECT_RANGE
ioctl.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: remove power-of-two limitation of zoned device
Daeho Jeong [Wed, 31 May 2023 17:52:13 +0000 (10:52 -0700)]
f2fs-tools: remove power-of-two limitation of zoned device

Remove power-of-two limitation for zoned device, since zoned devices
don't have it.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agofsck.f2fs: clean up codes with IS_INODE()
Chao Yu [Wed, 31 May 2023 01:19:36 +0000 (09:19 +0800)]
fsck.f2fs: clean up codes with IS_INODE()

and change return value's type of IS_INODE() from int to bool.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: reuse feature_table to clean up print_sb_state()
Chao Yu [Sat, 27 May 2023 00:01:26 +0000 (08:01 +0800)]
f2fs-tools: reuse feature_table to clean up print_sb_state()

reuse feature_table in print_sb_state() for cleanup.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: fix to le32 type variable correctly
Chao Yu [Sat, 27 May 2023 00:01:25 +0000 (08:01 +0800)]
f2fs-tools: fix to le32 type variable correctly

Fix below incorrect use:
- compare cpu and le32 type variable:
if (get_sb(feature) & cpu_to_le32(F2FS_FEATURE_RO))
- compare le32 type vairable:
if (c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR))
- miss get_sb(feature)
(cpu_to_le32(F2FS_FEATURE_RO) ? 1 : 0)
- update le32 type variable
sb->feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agomkfs.f2fs: refactor format flow for cleanup
Chao Yu [Fri, 26 May 2023 23:54:23 +0000 (07:54 +0800)]
mkfs.f2fs: refactor format flow for cleanup

During formatting device, node/data block and filesystem metatdata related
to same inode were updated in separated functions, e.g. for root inode:
- f2fs_write_root_inode() updates root inode's block
- f2fs_write_check_point_pack updates its nat/sit journal, summary block

Result in:
- there are some redundant codes in between f2fs_write_check_point_pack()
and functions in f2fs_create_root_dir().
- readability is bad due to filesystem meta and data/node updates in
separated places.
- bad scalability if we want to add more default inode.

So that, this patch introduces below functions:
- update_sit_journal
- update_nat_jounral
- update_summary_entry

Then use them to update inode related metadata into cache in below
functions:
- f2fs_write_root_inode
- f2fs_add_default_dentry_root
- f2fs_write_qf_inode
- f2fs_write_default_quota
- f2fs_write_lpf_inode
- f2fs_write_lpf_inode

Finally, f2fs_write_check_point_pack() can write back cached metadata
into CP area directly.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agomkfs.f2fs: cleanup w/ alloc_next_free_block()
Chao Yu [Fri, 26 May 2023 23:54:22 +0000 (07:54 +0800)]
mkfs.f2fs: cleanup w/ alloc_next_free_block()

Introduce alloc_next_free_block() to wrap below openned codes:

blkaddr = get_sb(main_blkaddr) +
c.cur_seg[curseg_type] * c.blks_per_seg +
c.curseg_offset[curseg_type];

Meanwhile add curseg_offset field in f2fs_configuration to record
last blkaddr in each log.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs_io: Fix integer multiplication overflow error in fiemap
zangyangyang1 [Tue, 23 May 2023 12:27:20 +0000 (20:27 +0800)]
f2fs_io: Fix integer multiplication overflow error in fiemap

When using fiemap to obtain the block address of files
larger than 2GB ((2147483647+1) bytes), an integer
multiplication overflow error will occur.
This issue is caused by the following code:
    start = atoi(argv[1]) * F2FS_BLKSIZE;
    length = atoi(argv[2]) * F2FS_BLKSIZE;

Signed-off-by: zangyangyang1 <zangyangyang1@xiaomi.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agomkfs.f2fs: remove unneeded nat initialization in f2fs_update_nat_root()
Chao Yu [Wed, 17 May 2023 08:26:30 +0000 (16:26 +0800)]
mkfs.f2fs: remove unneeded nat initialization in f2fs_update_nat_root()

- remove unneeded nat initialization for root/quota inode due to
it has been initialized in nat journal.
- name f2fs_update_nat_root() to f2fs_update_nat_default().

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: add noatime for quota file
Chao Yu [Wed, 17 May 2023 08:26:29 +0000 (16:26 +0800)]
f2fs-tools: add noatime for quota file

Disk quota file is controlled by filesystem quota subsystem, access time
of quota file is almost random, and should be meanless to user, so let's
add noatime to quota file.

Meanwhile, set quota file w/ F2FS_IMMUTABLE_FL instead of FS_IMMUTABLE_FL,
since F2FS_IMMUTABLE_FL is on-disk flag, however FS_IMMUTABLE_FL is in-memory
one.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agofsck.f2fs: lookup and relink root inode
Chao Yu [Fri, 12 May 2023 10:03:54 +0000 (18:03 +0800)]
fsck.f2fs: lookup and relink root inode

As Stephanos reported in mailing list:

Info: checkpoint state = 1 :  unmount
[ASSERT] (sanity_check_nid: 362)  --> nid[0x3] ino is 0

The root cause is root inode's nat entry is corrupted, this patch
add logic to search root inode from all node blocks, try to relink
root inode's nat to target node block.

Before:

Info: checkpoint state = 185 :  trimmed nat_bits compacted_summary unmount
[lookup_nat_in_journal:3085] ==> Found nid [0x3] in nat cache
[ASSERT] (sanity_check_nat: 404)  --> nid->blk_addr is 0x0. [0x3]
Info: root inode is corrupted, search and relink it
Info: possible root inode blkaddr: 0x5a00
[lookup_nat_in_journal:3085] ==> Found nid [0x3] in nat cache
[ASSERT] (sanity_check_nat: 404)  --> nid->blk_addr is 0x0. [0x3]

[FSCK] Max image size: 94 MB, Free space: 12194 MB
[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Fail]
[FSCK] Hard link checking for regular file            [Ok..] [0x0]
[FSCK] valid_block_count matching with CP             [Fail] [0x2, 0x0]
[FSCK] valid_node_count matching with CP (de lookup)  [Fail] [0x1, 0x0]
[FSCK] valid_node_count matching with CP (nat lookup) [Fail] [0x1, 0x0]
[FSCK] valid_inode_count matched with CP              [Fail] [0x1, 0x0]
[FSCK] free segment_count matched with CP             [Ok..] [0x17cd]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Fail]
Do you want to fix this partition? [Y/N] Y

After:

Info: checkpoint state = 185 :  trimmed nat_bits compacted_summary unmount
[lookup_nat_in_journal:3085] ==> Found nid [0x3] in nat cache
[ASSERT] (sanity_check_nat: 404)  --> nid->blk_addr is 0x0. [0x3]
Info: root inode is corrupted, search and relink it
Info: possible root inode blkaddr: 0x5a00
[FIX] (fsck_chk_root_inode: 730)  --> Relink root inode, blkaddr: 0x5a00
update nat(nid:3) blkaddr [0x5a00] in journal
[fsck_chk_dentry_blk:1978] [  1] Dentry Block [0x6000] Done : dentries:0 in 214 slots (len:255)

[fsck_chk_inode_blk:1244] Directory Inode: 0x3 [] depth: 1 has 0 files

[FSCK] Max image size: 94 MB, Free space: 12194 MB
[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0x0]
[FSCK] valid_block_count matching with CP             [Ok..] [0x2]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x1]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x1]
[FSCK] valid_inode_count matched with CP              [Ok..] [0x1]
[FSCK] free segment_count matched with CP             [Ok..] [0x17cd]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Fail]
Info: flush_journal_entries() n_nats: 1, n_sits: 6
Info: Duplicate valid checkpoint to mirror position 512 -> 1024
[write_nat_bits:1737]  Writing NAT bits pages, at offset 0x000003ff
Info: Write valid nat_bits in checkpoint
Info: write_checkpoint() cur_cp:1
[write_nat_bits:1737]  Writing NAT bits pages, at offset 0x000003ff
Info: Write valid nat_bits in checkpoint
Info: fix_checkpoint() cur_cp:1

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agofsck.f2fs: add more debug info in fsck_verify()
Chao Yu [Fri, 12 May 2023 10:03:53 +0000 (18:03 +0800)]
fsck.f2fs: add more debug info in fsck_verify()

In order to track details of stat info and repair flow.

[FSCK] valid_block_count matching with CP             [Fail] [0x2, 0x0]
[FSCK] valid_node_count matching with CP (de lookup)  [Fail] [0x1, 0x0]
[FSCK] valid_node_count matching with CP (nat lookup) [Fail] [0x1, 0x0]
[FSCK] valid_inode_count matched with CP              [Fail] [0x1, 0x0]

Info: flush_journal_entries() n_nats: 1, n_sits: 6
Info: write_checkpoint() cur_cp:1
Info: fix_checkpoint() cur_cp:1

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agofsck.f2fs: use f2fs_is_valid_blkaddr()
Chao Yu [Fri, 12 May 2023 10:03:52 +0000 (18:03 +0800)]
fsck.f2fs: use f2fs_is_valid_blkaddr()

use f2fs_is_valid_blkaddr() instead of IS_VALID_BLK_ADDR() to
check validity of data/node's block address.

use is_valid_data_blkaddr() in sanity_check_nid() to check NULL_ADDR
as NEW_ADDR, and print the value in error path explicitly.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agofsck.f2fs: wrap openned codes into fsck_sanity_check_nid()
Chao Yu [Fri, 12 May 2023 10:03:51 +0000 (18:03 +0800)]
fsck.f2fs: wrap openned codes into fsck_sanity_check_nid()

read_all_xattrs() is the only user of fsck_sanity_check_nid(), wrap
openned codes of read_all_xattrs() into fsck_sanity_check_nid().

Then fsck_sanity_check_nid() can be reused later.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs_io: support move_range command
Yangtao Li [Sat, 6 May 2023 11:45:36 +0000 (19:45 +0800)]
f2fs_io: support move_range command

This patch supports a new sub-command 'move_range' in f2fs_io
to move a range of data blocks from source file to destination
file via F2FS_IOC_MOVE_RANGE ioctl.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: use f2fs_init_inode() to clean up codes
Chao Yu [Fri, 5 May 2023 10:02:05 +0000 (18:02 +0800)]
f2fs-tools: use f2fs_init_inode() to clean up codes

No logic changes.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: print more raw sb info
Chao Yu [Fri, 5 May 2023 10:02:04 +0000 (18:02 +0800)]
f2fs-tools: print more raw sb info

Output is as below:

magic                          [0xf2f52010 : 4076150800]
major_ver                      [0x       1 : 1]
minor_ver                      [0x      10 : 16]
log_sectorsize                 [0x       9 : 9]
log_sectors_per_block          [0x       3 : 3]
log_blocksize                  [0x       c : 12]
log_blocks_per_seg             [0x       9 : 9]
segs_per_sec                   [0x       1 : 1]
secs_per_zone                  [0x       1 : 1]
checksum_offset                [0x       0 : 0]
block_count                    [0x  300000 : 3145728]
section_count                  [0x    17d3 : 6099]
segment_count                  [0x    17ff : 6143]
segment_count_ckpt             [0x       2 : 2]
segment_count_sit              [0x       2 : 2]
segment_count_nat              [0x      1c : 28]
segment_count_ssa              [0x       c : 12]
segment_count_main             [0x    17d3 : 6099]
segment0_blkaddr               [0x     200 : 512]
cp_blkaddr                     [0x     200 : 512]
sit_blkaddr                    [0x     600 : 1536]
nat_blkaddr                    [0x     a00 : 2560]
ssa_blkaddr                    [0x    4200 : 16896]
main_blkaddr                   [0x    5a00 : 23040]
root_ino                       [0x       3 : 3]
node_ino                       [0x       1 : 1]
meta_ino                       [0x       2 : 2]
uuid                           [f16856a6-8781-422b-adce-d51c0632c94e]
volum_name                     []
extension_count                [0x      24 : 36]
cold file extentsions
                               [mp      wm      og      jp      ]
                               [avi     m4v     m4p     mkv     ]
                               [mov     webm    wav     m4a     ]
                               [3gp     opus    flac    gif     ]
                               [png     svg     webp    jar     ]
                               [deb     iso     gz      xz      ]
                               [zst     pdf     pyc     ttc     ]
                               [ttf     exe     apk     cnt     ]
                               [exo     odex    vdex    so      ]
hot_ext_count                  [0x       4 : 4]
hot file extentsions
                               [db      vmdk    vdi     qcow2   ]
cp_payload                     [0x       0 : 0]
version                        [Linux version 6.3.0+ (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #143 SMP PREEMPT_DYNAMIC Thu May  4 09:50:08 HKT 2023]
init_version                   [Linux version 6.3.0+ (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #143 SMP PREEMPT_DYNAMIC Thu May  4 09:50:08 HKT 2023]
feature                        [0x    21f8 : 8696]
encryption_level               [0x       0 : 0]
encrypt_pw_salt                [00000000-0000-0000-0000-000000000000]
qf_ino[USRQUOTA]               [0x       4 : 4]
qf_ino[GRPQUOTA]               [0x       5 : 5]
qf_ino[PRJQUOTA]               [0x       6 : 6]
s_encoding                     [0x       0 : 0]
crc                            [0x       0 : 0]

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: add DISP_u8() macro
Chao Yu [Fri, 5 May 2023 10:02:03 +0000 (18:02 +0800)]
f2fs-tools: add DISP_u8() macro

Introduce DISP_u8(), and use DISP_u16() and DISP_u8() to print below fields:
- i_compress_algorithm
- i_log_cluster_size
- i_compress_flag

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: fix typo in f2fs_inode structure
Chao Yu [Fri, 5 May 2023 10:02:02 +0000 (18:02 +0800)]
f2fs-tools: fix typo in f2fs_inode structure

:%s/i_compress_algrithm/i_compress_algorithm/g

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: rename i_padding to i_compress_flag
Chao Yu [Fri, 5 May 2023 10:02:01 +0000 (18:02 +0800)]
f2fs-tools: rename i_padding to i_compress_flag

Commit b28f047b28c5 ("f2fs: compress: support chksum") renames i_padding
to i_compress_flag in struct f2fs_inode, adjust f2fs-tools' codes as well.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: add packed attribute for struct f2fs_super_block
Chao Yu [Fri, 5 May 2023 10:02:00 +0000 (18:02 +0800)]
f2fs-tools: add packed attribute for struct f2fs_super_block

Otherwise, it may trigger static assert below when the structure
updates.

static_assert(sizeof(struct f2fs_super_block) == 3072, "")

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
11 months agof2fs-tools: allocate memory to handle label
Jaegeuk Kim [Fri, 5 May 2023 16:18:30 +0000 (09:18 -0700)]
f2fs-tools: allocate memory to handle label

Let's avoid memory alignment of sb->volume_name.

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
12 months agof2fs_io: support precache_extents command
Yangtao Li [Fri, 14 Apr 2023 08:47:28 +0000 (16:47 +0800)]
f2fs_io: support precache_extents command

This patch supports a new sub-command 'precache_extents' in f2fs_io
to trigger precache extents via F2FS_IOC_PRECACHE_EXTENTS ioctl.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
12 months agof2fs_io: support checkpoint command
Chao Yu [Fri, 14 Apr 2023 03:51:46 +0000 (11:51 +0800)]
f2fs_io: support checkpoint command

This patch supports a new sub-command 'checkpoint' in f2fs_io to
trigger filesystem checkpoint via F2FS_IOC_WRITE_CHECKPOINT ioctl.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
12 months agomkfs.f2fs: Introduce configurable reserved sections
Yonggil Song [Tue, 4 Apr 2023 06:21:03 +0000 (15:21 +0900)]
mkfs.f2fs: Introduce configurable reserved sections

Overview
========

This option allows zoned block device users to configure GC reserved and
overprovision area manually according to their demands on performance of
sustained write latency and WAF.

Problem
=======

The overprovision segments that mkfs generates are mostly occupied by GC
reserved. This degrades WAF performance.

Experiment
==========

The following experiment evaluated the application of configurable reserved.
The experimental environment is as follows.

  System info
    - 4.2Ghz, 8 core CPU
    - 64GiB Memory
  Device info
    - a conventional null_blk with 448MiB capacity(meta area) and
    - a sequential null_blk with 953 zones of 64MiB
  Format
    - as-is (find out ovp ratio): mkfs.f2fs <conv null_blk> -c <seq null_blk> -m
        Info: Overprovision ratio = 3.700%
        Info: Overprovision segments = 1152 (GC reserved = 1088)
    - config rsvd: mkfs.f2fs <conv null_blk> -c <seq null_blk> -m -Z 8 -o 2.965
        Info: Overprovision ratio = 2.965%
        Info: Overprovision segments = 1152 (GC reserved = 256)
  Mount
    - mount <conv null_blk> <mount point>
  Fio script
    - fio --rw=randwrite --bs=4k --ba=4k --filesize=58630m --norandommap --overwrite=1 --name=job1 --filename=<mount point>/sustain --time_based --runtime=2h
  WAF calculation
    - (IOs on conv. null_blk + IOs on seq. null_blk) / random write IOs

Conclusion
==========

In the experiment, it can be shown that reducing the reserved segments
decreases WAF to 10% (from 222 to 23) although it triggers checkpoint more
frequently during gc. With direct IO, the WAF of as-is gets much higher.
In other words, a user can configure more reserved segments for lower GC
latency or allocate less reserved segments for lower WAF on the same number
of OP segments.

Signed-off-by: Yonggil Song <yonggil.song@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
12 months agof2fs-tools: upgrade version 1.16.0
Jaegeuk Kim [Tue, 11 Apr 2023 17:11:16 +0000 (10:11 -0700)]
f2fs-tools: upgrade version 1.16.0

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
13 months agofsck.f2fs: fix sanity check logic for cp_payload
Juhyung Park [Tue, 4 Apr 2023 05:54:46 +0000 (14:54 +0900)]
fsck.f2fs: fix sanity check logic for cp_payload

cp_payload is set differently [1] when extended node bitmap feature is
enabled. Commit b79c3ba4ea9d broke fsck on f2fs file systems created on
2+ TB device with extended node bitmap feature enabled.

As the sanity check is for checking overflows, fix this to assume the max
possible cp_payload size under the extended node bitmap.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/tree/mkfs/f2fs_format.c?h=v1.15.0#n372
Fixes: b79c3ba4ea9d ("fsck.f2fs: sanity check cp_payload before reading checkpoint")
Reported-by: Alexander Koskovich <akoskovich@pm.me>
Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
13 months agomkfs.f2fs: remove indentation
Jaegeuk Kim [Mon, 27 Mar 2023 18:42:49 +0000 (11:42 -0700)]
mkfs.f2fs: remove indentation

Show info w/o it.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
13 months agofsck.f2fs: don't call report_zone on normal partition
Jaegeuk Kim [Mon, 20 Mar 2023 23:59:31 +0000 (16:59 -0700)]
fsck.f2fs: don't call report_zone on normal partition

Report_zone is not supported on normal partition.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
13 months agof2fs-tools: relax zone size of power of 2
Jaegeuk Kim [Thu, 2 Mar 2023 19:45:09 +0000 (11:45 -0800)]
f2fs-tools: relax zone size of power of 2

Let's relax this for Android support.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
14 months agomkfs.f2fs: trim all the devices except the first one
Jaegeuk Kim [Wed, 8 Feb 2023 19:24:41 +0000 (11:24 -0800)]
mkfs.f2fs: trim all the devices except the first one

We need to check the first disk only, and trim the other disks.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
14 months agof2fs-tools: fix # of total segments
Jaegeuk Kim [Fri, 10 Feb 2023 21:02:23 +0000 (13:02 -0800)]
f2fs-tools: fix # of total segments

TOTAL_SEGS should include metadata segments and main segments.

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
14 months agof2fs_io: support AES_256_HCTR2
Jaegeuk Kim [Tue, 7 Feb 2023 02:22:03 +0000 (18:22 -0800)]
f2fs_io: support AES_256_HCTR2

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
14 months agof2fs_io: Fix out of tree builds
Khem Raj [Thu, 22 Dec 2022 02:28:29 +0000 (18:28 -0800)]
f2fs_io: Fix out of tree builds

Relative path does not work when searching for include files
when srcdir != builddir

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
14 months agofsck.f2fs: relocate chksum verification step during f2fs_do_mount()
Chao Yu [Thu, 2 Feb 2023 07:56:25 +0000 (15:56 +0800)]
fsck.f2fs: relocate chksum verification step during f2fs_do_mount()

Keep sanity_check_raw_super flow in fsck.f2fs being consistent w/
sanity_check_raw_super() in f2fs kernel module, otherwise, it outputs
different error information when mounting/fscking the same image which
contains corrupted superblock.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
14 months agof2fs-tools: Remove deprecated f2fstat
Jaegeuk Kim [Tue, 20 Dec 2022 18:49:45 +0000 (10:49 -0800)]
f2fs-tools: Remove deprecated f2fstat

Let's remove this.

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
17 months agoRemove sg_write_buffer
Bart Van Assche [Thu, 24 Nov 2022 00:34:49 +0000 (16:34 -0800)]
Remove sg_write_buffer

Remove the sg_write_buffer source code and build rules now that the
sg3_utils project has been imported.

Signed-off-by: Bart Van Assche <bvanassche@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
17 months agofsck.f2fs: avoid uncessary recalculation
Sheng Yong [Mon, 14 Nov 2022 14:17:00 +0000 (22:17 +0800)]
fsck.f2fs: avoid uncessary recalculation

There is no need to recalculate ADDRS_PER_INODE and ADDRS_PER_BLOCK,
especially in a for loop.

Signed-off-by: Sheng Yong <shengyong@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
17 months agofsck.f2fs: fix potential overflow of copying i_name
Sheng Yong [Thu, 10 Nov 2022 14:07:22 +0000 (22:07 +0800)]
fsck.f2fs: fix potential overflow of copying i_name

If i_namelen is corrupted, there may be an overflow when doing memcpy.

Signed-off-by: Sheng Yong <shengyong@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
17 months agofsck.f2fs: add parentheses for SB_MASK
Sheng Yong [Thu, 10 Nov 2022 14:07:21 +0000 (22:07 +0800)]
fsck.f2fs: add parentheses for SB_MASK

Signed-off-by: Sheng Yong <shengyong@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
17 months agodump.f2fs: remove unavailable option -g
Sheng Yong [Thu, 10 Nov 2022 14:07:20 +0000 (22:07 +0800)]
dump.f2fs: remove unavailable option -g

Option "-g" for dump.f2fs is unavailable and not used in dump.f2fs.

Signed-off-by: Sheng Yong <shengyong@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
17 months agof2fs-tools: define HAVE_CLOCK_GETTIME properly
Juhyung Park [Sun, 6 Nov 2022 12:19:23 +0000 (21:19 +0900)]
f2fs-tools: define HAVE_CLOCK_GETTIME properly

HAVE_CLOCK_GETTIME wasn't defined during autoconf, leading to
messages like "Done: 0.000000 secs" on Linux distros.

Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agof2fs-tools: support F2FS_IOC_START_ATOMIC_REPLACE
Daeho Jeong [Mon, 19 Sep 2022 16:15:02 +0000 (09:15 -0700)]
f2fs-tools: support F2FS_IOC_START_ATOMIC_REPLACE

Added options in f2fs_io write command to support
F2FS_IOC_START_ATOMIC_REPLACE.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agof2fs-tools: give less overprovisioning space
Jaegeuk Kim [Mon, 10 Oct 2022 21:02:22 +0000 (14:02 -0700)]
f2fs-tools: give less overprovisioning space

As f2fs becomes more resilient for GCs, let's give the marginal overprovision
space back to user.

Fix an issue where reserved_space > ovp_space, reported by Shinichiro.

Signed-off-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agof2fs-tools: set host-aware zoned device similar to host-managed one
Jaegeuk Kim [Fri, 30 Sep 2022 15:51:13 +0000 (08:51 -0700)]
f2fs-tools: set host-aware zoned device similar to host-managed one

It'd be good to generate zone-aware sequential writes to both of HA and HM
zoned devices.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agofsck.f2fs: fix missing to assign c.zoned_model
Jaegeuk Kim [Mon, 3 Oct 2022 20:55:07 +0000 (13:55 -0700)]
fsck.f2fs: fix missing to assign c.zoned_model

We need to set the c.zoned_model appropriately for further usages.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agofsck.f2fs: trigger repairing if filesystem has inconsistent errors
Chao Yu [Thu, 6 Oct 2022 15:17:27 +0000 (23:17 +0800)]
fsck.f2fs: trigger repairing if filesystem has inconsistent errors

In auto/preen mode, let's trigger repairing if filesystem has
inconsistent errors.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agofsck.f2fs: trigger repairing if filesystem was forced to stop
Chao Yu [Thu, 6 Oct 2022 15:17:26 +0000 (23:17 +0800)]
fsck.f2fs: trigger repairing if filesystem was forced to stop

In auto/preen mode, let's trigger repairing if filesystem was forced
to stop.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agofsck.f2fs: export valid image size
Chao Yu [Thu, 6 Oct 2022 15:16:57 +0000 (23:16 +0800)]
fsck.f2fs: export valid image size

Change to calculate and export max image size with valid blocks
used of image rather than last used block of image.

[FSCK] Max image size: xx MB, Free space: xx MB

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agomkfs.f2fs: update allocation policy for ro feature
Chao Yu [Thu, 6 Oct 2022 15:16:56 +0000 (23:16 +0800)]
mkfs.f2fs: update allocation policy for ro feature

Update allocation policy for ro feature:
- hot_data: allocating blocks by LBA ascending order
- hot_node: allocating blocks by LBA descending order

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
18 months agofsck.f2fs: fix __end_block_addr()
Chao Yu [Thu, 6 Oct 2022 15:16:06 +0000 (23:16 +0800)]
fsck.f2fs: fix __end_block_addr()

The calculation is wrong, fix it.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
19 months agoAlways use sparse/sparse.h when building for Android
Robin Lee [Fri, 9 Sep 2022 08:05:51 +0000 (08:05 +0000)]
Always use sparse/sparse.h when building for Android

Change-Id: Ic903ce09c93de75d6deb700a5a283638a912a25b
Test: fastboot erase userdata

19 months agof2fs-tools: fix build error on lz4-1.9.4
Jaegeuk Kim [Mon, 29 Aug 2022 18:03:35 +0000 (11:03 -0700)]
f2fs-tools: fix build error on lz4-1.9.4

LZ4_STREAMSIZE_U64 is undefined in new lz4 lib.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
19 months agoFix format strings in log messages
Bart Van Assche [Fri, 26 Aug 2022 22:45:34 +0000 (15:45 -0700)]
Fix format strings in log messages

Make the argument list match the format string. Use PRIu64 for uint64_t
and %zu for size_t.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
19 months agofsck.f2fs: use elapsed_time in checkpoint for period check
Weichao Guo [Wed, 31 Aug 2022 08:38:26 +0000 (16:38 +0800)]
fsck.f2fs: use elapsed_time in checkpoint for period check

We now use walltime for monthly period check. However the walltime is:
* unstable(timestamp register reset) and settable(modified by user)
* unreasonable(e.g: device power-off for one month, no data changed)

When the walltime changes to the past before one month or the future
after one month, the period check in next fsck will fail to skip or
start a full scan. So, let's use the elapsed_time in checkpoint as
current time for period check.

Signed-off-by: Weichao Guo <guoweichao@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
20 months agomkfs.f2fs: catch total_zones=0 instead of crashing
Eric Biggers [Tue, 16 Aug 2022 04:48:32 +0000 (21:48 -0700)]
mkfs.f2fs: catch total_zones=0 instead of crashing

Cleanly report an error instead of dividing by 0 (causing a floating
point exception) in the following case:

truncate -s 16M img && mkfs.f2fs img

Note that this is a minimal fix; it appears that overly-small images
still cause various integer overflows in f2fs_prepare_super_block().

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
20 months agof2fs-tools: use F2FS_BLKSIZE instead of PAGE_*_SIZE
Jaegeuk Kim [Mon, 8 Aug 2022 22:18:18 +0000 (15:18 -0700)]
f2fs-tools: use F2FS_BLKSIZE instead of PAGE_*_SIZE

We don't need to check the running kernel configuration.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>