Commit Graph

1008 Commits

Author SHA1 Message Date
Chao Yu
91e7365533 f2fs_io: support unset subcommand for pinfile
This patch adds unset subcommand for pinfile command.

Usage: f2fs_io pinfile unset [target_file]

Signed-off-by: Chao Yu <chao@kernel.org>
Reviewed-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-12 20:54:18 +00:00
Sheng Yong
cc40084468 f2fs-tools: print extension list properly
The "hot file extensions" list does not print properly.

**Before**

extension_count                         [0x      23 : 35]
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    ]
hot_ext_count                           [0x       1 : 1]
hot file extentsions
db      ]
cp_payload                              [0x       0 : 0]

**After**

extension_count                         [0x      23 : 35]
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            ]
hot_ext_count                           [0x       1 : 1]
hot file extentsions
                                        [db                              ]
cp_payload                              [0x       0 : 0]

Signed-off-by: Sheng Yong <shengyong@oppo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-10 00:35:35 +00:00
Jaegeuk Kim
5da4e52415 f2fs-tools: give 6 sections for overprovision buffer
This addresses high GC cost at runtime.

Reviewed-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-04-08 18:10:33 +00:00
Daeho Jeong
f611eac6d9 f2fs-tools: reset only current zones
Send reset commands to only current zones and finish the others.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-03-11 13:37:43 -07:00
Chao Yu
151fdb1aa0 f2fs_io: support get_advise command
Support get_advise command to get i_advise field value and info
in file.

For example:
f2fs_io get_advise /mnt/f2fs/foo.so
i_advise=0x11, advise_type: cold keep_size

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-03-08 13:34:54 -08:00
Jaegeuk Kim
dc03566da7 mkfs.f2fs: should give section-aligned reserved segments
The reserved segments should be aligned to the section boundary.

Reviewed-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-03-08 13:34:51 -08:00
Jaegeuk Kim
efcff4bc16 f2fs-tools: deal with permission denial on non-root user
This fixes some android build failures due to the missing permission when
checking the loop device. Until we get a better solution, let's ignore
the error with warnings.

Reviewed-by: Huang Jianan <huangjianan@xiaomi.com>
Reviewed-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-03-06 09:42:08 -08:00
Chao Yu
4ecb90c2e3 f2fs-tools: print hexadecimal number in log
Otherwise, it will waste time to convert for comparison.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-23 14:59:40 -08:00
Chao Yu
71855932e7 f2fs-tools: use NULL_ADDR macro to instead magic number for cleanup
Use NULL_ADDR macro to instead magic number for cleanup.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-23 14:59:33 -08:00
Chao Yu
4f1ab35c65 f2fs-tools: remove obsolete fields in struct f2fs_sb_info
No logic change.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-23 14:59:17 -08:00
Chao Yu
d1225a911d mkfs.f2fs: kill heap allocation
No one uses this feature. Let's kill it.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-21 09:42:41 -08:00
Konstantin Vyshetsky
b6fad4e648 f2fs_io: add write_advice command
Add a write_advice command with same behavior as existing write command
with the exception that data should be treated as hot or cold.

Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-21 09:41:52 -08:00
Konstantin Vyshetsky
575e8e05d3 f2fs_io: override setxattr value for system.advise
Adjust behavior to match kernel.

Signed-off-by: Konstantin Vyshetsky <vkon@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-21 09:41:52 -08:00
Zhiguo Niu
ab654fcca2 f2fs-tools: add a new stop cp reason STOP_CP_REASON_NO_SEGMENT
Add a new stop cp reason STOP_CP_REASON_NO_SEGMENT for keeping
consistent with kernel codes.

Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-21 09:38:14 -08:00
Daeho Jeong
06393fda81 f2fs_io: add lseek command to execute lseek()
Added lseek command to support lseek() for SEEK_DATA and SEEK_HOLE.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-15 13:49:34 -08:00
Jaegeuk Kim
e22c886268 mkfs.f2fs: fix sparse_mode case on stat
When we turn on sparse_mode, stat() will be failed, as the file will be
created afterwards. Let's fix.

Fixes: 14197d546b ("f2fs-tools: fix to check loop device")
Reviewed-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-13 16:23:05 -08:00
Chao Yu
14197d546b f2fs-tools: fix to check loop device
Otherwise, mkfs/fsck can update backfile of moutned loop device.

1. mkfs.f2fs image
2. mount -o loop image /mnt/f2fs/
3. mkfs.f2fs image -f

Before:
...
Info: format successful

After:
...
	Error: In use by loop device!

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-07 16:25:51 -08:00
Daeho Jeong
96da467d93 f2fs-tools: allocate logs after conventional area for HM zoned devices
Make to allocate logs after conventional area for HM zoned devices to
spare them for file pinning support.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-02-07 16:22:14 -08:00
Daniel Rosenberg
eca9049a07 libf2fs: Fix possible memleak with Sparse Files
If sparse files is set along with multiple devices, we initialize
sparse file data multiple times without freeing the previously allocated
data. This skips the initialization for subsequent devices, as sparse
file mode currently only deals with device 0 anyways.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-01-29 12:14:56 -08:00
Daniel Rosenberg
9f435e3d57 libf2fs: Accept Sparse files with non 4K Blocksize
Since we may not know the block size when initializing sparse files, we
should assume that the sparse file's blocksize is correct.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-01-29 12:14:52 -08:00
Chao Yu
dff4893b49 f2fs-tools: don't call fsync on a clean image
generic/019 50s ... _check_generic_filesystem: filesystem on /dev/vdc is inconsistent
(see /media/fstests/results//generic/019.full for details)

[FSCK] Max image size: 16196 MB, Free space: 188 MB
[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0x166]
[FSCK] valid_block_count matching with CP             [Ok..] [0x3ecfe7]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x4c79]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x4c79]
[FSCK] valid_inode_count matched with CP              [Ok..] [0xb46]
[FSCK] free segment_count matched with CP             [Ok..] [0x9d]
[FSCK] next block offset is free                      [Ok..]
[FSCK] fixing SIT types
[FSCK] other corrupted bugs                           [Ok..]
        Error: Could not conduct fsync!!!

Generic/019 will trigger fsync() on a clean image, but it will fail
due to simulated failure on disk, result in testcase failure.

Let's add c.need_fsync to record dirty status of image, and only trigger
fsync() when there is dirty data in image.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-01-26 00:40:27 -08:00
Chao Yu
54f637a965 fsck.f2fs: fix to avoid assert in do_record_fsync_data()
As Kane Ch'in reported in bugzilla [1]

I am using some Debian VMs with f2fs root partition for development.
My host machine crashed for some reason and this caused the f2fs
partitions in the VMs to become corrupted. I tried to boot from Debian
Live and repair the partitions but failed.

do_record_fsync_data: [node] ino = 24573, nid = 0, blkaddr = 2063580
recover_data: ino = 24573, nid = 0, recorded = 0, err = 0
do_record_fsync_data: [node] ino = 471286, nid = 0, blkaddr = 2063581
recover_data: ino = 471286, nid = 0, recorded = 0, err = 0
[ASSERT] (do_record_fsync_data:3475) 0

During do_record_fsync_data(), if dnode in warm node chain is valid in
SIT table, it's better to continue checking rather than triggering
assert().

[1] https://bugzilla.kernel.org/show_bug.cgi?id=218349

Reported-by: Kane Ch'in <qinfd2023@lzu.edu.cn>
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2024-01-16 10:47:37 -08:00
Wu Bo
fa3bb83a48 fsck.f2fs: fix orphan inode check fail
Call path:
fsck_chk_orphan_node
  fsck_chk_node_blk
    fsck_chk_inode_blk

'F2FS_FT_ORPHAN' will pass to fsck_chk_inode_blk(). If the orphan inode
is a DIR, it will be wrongly fixed.

Fixes: 8fd836f ("fsck: clear unexpected casefold flags")
Signed-off-by: Wu Bo <bo.wu@vivo.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-12-15 15:07:41 -08:00
Daniel Rosenberg
bf5100606d man: Add description for mkfs -b option
Describes the block size option -b. This sets the block size, which is
restricted to powers of 2. The linux kernel currently requires that the
block size be equal to the page size to mount.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-12-08 10:12:32 -08:00
Daeho Jeong
1cbaa9069e f2fs-tools: skip finishing zones for current zones
Do not finishing zones for current zones.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Fixes: 06a25b021d ("f2fs-tools: make six open zone check resilient")
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-12-04 17:17:06 -08:00
Jaegeuk Kim
f2ae743ca9 fsck.f2fs: run full scan if checkpoint is disabled
Let's fix any inconsistency until checkpint being enabled back.

Reviewed-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-12-04 17:16:27 -08:00
Daeho Jeong
10dad5ed7c f2fs-tools: support zoned ufs devices
Support zoned ufs devices.
1. implemented out-place updates
2. keep roll forward recovery intact
3. open block device files with O_SYNC to comply with zoned device's
   write rules

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-30 12:04:42 -08:00
Daeho Jeong
83e64044de f2fs-tools: convert lost+found dir to regular dentry before adding nodes
fsck doesn't support adding inodes to inline dentries. So, need to
convert inline lost+found dentry before adding missing inodes.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-29 17:25:41 -08:00
Maxim Korotkov
00efc38bb9 f2fs-tools: fixed incorrect error handling
Case of failed memory allocation of dev->zone_cap_blocks
doesn't release heap allocated rep
Found by RASU JSC
Fixes: f8410857b7a8(f2fs-tools: zns zone-capacity support)
Signed-off-by: Maxim Korotkov <maskorotkov@rasu.ru>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-28 10:55:59 -08:00
Daeho Jeong
68abdf360a f2fs-tools: adjust nat and block release logic
Fixes: 0f503e443c ("f2fs-tools: do not reuse corrupted quota inodes")
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-28 10:55:59 -08:00
Daniel Rosenberg
444c048c15 f2fs-tools: Fix dqb_curspace to reflect blocksize
The initial sizes for dqblk.dqb_curspace should reflect the block size,
as that's the minimal filesize.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-28 10:55:59 -08:00
Daniel Rosenberg
97af7a106e f2fs-tools: Wait for Block Size to initialize Cache
The cache is initialized during the first read, however, it requires the
block size to establish its buffer. This disables the cache until the
block size is known.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-28 10:55:59 -08:00
Daniel Rosenberg
779bc50606 f2fs-tools: Fix debug size print
The conversion from block size to MB in this debug statement assumes a
block size of 4K. This switches it to properly use the filesystem's
block size.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-28 10:55:50 -08:00
zangyangyang1
370d070e02 libf2fs: Fix using uninitialized variables error in get_device_info()
This issue comes from a static code scanning tool.
When c.sparse_mode is 1, stat_buf will not be initialized,
but it will be used next.
If this issue does not require modification, please ignore this commit.

Signed-off-by: zangyangyang1 <zangyangyang1@xiaomi.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-17 09:26:56 -08:00
Daeho Jeong
5e7ebf1278 f2fs-tools: initialize user cache valid values
Need to initialize user cache valid values to prevent from providing
false cache entries.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-09 15:38:39 -08:00
Daeho Jeong
f71fbf8f3d f2fs-tools: synchronize nat journal with nat cache
Make nat journal and nat cache have the same content.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-11-08 09:29:16 -08:00
Jaegeuk Kim
a354b4b804 fsck.f2fs: wrong report on xattr boundary
This avoids false alarm on xfstests/generic/425.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-10-28 16:43:56 -07:00
Jaegeuk Kim
c5f03172b5 f2fs-tools: use F2FS_BLKSIZE by default
No need to do

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-10-28 16:42:59 -07:00
Daeho Jeong
8395c42a9a f2fs-tools: do not put CP_UMOUNT_FLAG for roll forward recovery
If we write CP_UMOUNT_FLAG in fsck, f2fs will not do foll forward recovery
even though it has to do.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-10-27 15:46:46 -07:00
Daeho Jeong
96f809cf4e f2fs-tools: use total_node_count when creating a new node block in fsck
We might allocate more node blocks than total_valid_node_count, when we
recreate quota files.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-10-27 15:46:36 -07:00
Daeho Jeong
06a25b021d f2fs-tools: make six open zone check resilient
We need to make sure to finish all the zones except six open zones. In
a case of that the previous mount wasn't successfully unmounted, we have
to change all the current segments.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-10-26 18:37:58 -07:00
Eric Biggers
d860afaebd 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>
2023-10-25 20:06:26 -07:00
Daeho Jeong
c9009e00d4 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>
2023-10-25 20:06:21 -07:00
Daeho Jeong
0f503e443c 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>
2023-10-25 20:06:20 -07:00
Jaegeuk Kim
eea39f1207 f2fs_io: add list/set/removexattr command
Let's add list/set/removexattrs commands.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-10-19 19:07:24 -07:00
Chao Yu
628fe15af4 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>
2023-10-17 13:15:58 -07:00
Jaegeuk Kim
13e9d9f71f 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>
2023-10-16 16:14:20 -07:00
Jaegeuk Kim
efcb92448d Revert "f2fs-tools: do not support user-space cache"
This reverts commit 2835107ae3.

There's a report that the impact was true.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
2023-10-16 16:14:04 -07:00
Daeho Jeong
b6e5183f4b 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>
2023-10-11 17:30:40 -07:00
Daeho Jeong
4d811ae0c1 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>
2023-10-03 15:53:09 -07:00