Skip to content

Commit 44b4d13

Browse files
committed
Merge tag 'f2fs-for-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs updates from Jaegeuk Kim: "This series introduces a device aliasing feature where user can carve out partitions but reclaim the space back by deleting aliased file in root dir. In addition to that, there're numerous minor bug fixes in zoned device support, checkpoint=disable, extent cache management, fiemap, and lazytime mount option. The full list of noticeable changes can be found below. Enhancements: - introduce device aliasing file - add stats in debugfs to show multiple devices - add a sysfs node to limit max read extent count per-inode - modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable - decrease spare area for pinned files for zoned devices Fixes: - Revert "f2fs: remove unreachable lazytime mount option parsing" - adjust unusable cap before checkpoint=disable mode - fix to drop all discards after creating snapshot on lvm device - fix to shrink read extent node in batches - fix changing cursegs if recovery fails on zoned device - fix to adjust appropriate length for fiemap - fix fiemap failure issue when page size is 16KB - fix to avoid forcing direct write to use buffered IO on inline_data inode - fix to map blocks correctly for direct write - fix to account dirty data in __get_secs_required() - fix null-ptr-deref in f2fs_submit_page_bio() - fix inconsistent update of i_blocks in release_compress_blocks and reserve_compress_blocks" * tag 'f2fs-for-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (40 commits) f2fs: fix to drop all discards after creating snapshot on lvm device f2fs: add a sysfs node to limit max read extent count per-inode f2fs: fix to shrink read extent node in batches f2fs: print message if fscorrupted was found in f2fs_new_node_page() f2fs: clear SBI_POR_DOING before initing inmem curseg f2fs: fix changing cursegs if recovery fails on zoned device f2fs: adjust unusable cap before checkpoint=disable mode f2fs: fix to requery extent which cross boundary of inquiry f2fs: fix to adjust appropriate length for fiemap f2fs: clean up w/ F2FS_{BLK_TO_BYTES,BTYES_TO_BLK} f2fs: fix to do cast in F2FS_{BLK_TO_BYTES, BTYES_TO_BLK} to avoid overflow f2fs: replace deprecated strcpy with strscpy Revert "f2fs: remove unreachable lazytime mount option parsing" f2fs: fix to avoid forcing direct write to use buffered IO on inline_data inode f2fs: fix to map blocks correctly for direct write f2fs: fix race in concurrent f2fs_stop_gc_thread f2fs: fix fiemap failure issue when page size is 16KB f2fs: remove redundant atomic file check in defragment f2fs: fix to convert log type to segment data type correctly f2fs: clean up the unused variable additional_reserved_segments ...
2 parents fb527fc + bc8aeb0 commit 44b4d13

File tree

20 files changed

+700
-255
lines changed

20 files changed

+700
-255
lines changed

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,13 @@ Description: Do background GC aggressively when set. Set to 0 by default.
311311
GC approach and turns SSR mode on.
312312
gc urgent low(2): lowers the bar of checking I/O idling in
313313
order to process outstanding discard commands and GC a
314-
little bit aggressively. uses cost benefit GC approach.
314+
little bit aggressively. always uses cost benefit GC approach,
315+
and will override age-threshold GC approach if ATGC is enabled
316+
at the same time.
315317
gc urgent mid(3): does GC forcibly in a period of given
316318
gc_urgent_sleep_time and executes a mid level of I/O idling check.
317-
uses cost benefit GC approach.
319+
always uses cost benefit GC approach, and will override
320+
age-threshold GC approach if ATGC is enabled at the same time.
318321

319322
What: /sys/fs/f2fs/<disk>/gc_urgent_sleep_time
320323
Date: August 2017
@@ -819,3 +822,9 @@ Description: It controls the valid block ratio threshold not to trigger excessiv
819822
for zoned deivces. The initial value of it is 95(%). F2FS will stop the
820823
background GC thread from intiating GC for sections having valid blocks
821824
exceeding the ratio.
825+
826+
What: /sys/fs/f2fs/<disk>/max_read_extent_count
827+
Date: November 2024
828+
Contact: "Chao Yu" <chao@kernel.org>
829+
Description: It controls max read extent count for per-inode, the value of threshold
830+
is 10240 by default.

Documentation/filesystems/f2fs.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,3 +943,47 @@ NVMe Zoned Namespace devices
943943
can start before the zone-capacity and span across zone-capacity boundary.
944944
Such spanning segments are also considered as usable segments. All blocks
945945
past the zone-capacity are considered unusable in these segments.
946+
947+
Device aliasing feature
948+
-----------------------
949+
950+
f2fs can utilize a special file called a "device aliasing file." This file allows
951+
the entire storage device to be mapped with a single, large extent, not using
952+
the usual f2fs node structures. This mapped area is pinned and primarily intended
953+
for holding the space.
954+
955+
Essentially, this mechanism allows a portion of the f2fs area to be temporarily
956+
reserved and used by another filesystem or for different purposes. Once that
957+
external usage is complete, the device aliasing file can be deleted, releasing
958+
the reserved space back to F2FS for its own use.
959+
960+
<use-case>
961+
962+
# ls /dev/vd*
963+
/dev/vdb (32GB) /dev/vdc (32GB)
964+
# mkfs.ext4 /dev/vdc
965+
# mkfs.f2fs -c /dev/vdc@vdc.file /dev/vdb
966+
# mount /dev/vdb /mnt/f2fs
967+
# ls -l /mnt/f2fs
968+
vdc.file
969+
# df -h
970+
/dev/vdb 64G 33G 32G 52% /mnt/f2fs
971+
972+
# mount -o loop /dev/vdc /mnt/ext4
973+
# df -h
974+
/dev/vdb 64G 33G 32G 52% /mnt/f2fs
975+
/dev/loop7 32G 24K 30G 1% /mnt/ext4
976+
# umount /mnt/ext4
977+
978+
# f2fs_io getflags /mnt/f2fs/vdc.file
979+
get a flag on /mnt/f2fs/vdc.file ret=0, flags=nocow(pinned),immutable
980+
# f2fs_io setflags noimmutable /mnt/f2fs/vdc.file
981+
get a flag on noimmutable ret=0, flags=800010
982+
set a flag on /mnt/f2fs/vdc.file ret=0, flags=noimmutable
983+
# rm /mnt/f2fs/vdc.file
984+
# df -h
985+
/dev/vdb 64G 753M 64G 2% /mnt/f2fs
986+
987+
So, the key idea is, user can do any file operations on /dev/vdc, and
988+
reclaim the space after the use, while the space is counted as /data.
989+
That doesn't require modifying partition size and filesystem format.

fs/f2fs/acl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,8 @@ static struct posix_acl *f2fs_acl_clone(const struct posix_acl *acl,
296296
struct posix_acl *clone = NULL;
297297

298298
if (acl) {
299-
int size = sizeof(struct posix_acl) + acl->a_count *
300-
sizeof(struct posix_acl_entry);
301-
clone = kmemdup(acl, size, flags);
299+
clone = kmemdup(acl, struct_size(acl, a_entries, acl->a_count),
300+
flags);
302301
if (clone)
303302
refcount_set(&clone->a_refcount, 1);
304303
}

fs/f2fs/checkpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io,
3232
f2fs_build_fault_attr(sbi, 0, 0);
3333
if (!end_io)
3434
f2fs_flush_merged_writes(sbi);
35-
f2fs_handle_critical_error(sbi, reason, end_io);
35+
f2fs_handle_critical_error(sbi, reason);
3636
}
3737

3838
/*

fs/f2fs/data.c

Lines changed: 50 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
16791679
/* reserved delalloc block should be mapped for fiemap. */
16801680
if (blkaddr == NEW_ADDR)
16811681
map->m_flags |= F2FS_MAP_DELALLOC;
1682-
if (flag != F2FS_GET_BLOCK_DIO || !is_hole)
1682+
/* DIO READ and hole case, should not map the blocks. */
1683+
if (!(flag == F2FS_GET_BLOCK_DIO && is_hole && !map->m_may_create))
16831684
map->m_flags |= F2FS_MAP_MAPPED;
16841685

16851686
map->m_pblk = blkaddr;
@@ -1821,16 +1822,6 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
18211822
return true;
18221823
}
18231824

1824-
static inline u64 bytes_to_blks(struct inode *inode, u64 bytes)
1825-
{
1826-
return (bytes >> inode->i_blkbits);
1827-
}
1828-
1829-
static inline u64 blks_to_bytes(struct inode *inode, u64 blks)
1830-
{
1831-
return (blks << inode->i_blkbits);
1832-
}
1833-
18341825
static int f2fs_xattr_fiemap(struct inode *inode,
18351826
struct fiemap_extent_info *fieinfo)
18361827
{
@@ -1856,7 +1847,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,
18561847
return err;
18571848
}
18581849

1859-
phys = blks_to_bytes(inode, ni.blk_addr);
1850+
phys = F2FS_BLK_TO_BYTES(ni.blk_addr);
18601851
offset = offsetof(struct f2fs_inode, i_addr) +
18611852
sizeof(__le32) * (DEF_ADDRS_PER_INODE -
18621853
get_inline_xattr_addrs(inode));
@@ -1888,7 +1879,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,
18881879
return err;
18891880
}
18901881

1891-
phys = blks_to_bytes(inode, ni.blk_addr);
1882+
phys = F2FS_BLK_TO_BYTES(ni.blk_addr);
18921883
len = inode->i_sb->s_blocksize;
18931884

18941885
f2fs_put_page(page, 1);
@@ -1904,30 +1895,11 @@ static int f2fs_xattr_fiemap(struct inode *inode,
19041895
return (err < 0 ? err : 0);
19051896
}
19061897

1907-
static loff_t max_inode_blocks(struct inode *inode)
1908-
{
1909-
loff_t result = ADDRS_PER_INODE(inode);
1910-
loff_t leaf_count = ADDRS_PER_BLOCK(inode);
1911-
1912-
/* two direct node blocks */
1913-
result += (leaf_count * 2);
1914-
1915-
/* two indirect node blocks */
1916-
leaf_count *= NIDS_PER_BLOCK;
1917-
result += (leaf_count * 2);
1918-
1919-
/* one double indirect node block */
1920-
leaf_count *= NIDS_PER_BLOCK;
1921-
result += leaf_count;
1922-
1923-
return result;
1924-
}
1925-
19261898
int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
19271899
u64 start, u64 len)
19281900
{
19291901
struct f2fs_map_blocks map;
1930-
sector_t start_blk, last_blk;
1902+
sector_t start_blk, last_blk, blk_len, max_len;
19311903
pgoff_t next_pgofs;
19321904
u64 logical = 0, phys = 0, size = 0;
19331905
u32 flags = 0;
@@ -1969,16 +1941,15 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
19691941
goto out;
19701942
}
19711943

1972-
if (bytes_to_blks(inode, len) == 0)
1973-
len = blks_to_bytes(inode, 1);
1974-
1975-
start_blk = bytes_to_blks(inode, start);
1976-
last_blk = bytes_to_blks(inode, start + len - 1);
1944+
start_blk = F2FS_BYTES_TO_BLK(start);
1945+
last_blk = F2FS_BYTES_TO_BLK(start + len - 1);
1946+
blk_len = last_blk - start_blk + 1;
1947+
max_len = F2FS_BYTES_TO_BLK(maxbytes) - start_blk;
19771948

19781949
next:
19791950
memset(&map, 0, sizeof(map));
19801951
map.m_lblk = start_blk;
1981-
map.m_len = bytes_to_blks(inode, len);
1952+
map.m_len = blk_len;
19821953
map.m_next_pgofs = &next_pgofs;
19831954
map.m_seg_type = NO_CHECK_TYPE;
19841955

@@ -1995,13 +1966,23 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
19951966
if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) {
19961967
start_blk = next_pgofs;
19971968

1998-
if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
1999-
max_inode_blocks(inode)))
1969+
if (F2FS_BLK_TO_BYTES(start_blk) < maxbytes)
20001970
goto prep_next;
20011971

20021972
flags |= FIEMAP_EXTENT_LAST;
20031973
}
20041974

1975+
/*
1976+
* current extent may cross boundary of inquiry, increase len to
1977+
* requery.
1978+
*/
1979+
if (!compr_cluster && (map.m_flags & F2FS_MAP_MAPPED) &&
1980+
map.m_lblk + map.m_len - 1 == last_blk &&
1981+
blk_len != max_len) {
1982+
blk_len = max_len;
1983+
goto next;
1984+
}
1985+
20051986
compr_appended = false;
20061987
/* In a case of compressed cluster, append this to the last extent */
20071988
if (compr_cluster && ((map.m_flags & F2FS_MAP_DELALLOC) ||
@@ -2033,28 +2014,28 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
20332014
} else if (compr_appended) {
20342015
unsigned int appended_blks = cluster_size -
20352016
count_in_cluster + 1;
2036-
size += blks_to_bytes(inode, appended_blks);
2017+
size += F2FS_BLK_TO_BYTES(appended_blks);
20372018
start_blk += appended_blks;
20382019
compr_cluster = false;
20392020
} else {
2040-
logical = blks_to_bytes(inode, start_blk);
2021+
logical = F2FS_BLK_TO_BYTES(start_blk);
20412022
phys = __is_valid_data_blkaddr(map.m_pblk) ?
2042-
blks_to_bytes(inode, map.m_pblk) : 0;
2043-
size = blks_to_bytes(inode, map.m_len);
2023+
F2FS_BLK_TO_BYTES(map.m_pblk) : 0;
2024+
size = F2FS_BLK_TO_BYTES(map.m_len);
20442025
flags = 0;
20452026

20462027
if (compr_cluster) {
20472028
flags = FIEMAP_EXTENT_ENCODED;
20482029
count_in_cluster += map.m_len;
20492030
if (count_in_cluster == cluster_size) {
20502031
compr_cluster = false;
2051-
size += blks_to_bytes(inode, 1);
2032+
size += F2FS_BLKSIZE;
20522033
}
20532034
} else if (map.m_flags & F2FS_MAP_DELALLOC) {
20542035
flags = FIEMAP_EXTENT_UNWRITTEN;
20552036
}
20562037

2057-
start_blk += bytes_to_blks(inode, size);
2038+
start_blk += F2FS_BYTES_TO_BLK(size);
20582039
}
20592040

20602041
prep_next:
@@ -2092,7 +2073,7 @@ static int f2fs_read_single_page(struct inode *inode, struct folio *folio,
20922073
struct readahead_control *rac)
20932074
{
20942075
struct bio *bio = *bio_ret;
2095-
const unsigned blocksize = blks_to_bytes(inode, 1);
2076+
const unsigned int blocksize = F2FS_BLKSIZE;
20962077
sector_t block_in_file;
20972078
sector_t last_block;
20982079
sector_t last_block_in_file;
@@ -2102,8 +2083,8 @@ static int f2fs_read_single_page(struct inode *inode, struct folio *folio,
21022083

21032084
block_in_file = (sector_t)index;
21042085
last_block = block_in_file + nr_pages;
2105-
last_block_in_file = bytes_to_blks(inode,
2106-
f2fs_readpage_limit(inode) + blocksize - 1);
2086+
last_block_in_file = F2FS_BYTES_TO_BLK(f2fs_readpage_limit(inode) +
2087+
blocksize - 1);
21072088
if (last_block > last_block_in_file)
21082089
last_block = last_block_in_file;
21092090

@@ -2203,7 +2184,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
22032184
struct bio *bio = *bio_ret;
22042185
unsigned int start_idx = cc->cluster_idx << cc->log_cluster_size;
22052186
sector_t last_block_in_file;
2206-
const unsigned blocksize = blks_to_bytes(inode, 1);
2187+
const unsigned int blocksize = F2FS_BLKSIZE;
22072188
struct decompress_io_ctx *dic = NULL;
22082189
struct extent_info ei = {};
22092190
bool from_dnode = true;
@@ -2212,8 +2193,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
22122193

22132194
f2fs_bug_on(sbi, f2fs_cluster_is_empty(cc));
22142195

2215-
last_block_in_file = bytes_to_blks(inode,
2216-
f2fs_readpage_limit(inode) + blocksize - 1);
2196+
last_block_in_file = F2FS_BYTES_TO_BLK(f2fs_readpage_limit(inode) +
2197+
blocksize - 1);
22172198

22182199
/* get rid of pages beyond EOF */
22192200
for (i = 0; i < cc->cluster_size; i++) {
@@ -2388,10 +2369,10 @@ static int f2fs_mpage_readpages(struct inode *inode,
23882369
.nr_cpages = 0,
23892370
};
23902371
pgoff_t nc_cluster_idx = NULL_CLUSTER;
2372+
pgoff_t index;
23912373
#endif
23922374
unsigned nr_pages = rac ? readahead_count(rac) : 1;
23932375
unsigned max_nr_pages = nr_pages;
2394-
pgoff_t index;
23952376
int ret = 0;
23962377

23972378
map.m_pblk = 0;
@@ -2409,9 +2390,9 @@ static int f2fs_mpage_readpages(struct inode *inode,
24092390
prefetchw(&folio->flags);
24102391
}
24112392

2393+
#ifdef CONFIG_F2FS_FS_COMPRESSION
24122394
index = folio_index(folio);
24132395

2414-
#ifdef CONFIG_F2FS_FS_COMPRESSION
24152396
if (!f2fs_compressed_file(inode))
24162397
goto read_single_page;
24172398

@@ -3444,6 +3425,11 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
34443425

34453426
if (!f2fs_lookup_read_extent_cache_block(inode, index,
34463427
&dn.data_blkaddr)) {
3428+
if (IS_DEVICE_ALIASING(inode)) {
3429+
err = -ENODATA;
3430+
goto out;
3431+
}
3432+
34473433
if (locked) {
34483434
err = f2fs_reserve_block(&dn, index);
34493435
goto out;
@@ -3974,7 +3960,7 @@ static int check_swap_activate(struct swap_info_struct *sis,
39743960
* to be very smart.
39753961
*/
39763962
cur_lblock = 0;
3977-
last_lblock = bytes_to_blks(inode, i_size_read(inode));
3963+
last_lblock = F2FS_BYTES_TO_BLK(i_size_read(inode));
39783964

39793965
while (cur_lblock < last_lblock && cur_lblock < sis->max) {
39803966
struct f2fs_map_blocks map;
@@ -4217,8 +4203,8 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
42174203
pgoff_t next_pgofs = 0;
42184204
int err;
42194205

4220-
map.m_lblk = bytes_to_blks(inode, offset);
4221-
map.m_len = bytes_to_blks(inode, offset + length - 1) - map.m_lblk + 1;
4206+
map.m_lblk = F2FS_BYTES_TO_BLK(offset);
4207+
map.m_len = F2FS_BYTES_TO_BLK(offset + length - 1) - map.m_lblk + 1;
42224208
map.m_next_pgofs = &next_pgofs;
42234209
map.m_seg_type = f2fs_rw_hint_to_seg_type(F2FS_I_SB(inode),
42244210
inode->i_write_hint);
@@ -4229,7 +4215,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
42294215
if (err)
42304216
return err;
42314217

4232-
iomap->offset = blks_to_bytes(inode, map.m_lblk);
4218+
iomap->offset = F2FS_BLK_TO_BYTES(map.m_lblk);
42334219

42344220
/*
42354221
* When inline encryption is enabled, sometimes I/O to an encrypted file
@@ -4249,21 +4235,21 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
42494235
if (WARN_ON_ONCE(map.m_pblk == NEW_ADDR))
42504236
return -EINVAL;
42514237

4252-
iomap->length = blks_to_bytes(inode, map.m_len);
4238+
iomap->length = F2FS_BLK_TO_BYTES(map.m_len);
42534239
iomap->type = IOMAP_MAPPED;
42544240
iomap->flags |= IOMAP_F_MERGED;
42554241
iomap->bdev = map.m_bdev;
4256-
iomap->addr = blks_to_bytes(inode, map.m_pblk);
4242+
iomap->addr = F2FS_BLK_TO_BYTES(map.m_pblk);
42574243
} else {
42584244
if (flags & IOMAP_WRITE)
42594245
return -ENOTBLK;
42604246

42614247
if (map.m_pblk == NULL_ADDR) {
4262-
iomap->length = blks_to_bytes(inode, next_pgofs) -
4263-
iomap->offset;
4248+
iomap->length = F2FS_BLK_TO_BYTES(next_pgofs) -
4249+
iomap->offset;
42644250
iomap->type = IOMAP_HOLE;
42654251
} else if (map.m_pblk == NEW_ADDR) {
4266-
iomap->length = blks_to_bytes(inode, map.m_len);
4252+
iomap->length = F2FS_BLK_TO_BYTES(map.m_len);
42674253
iomap->type = IOMAP_UNWRITTEN;
42684254
} else {
42694255
f2fs_bug_on(F2FS_I_SB(inode), 1);

0 commit comments

Comments
 (0)