mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-06 17:35:20 +02:00
UPSTREAM: f2fs: get rid of buffer_head use
Convert to use folio and related functionality.
Cc: Matthew Wilcox <willy@infradead.org>
Change-Id: Iab53cc6b5ea39fb66df4bcefd1b8cd9021f6c2e6
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
(cherry picked from commit 5bcde45578
)
This commit is contained in:
parent
220ce4c4c9
commit
8e550a95e3
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
#include <linux/fs.h>
|
||||
#include <linux/f2fs_fs.h>
|
||||
#include <linux/buffer_head.h>
|
||||
#include <linux/sched/mm.h>
|
||||
#include <linux/mpage.h>
|
||||
#include <linux/writeback.h>
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <linux/uio.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/page-flags.h>
|
||||
#include <linux/buffer_head.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/crc32.h>
|
||||
#include <linux/magic.h>
|
||||
|
@ -2005,6 +2004,16 @@ static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
|
|||
return (struct f2fs_super_block *)(sbi->raw_super);
|
||||
}
|
||||
|
||||
static inline struct f2fs_super_block *F2FS_SUPER_BLOCK(struct folio *folio,
|
||||
pgoff_t index)
|
||||
{
|
||||
pgoff_t idx_in_folio = index % (1 << folio_order(folio));
|
||||
|
||||
return (struct f2fs_super_block *)
|
||||
(page_address(folio_page(folio, idx_in_folio)) +
|
||||
F2FS_SUPER_OFFSET);
|
||||
}
|
||||
|
||||
static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
|
||||
{
|
||||
return (struct f2fs_checkpoint *)(sbi->ckpt);
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <linux/fs.h>
|
||||
#include <linux/f2fs_fs.h>
|
||||
#include <linux/stat.h>
|
||||
#include <linux/buffer_head.h>
|
||||
#include <linux/writeback.h>
|
||||
#include <linux/blkdev.h>
|
||||
#include <linux/falloc.h>
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
#include <linux/fs.h>
|
||||
#include <linux/f2fs_fs.h>
|
||||
#include <linux/buffer_head.h>
|
||||
#include <linux/writeback.h>
|
||||
#include <linux/sched/mm.h>
|
||||
#include <linux/lz4.h>
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <linux/fs_context.h>
|
||||
#include <linux/sched/mm.h>
|
||||
#include <linux/statfs.h>
|
||||
#include <linux/buffer_head.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/parser.h>
|
||||
#include <linux/mount.h>
|
||||
|
@ -3318,24 +3317,42 @@ loff_t max_file_blocks(struct inode *inode)
|
|||
return result;
|
||||
}
|
||||
|
||||
static int __f2fs_commit_super(struct buffer_head *bh,
|
||||
struct f2fs_super_block *super)
|
||||
static int __f2fs_commit_super(struct f2fs_sb_info *sbi, struct folio *folio,
|
||||
pgoff_t index, bool update)
|
||||
{
|
||||
lock_buffer(bh);
|
||||
if (super)
|
||||
memcpy(bh->b_data + F2FS_SUPER_OFFSET, super, sizeof(*super));
|
||||
set_buffer_dirty(bh);
|
||||
unlock_buffer(bh);
|
||||
|
||||
struct bio *bio;
|
||||
/* it's rare case, we can do fua all the time */
|
||||
return __sync_dirty_buffer(bh, REQ_SYNC | REQ_PREFLUSH | REQ_FUA);
|
||||
blk_opf_t opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH | REQ_FUA;
|
||||
int ret;
|
||||
|
||||
folio_lock(folio);
|
||||
folio_wait_writeback(folio);
|
||||
if (update)
|
||||
memcpy(F2FS_SUPER_BLOCK(folio, index), F2FS_RAW_SUPER(sbi),
|
||||
sizeof(struct f2fs_super_block));
|
||||
folio_mark_dirty(folio);
|
||||
folio_clear_dirty_for_io(folio);
|
||||
folio_start_writeback(folio);
|
||||
folio_unlock(folio);
|
||||
|
||||
bio = bio_alloc(sbi->sb->s_bdev, 1, opf, GFP_NOFS);
|
||||
|
||||
/* it doesn't need to set crypto context for superblock update */
|
||||
bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(folio_index(folio));
|
||||
|
||||
if (!bio_add_folio(bio, folio, folio_size(folio), 0))
|
||||
f2fs_bug_on(sbi, 1);
|
||||
|
||||
ret = submit_bio_wait(bio);
|
||||
folio_end_writeback(folio);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
|
||||
struct buffer_head *bh)
|
||||
struct folio *folio, pgoff_t index)
|
||||
{
|
||||
struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
|
||||
(bh->b_data + F2FS_SUPER_OFFSET);
|
||||
struct f2fs_super_block *raw_super = F2FS_SUPER_BLOCK(folio, index);
|
||||
struct super_block *sb = sbi->sb;
|
||||
u32 segment0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr);
|
||||
u32 cp_blkaddr = le32_to_cpu(raw_super->cp_blkaddr);
|
||||
|
@ -3410,7 +3427,7 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
|
|||
set_sbi_flag(sbi, SBI_NEED_SB_WRITE);
|
||||
res = "internally";
|
||||
} else {
|
||||
err = __f2fs_commit_super(bh, NULL);
|
||||
err = __f2fs_commit_super(sbi, folio, index, false);
|
||||
res = err ? "failed" : "done";
|
||||
}
|
||||
f2fs_info(sbi, "Fix alignment : %s, start(%u) end(%llu) block(%u)",
|
||||
|
@ -3423,12 +3440,11 @@ static inline bool sanity_check_area_boundary(struct f2fs_sb_info *sbi,
|
|||
}
|
||||
|
||||
static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
|
||||
struct buffer_head *bh)
|
||||
struct folio *folio, pgoff_t index)
|
||||
{
|
||||
block_t segment_count, segs_per_sec, secs_per_zone, segment_count_main;
|
||||
block_t total_sections, blocks_per_seg;
|
||||
struct f2fs_super_block *raw_super = (struct f2fs_super_block *)
|
||||
(bh->b_data + F2FS_SUPER_OFFSET);
|
||||
struct f2fs_super_block *raw_super = F2FS_SUPER_BLOCK(folio, index);
|
||||
size_t crc_offset = 0;
|
||||
__u32 crc = 0;
|
||||
|
||||
|
@ -3586,7 +3602,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
|
|||
}
|
||||
|
||||
/* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
|
||||
if (sanity_check_area_boundary(sbi, bh))
|
||||
if (sanity_check_area_boundary(sbi, folio, index))
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
return 0;
|
||||
|
@ -3933,7 +3949,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
|
|||
{
|
||||
struct super_block *sb = sbi->sb;
|
||||
int block;
|
||||
struct buffer_head *bh;
|
||||
struct folio *folio;
|
||||
struct f2fs_super_block *super;
|
||||
int err = 0;
|
||||
|
||||
|
@ -3942,32 +3958,33 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
|
|||
return -ENOMEM;
|
||||
|
||||
for (block = 0; block < 2; block++) {
|
||||
bh = sb_bread(sb, block);
|
||||
if (!bh) {
|
||||
folio = read_mapping_folio(sb->s_bdev->bd_inode->i_mapping,
|
||||
block, NULL);
|
||||
if (IS_ERR(folio)) {
|
||||
f2fs_err(sbi, "Unable to read %dth superblock",
|
||||
block + 1);
|
||||
err = -EIO;
|
||||
err = PTR_ERR(folio);
|
||||
*recovery = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* sanity checking of raw super */
|
||||
err = sanity_check_raw_super(sbi, bh);
|
||||
err = sanity_check_raw_super(sbi, folio, block);
|
||||
if (err) {
|
||||
f2fs_err(sbi, "Can't find valid F2FS filesystem in %dth superblock",
|
||||
block + 1);
|
||||
brelse(bh);
|
||||
folio_put(folio);
|
||||
*recovery = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!*raw_super) {
|
||||
memcpy(super, bh->b_data + F2FS_SUPER_OFFSET,
|
||||
memcpy(super, F2FS_SUPER_BLOCK(folio, block),
|
||||
sizeof(*super));
|
||||
*valid_super_block = block;
|
||||
*raw_super = super;
|
||||
}
|
||||
brelse(bh);
|
||||
folio_put(folio);
|
||||
}
|
||||
|
||||
/* No valid superblock */
|
||||
|
@ -3981,7 +3998,8 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi,
|
|||
|
||||
int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
|
||||
{
|
||||
struct buffer_head *bh;
|
||||
struct folio *folio;
|
||||
pgoff_t index;
|
||||
__u32 crc = 0;
|
||||
int err;
|
||||
|
||||
|
@ -3999,22 +4017,26 @@ int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover)
|
|||
}
|
||||
|
||||
/* write back-up superblock first */
|
||||
bh = sb_bread(sbi->sb, sbi->valid_super_block ? 0 : 1);
|
||||
if (!bh)
|
||||
return -EIO;
|
||||
err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
|
||||
brelse(bh);
|
||||
index = sbi->valid_super_block ? 0 : 1;
|
||||
folio = read_mapping_folio(sbi->sb->s_bdev->bd_inode->i_mapping,
|
||||
index, NULL);
|
||||
if (IS_ERR(folio))
|
||||
return PTR_ERR(folio);
|
||||
err = __f2fs_commit_super(sbi, folio, index, true);
|
||||
folio_put(folio);
|
||||
|
||||
/* if we are in recovery path, skip writing valid superblock */
|
||||
if (recover || err)
|
||||
return err;
|
||||
|
||||
/* write current valid superblock */
|
||||
bh = sb_bread(sbi->sb, sbi->valid_super_block);
|
||||
if (!bh)
|
||||
return -EIO;
|
||||
err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
|
||||
brelse(bh);
|
||||
index = sbi->valid_super_block;
|
||||
folio = read_mapping_folio(sbi->sb->s_bdev->bd_inode->i_mapping,
|
||||
index, NULL);
|
||||
if (IS_ERR(folio))
|
||||
return PTR_ERR(folio);
|
||||
err = __f2fs_commit_super(sbi, folio, index, true);
|
||||
folio_put(folio);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user