Skip to content

Commit d7e9a90

Browse files
drosen-googleJaegeuk Kim
authored andcommitted
f2fs: Support Block Size == Page Size
This allows f2fs to support cases where the block size = page size for both 4K and 16K block sizes. Other sizes should work as well, should the need arise. This does not currently support 4K Block size filesystems if the page size is 16K. Signed-off-by: Daniel Rosenberg <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 4ed33e6 commit d7e9a90

File tree

5 files changed

+46
-33
lines changed

5 files changed

+46
-33
lines changed

fs/f2fs/data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4076,7 +4076,7 @@ static int check_swap_activate(struct swap_info_struct *sis,
40764076
sis->highest_bit = cur_lblock - 1;
40774077
out:
40784078
if (not_aligned)
4079-
f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%u * N)",
4079+
f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)",
40804080
not_aligned, blks_per_sec * F2FS_BLKSIZE);
40814081
return ret;
40824082
}

fs/f2fs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
315315
f2fs_has_inline_xattr(inode) &&
316316
(!fi->i_inline_xattr_size ||
317317
fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE)) {
318-
f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_inline_xattr_size: %d, max: %zu",
318+
f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_inline_xattr_size: %d, max: %lu",
319319
__func__, inode->i_ino, fi->i_inline_xattr_size,
320320
MAX_INLINE_XATTR_SIZE);
321321
return false;

fs/f2fs/node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ static void f2fs_ra_node_pages(struct page *parent, int start, int n)
633633

634634
/* Then, try readahead for siblings of the desired node */
635635
end = start + n;
636-
end = min(end, NIDS_PER_BLOCK);
636+
end = min(end, (int)NIDS_PER_BLOCK);
637637
for (i = start; i < end; i++) {
638638
nid = get_nid(parent, i, false);
639639
f2fs_ra_node_page(sbi, nid);

fs/f2fs/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,7 +3502,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
35023502
return -EFSCORRUPTED;
35033503
}
35043504

3505-
/* Currently, support 512/1024/2048/4096 bytes sector size */
3505+
/* Currently, support 512/1024/2048/4096/16K bytes sector size */
35063506
if (le32_to_cpu(raw_super->log_sectorsize) >
35073507
F2FS_MAX_LOG_SECTOR_SIZE ||
35083508
le32_to_cpu(raw_super->log_sectorsize) <
@@ -4948,7 +4948,7 @@ static int __init init_f2fs_fs(void)
49484948
int err;
49494949

49504950
if (PAGE_SIZE != F2FS_BLKSIZE) {
4951-
printk("F2FS not supported on PAGE_SIZE(%lu) != %d\n",
4951+
printk("F2FS not supported on PAGE_SIZE(%lu) != BLOCK_SIZE(%lu)\n",
49524952
PAGE_SIZE, F2FS_BLKSIZE);
49534953
return -EINVAL;
49544954
}

include/linux/f2fs_fs.h

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
#define F2FS_SUPER_OFFSET 1024 /* byte-size offset */
1515
#define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */
16-
#define F2FS_MAX_LOG_SECTOR_SIZE 12 /* 12 bits for 4096 bytes */
17-
#define F2FS_LOG_SECTORS_PER_BLOCK 3 /* log number for sector/blk */
18-
#define F2FS_BLKSIZE 4096 /* support only 4KB block */
19-
#define F2FS_BLKSIZE_BITS 12 /* bits for F2FS_BLKSIZE */
16+
#define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */
17+
#define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sector/blk */
18+
#define F2FS_BLKSIZE PAGE_SIZE /* support only block == page */
19+
#define F2FS_BLKSIZE_BITS PAGE_SHIFT /* bits for F2FS_BLKSIZE */
2020
#define F2FS_MAX_EXTENSION 64 /* # of extension entries */
2121
#define F2FS_EXTENSION_LEN 8 /* max size of extension */
2222
#define F2FS_BLK_ALIGN(x) (((x) + F2FS_BLKSIZE - 1) >> F2FS_BLKSIZE_BITS)
@@ -210,14 +210,14 @@ struct f2fs_checkpoint {
210210
unsigned char sit_nat_version_bitmap[];
211211
} __packed;
212212

213-
#define CP_CHKSUM_OFFSET 4092 /* default chksum offset in checkpoint */
213+
#define CP_CHKSUM_OFFSET (F2FS_BLKSIZE - sizeof(__le32)) /* default chksum offset in checkpoint */
214214
#define CP_MIN_CHKSUM_OFFSET \
215215
(offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap))
216216

217217
/*
218218
* For orphan inode management
219219
*/
220-
#define F2FS_ORPHANS_PER_BLOCK 1020
220+
#define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / sizeof(__le32))
221221

222222
#define GET_ORPHAN_BLOCKS(n) (((n) + F2FS_ORPHANS_PER_BLOCK - 1) / \
223223
F2FS_ORPHANS_PER_BLOCK)
@@ -243,14 +243,31 @@ struct f2fs_extent {
243243
#define F2FS_NAME_LEN 255
244244
/* 200 bytes for inline xattrs by default */
245245
#define DEFAULT_INLINE_XATTR_ADDRS 50
246-
#define DEF_ADDRS_PER_INODE 923 /* Address Pointers in an Inode */
246+
247+
#define OFFSET_OF_END_OF_I_EXT 360
248+
#define SIZE_OF_I_NID 20
249+
250+
struct node_footer {
251+
__le32 nid; /* node id */
252+
__le32 ino; /* inode number */
253+
__le32 flag; /* include cold/fsync/dentry marks and offset */
254+
__le64 cp_ver; /* checkpoint version */
255+
__le32 next_blkaddr; /* next node page block address */
256+
} __packed;
257+
258+
/* Address Pointers in an Inode */
259+
#define DEF_ADDRS_PER_INODE ((F2FS_BLKSIZE - OFFSET_OF_END_OF_I_EXT \
260+
- SIZE_OF_I_NID \
261+
- sizeof(struct node_footer)) / sizeof(__le32))
247262
#define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \
248263
get_extra_isize(inode))
249264
#define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */
250265
#define ADDRS_PER_INODE(inode) addrs_per_inode(inode)
251-
#define DEF_ADDRS_PER_BLOCK 1018 /* Address Pointers in a Direct Block */
266+
/* Address Pointers in a Direct Block */
267+
#define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32))
252268
#define ADDRS_PER_BLOCK(inode) addrs_per_block(inode)
253-
#define NIDS_PER_BLOCK 1018 /* Node IDs in an Indirect Block */
269+
/* Node IDs in an Indirect Block */
270+
#define NIDS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32))
254271

255272
#define ADDRS_PER_PAGE(page, inode) \
256273
(IS_INODE(page) ? ADDRS_PER_INODE(inode) : ADDRS_PER_BLOCK(inode))
@@ -342,14 +359,6 @@ enum {
342359

343360
#define OFFSET_BIT_MASK GENMASK(OFFSET_BIT_SHIFT - 1, 0)
344361

345-
struct node_footer {
346-
__le32 nid; /* node id */
347-
__le32 ino; /* inode number */
348-
__le32 flag; /* include cold/fsync/dentry marks and offset */
349-
__le64 cp_ver; /* checkpoint version */
350-
__le32 next_blkaddr; /* next node page block address */
351-
} __packed;
352-
353362
struct f2fs_node {
354363
/* can be one of three types: inode, direct, and indirect types */
355364
union {
@@ -363,7 +372,7 @@ struct f2fs_node {
363372
/*
364373
* For NAT entries
365374
*/
366-
#define NAT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_nat_entry))
375+
#define NAT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_nat_entry))
367376

368377
struct f2fs_nat_entry {
369378
__u8 version; /* latest version of cached nat entry */
@@ -378,12 +387,13 @@ struct f2fs_nat_block {
378387
/*
379388
* For SIT entries
380389
*
381-
* Each segment is 2MB in size by default so that a bitmap for validity of
382-
* there-in blocks should occupy 64 bytes, 512 bits.
390+
* A validity bitmap of 64 bytes covers 512 blocks of area. For a 4K page size,
391+
* this results in a segment size of 2MB. For 16k pages, the default segment size
392+
* is 8MB.
383393
* Not allow to change this.
384394
*/
385395
#define SIT_VBLOCK_MAP_SIZE 64
386-
#define SIT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_sit_entry))
396+
#define SIT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_sit_entry))
387397

388398
/*
389399
* F2FS uses 4 bytes to represent block address. As a result, supported size of
@@ -418,7 +428,7 @@ struct f2fs_sit_block {
418428
* For segment summary
419429
*
420430
* One summary block contains exactly 512 summary entries, which represents
421-
* exactly 2MB segment by default. Not allow to change the basic units.
431+
* exactly one segment by default. Not allow to change the basic units.
422432
*
423433
* NOTE: For initializing fields, you must use set_summary
424434
*
@@ -429,12 +439,12 @@ struct f2fs_sit_block {
429439
* from node's page's beginning to get a data block address.
430440
* ex) data_blkaddr = (block_t)(nodepage_start_address + ofs_in_node)
431441
*/
432-
#define ENTRIES_IN_SUM 512
442+
#define ENTRIES_IN_SUM (F2FS_BLKSIZE / 8)
433443
#define SUMMARY_SIZE (7) /* sizeof(struct summary) */
434444
#define SUM_FOOTER_SIZE (5) /* sizeof(struct summary_footer) */
435445
#define SUM_ENTRY_SIZE (SUMMARY_SIZE * ENTRIES_IN_SUM)
436446

437-
/* a summary entry for a 4KB-sized block in a segment */
447+
/* a summary entry for a block in a segment */
438448
struct f2fs_summary {
439449
__le32 nid; /* parent node id */
440450
union {
@@ -518,7 +528,7 @@ struct f2fs_journal {
518528
};
519529
} __packed;
520530

521-
/* 4KB-sized summary block structure */
531+
/* Block-sized summary block structure */
522532
struct f2fs_summary_block {
523533
struct f2fs_summary entries[ENTRIES_IN_SUM];
524534
struct f2fs_journal journal;
@@ -559,11 +569,14 @@ typedef __le32 f2fs_hash_t;
559569
* Note: there are more reserved space in inline dentry than in regular
560570
* dentry, when converting inline dentry we should handle this carefully.
561571
*/
562-
#define NR_DENTRY_IN_BLOCK 214 /* the number of dentry in a block */
572+
573+
/* the number of dentry in a block */
574+
#define NR_DENTRY_IN_BLOCK ((BITS_PER_BYTE * F2FS_BLKSIZE) / \
575+
((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1))
563576
#define SIZE_OF_DIR_ENTRY 11 /* by byte */
564577
#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \
565578
BITS_PER_BYTE)
566-
#define SIZE_OF_RESERVED (PAGE_SIZE - ((SIZE_OF_DIR_ENTRY + \
579+
#define SIZE_OF_RESERVED (F2FS_BLKSIZE - ((SIZE_OF_DIR_ENTRY + \
567580
F2FS_SLOT_LEN) * \
568581
NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP))
569582
#define MIN_INLINE_DENTRY_SIZE 40 /* just include '.' and '..' entries */
@@ -576,7 +589,7 @@ struct f2fs_dir_entry {
576589
__u8 file_type; /* file type */
577590
} __packed;
578591

579-
/* 4KB-sized directory entry block */
592+
/* Block-sized directory entry block */
580593
struct f2fs_dentry_block {
581594
/* validity bitmap for directory entries in each block */
582595
__u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP];

0 commit comments

Comments
 (0)