1// SPDX-License-Identifier: GPL-2.0 |
2/* 3 * fs/f2fs/f2fs.h 4 * 5 * Copyright (c) 2012 Samsung Electronics Co., Ltd. 6 * http://www.samsung.com/ 7 */ 8#ifndef _LINUX_F2FS_H 9#define _LINUX_F2FS_H --- 123 unchanged lines hidden (view full) --- 133 int s_jquota_fmt; /* Format of quota to use */ 134#endif 135 /* For which write hints are passed down to block layer */ 136 int whint_mode; 137 int alloc_mode; /* segment allocation policy */ 138 int fsync_mode; /* fsync policy */ 139 int fs_mode; /* fs mode: LFS or ADAPTIVE */ 140 int bggc_mode; /* bggc mode: off, on or sync */ |
141 struct fscrypt_dummy_context dummy_enc_ctx; /* test dummy encryption */ |
142 block_t unusable_cap; /* Amount of space allowed to be 143 * unusable when disabling checkpoint 144 */ 145 146 /* For compression */ 147 unsigned char compress_algorithm; /* algorithm type */ 148 unsigned compress_log_size; /* cluster log size */ 149 unsigned char compress_ext_cnt; /* extension count */ --- 39 unchanged lines hidden (view full) --- 189 190#define CP_UMOUNT 0x00000001 191#define CP_FASTBOOT 0x00000002 192#define CP_SYNC 0x00000004 193#define CP_RECOVERY 0x00000008 194#define CP_DISCARD 0x00000010 195#define CP_TRIMMED 0x00000020 196#define CP_PAUSE 0x00000040 |
197 198#define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 199#define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 200#define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 201#define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ 202#define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 203#define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ 204#define DEF_CP_INTERVAL 60 /* 60 secs */ --- 218 unchanged lines hidden (view full) --- 423#define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 424 struct f2fs_gc_range) 425#define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) 426#define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) 427#define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) 428#define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) 429#define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) 430#define F2FS_IOC_GET_COMPRESS_BLOCKS _IOR(F2FS_IOCTL_MAGIC, 17, __u64) |
431 432#define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL 433#define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL 434 435#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 436#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 437#define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 438 --- 62 unchanged lines hidden (view full) --- 501 ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 502 NR_INLINE_DENTRY(inode) + \ 503 INLINE_DENTRY_BITMAP_SIZE(inode))) 504 505/* 506 * For INODE and NODE manager 507 */ 508/* for directory operations */ |
509struct f2fs_dentry_ptr { 510 struct inode *inode; 511 void *bitmap; 512 struct f2fs_dir_entry *dentry; 513 __u8 (*filename)[F2FS_SLOT_LEN]; 514 int max; 515 int nr_bitmap; 516}; --- 566 unchanged lines hidden (view full) --- 1083 CP_NO_SPC_ROLL, 1084 CP_NODE_NEED_CP, 1085 CP_FASTBOOT_MODE, 1086 CP_SPEC_LOG_NUM, 1087 CP_RECOVER_DIR, 1088}; 1089 1090enum iostat_type { |
1091 APP_DIRECT_IO, /* app direct IOs */ 1092 APP_BUFFERED_IO, /* app buffered IOs */ |
1093 APP_WRITE_IO, /* app write IOs */ 1094 APP_MAPPED_IO, /* app mapped IOs */ 1095 FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 1096 FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 1097 FS_META_IO, /* meta IOs from kworker/reclaimer */ 1098 FS_GC_DATA_IO, /* data IOs from forground gc */ 1099 FS_GC_NODE_IO, /* node IOs from forground gc */ 1100 FS_CP_DATA_IO, /* data IOs from checkpoint */ 1101 FS_CP_NODE_IO, /* node IOs from checkpoint */ 1102 FS_CP_META_IO, /* meta IOs from checkpoint */ |
1103 FS_DISCARD, /* discard */ 1104 NR_IO_TYPE, 1105}; 1106 1107struct f2fs_io_info { 1108 struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 1109 nid_t ino; /* inode number */ 1110 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ --- 143 unchanged lines hidden (view full) --- 1254 1255#define IS_ATOMIC_WRITTEN_PAGE(page) \ 1256 (page_private(page) == (unsigned long)ATOMIC_WRITTEN_PAGE) 1257#define IS_DUMMY_WRITTEN_PAGE(page) \ 1258 (page_private(page) == (unsigned long)DUMMY_WRITTEN_PAGE) 1259 1260#ifdef CONFIG_FS_ENCRYPTION 1261#define DUMMY_ENCRYPTION_ENABLED(sbi) \ |
1262 (unlikely(F2FS_OPTION(sbi).dummy_enc_ctx.ctx != NULL)) |
1263#else 1264#define DUMMY_ENCRYPTION_ENABLED(sbi) (0) 1265#endif 1266 1267/* For compression */ 1268enum compress_algorithm_type { 1269 COMPRESS_LZO, 1270 COMPRESS_LZ4, 1271 COMPRESS_ZSTD, |
1272 COMPRESS_MAX, 1273}; 1274 1275#define COMPRESS_DATA_RESERVED_SIZE 5 1276struct compress_data { 1277 __le32 clen; /* compressed data size */ 1278 __le32 reserved[COMPRESS_DATA_RESERVED_SIZE]; /* reserved */ 1279 u8 cdata[]; /* compressed data */ --- 133 unchanged lines hidden (view full) --- 1413 unsigned int root_ino_num; /* root inode number*/ 1414 unsigned int node_ino_num; /* node inode number*/ 1415 unsigned int meta_ino_num; /* meta inode number*/ 1416 unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 1417 unsigned int blocks_per_seg; /* blocks per segment */ 1418 unsigned int segs_per_sec; /* segments per section */ 1419 unsigned int secs_per_zone; /* sections per zone */ 1420 unsigned int total_sections; /* total section count */ |
1421 struct mutex resize_mutex; /* for resize exclusion */ |
1422 unsigned int total_node_count; /* total node block count */ 1423 unsigned int total_valid_node_count; /* valid node block count */ 1424 loff_t max_file_blocks; /* max block index of file */ 1425 int dir_level; /* directory level */ 1426 int readdir_ra; /* readahead inode in readdir */ 1427 1428 block_t user_block_count; /* # of user blocks */ 1429 block_t total_valid_block_count; /* # of valid blocks */ --- 69 unchanged lines hidden (view full) --- 1499 unsigned int io_skip_bggc; /* skip background gc for in-flight IO */ 1500 unsigned int other_skip_bggc; /* skip background gc for other reasons */ 1501 unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 1502#endif 1503 spinlock_t stat_lock; /* lock for stat operations */ 1504 1505 /* For app/fs IO statistics */ 1506 spinlock_t iostat_lock; |
1507 unsigned long long write_iostat[NR_IO_TYPE]; |
1508 bool iostat_enable; |
1509 |
1510 /* For sysfs suppport */ 1511 struct kobject s_kobj; 1512 struct completion s_kobj_unregister; 1513 1514 /* For shrinker support */ 1515 struct list_head s_list; 1516 int s_ndevs; /* number of devices */ 1517 struct f2fs_dev_info *devs; /* for device list */ --- 1379 unchanged lines hidden (view full) --- 2897 return sb_rdonly(sb); 2898} 2899 2900static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 2901{ 2902 return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 2903} 2904 |
2905static inline bool is_dot_dotdot(const struct qstr *str) |
2906{ |
2907 if (str->len == 1 && str->name[0] == '.') |
2908 return true; 2909 |
2910 if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') |
2911 return true; 2912 2913 return false; 2914} 2915 2916static inline bool f2fs_may_extent_tree(struct inode *inode) 2917{ 2918 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); --- 72 unchanged lines hidden (view full) --- 2991 offsetof(struct f2fs_inode, i_extra_isize)) \ 2992 2993#define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 2994#define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 2995 ((offsetof(typeof(*(f2fs_inode)), field) + \ 2996 sizeof((f2fs_inode)->field)) \ 2997 <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \ 2998 |
2999static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 3000{ 3001 int i; 3002 3003 spin_lock(&sbi->iostat_lock); |
3004 for (i = 0; i < NR_IO_TYPE; i++) 3005 sbi->write_iostat[i] = 0; |
3006 spin_unlock(&sbi->iostat_lock); 3007} 3008 |
3009static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 3010 enum iostat_type type, unsigned long long io_bytes) 3011{ 3012 if (!sbi->iostat_enable) 3013 return; 3014 spin_lock(&sbi->iostat_lock); |
3015 sbi->write_iostat[type] += io_bytes; |
3016 3017 if (type == APP_WRITE_IO || type == APP_DIRECT_IO) |
3018 sbi->write_iostat[APP_BUFFERED_IO] = 3019 sbi->write_iostat[APP_WRITE_IO] - 3020 sbi->write_iostat[APP_DIRECT_IO]; |
3021 spin_unlock(&sbi->iostat_lock); |
3022} 3023 3024#define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 3025 3026#define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META) 3027 3028bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 3029 block_t blkaddr, int type); --- 36 unchanged lines hidden (view full) --- 3066 f2fs_put_page(page, 0); 3067} 3068 3069/* 3070 * file.c 3071 */ 3072int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 3073void f2fs_truncate_data_blocks(struct dnode_of_data *dn); |
3074int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); 3075int f2fs_truncate(struct inode *inode); 3076int f2fs_getattr(const struct path *path, struct kstat *stat, 3077 u32 request_mask, unsigned int flags); 3078int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 3079int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 3080void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); 3081int f2fs_precache_extents(struct inode *inode); --- 19 unchanged lines hidden (view full) --- 3101 3102/* 3103 * namei.c 3104 */ 3105int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, 3106 bool hot, bool set); 3107struct dentry *f2fs_get_parent(struct dentry *child); 3108 |
3109extern int f2fs_ci_compare(const struct inode *parent, 3110 const struct qstr *name, 3111 const struct qstr *entry, 3112 bool quick); 3113 |
3114/* 3115 * dir.c 3116 */ 3117unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); |
3118struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, 3119 f2fs_hash_t namehash, int *max_slots, 3120 struct f2fs_dentry_ptr *d); |
3121int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 3122 unsigned int start_pos, struct fscrypt_str *fstr); 3123void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, 3124 struct f2fs_dentry_ptr *d); 3125struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, |
3126 const struct qstr *new_name, 3127 const struct qstr *orig_name, struct page *dpage); |
3128void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, 3129 unsigned int current_depth); 3130int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); 3131void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 3132struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, |
3133 struct fscrypt_name *fname, struct page **res_page); |
3134struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 3135 const struct qstr *child, struct page **res_page); 3136struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 3137ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 3138 struct page **page); 3139void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 3140 struct page *page, struct inode *inode); 3141bool f2fs_has_enough_room(struct inode *dir, struct page *ipage, |
3142 struct fscrypt_name *fname); |
3143void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, |
3144 const struct qstr *name, f2fs_hash_t name_hash, |
3145 unsigned int bit_pos); |
3146int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 3147 const struct qstr *orig_name, |
3148 struct inode *inode, nid_t ino, umode_t mode); |
3149int f2fs_add_dentry(struct inode *dir, struct fscrypt_name *fname, |
3150 struct inode *inode, nid_t ino, umode_t mode); 3151int f2fs_do_add_link(struct inode *dir, const struct qstr *name, 3152 struct inode *inode, nid_t ino, umode_t mode); 3153void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 3154 struct inode *dir, struct inode *inode); 3155int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 3156bool f2fs_empty_dir(struct inode *dir); 3157 --- 13 unchanged lines hidden (view full) --- 3171void f2fs_quota_off_umount(struct super_block *sb); 3172int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 3173int f2fs_sync_fs(struct super_block *sb, int sync); 3174int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); 3175 3176/* 3177 * hash.c 3178 */ |
3179f2fs_hash_t f2fs_dentry_hash(const struct inode *dir, 3180 const struct qstr *name_info, struct fscrypt_name *fname); |
3181 3182/* 3183 * node.c 3184 */ 3185struct dnode_of_data; 3186struct node_info; 3187 3188int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); --- 15 unchanged lines hidden (view full) --- 3204 unsigned int seq_id); 3205int f2fs_remove_inode_page(struct inode *inode); 3206struct page *f2fs_new_inode_page(struct inode *inode); 3207struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); 3208void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 3209struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 3210struct page *f2fs_get_node_page_ra(struct page *parent, int start); 3211int f2fs_move_node_page(struct page *node_page, int gc_type); |
3212int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 3213 struct writeback_control *wbc, bool atomic, 3214 unsigned int *seq_id); 3215int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, 3216 struct writeback_control *wbc, 3217 bool do_balance, enum iostat_type io_type); 3218int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 3219bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); --- 430 unchanged lines hidden (view full) --- 3650#define stat_inc_tot_blk_count(si, blks) do { } while (0) 3651#define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 3652#define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 3653 3654static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 3655static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 3656static inline void __init f2fs_create_root_stats(void) { } 3657static inline void f2fs_destroy_root_stats(void) { } |
3658static inline void update_sit_info(struct f2fs_sb_info *sbi) {} |
3659#endif 3660 3661extern const struct file_operations f2fs_dir_operations; 3662#ifdef CONFIG_UNICODE 3663extern const struct dentry_operations f2fs_dentry_ops; 3664#endif 3665extern const struct file_operations f2fs_file_operations; 3666extern const struct inode_operations f2fs_file_inode_operations; --- 16 unchanged lines hidden (view full) --- 3683 struct page *ipage, u64 from); 3684int f2fs_read_inline_data(struct inode *inode, struct page *page); 3685int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 3686int f2fs_convert_inline_inode(struct inode *inode); 3687int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry); 3688int f2fs_write_inline_data(struct inode *inode, struct page *page); 3689bool f2fs_recover_inline_data(struct inode *inode, struct page *npage); 3690struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, |
3691 struct fscrypt_name *fname, struct page **res_page); |
3692int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 3693 struct page *ipage); |
3694int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 3695 const struct qstr *orig_name, |
3696 struct inode *inode, nid_t ino, umode_t mode); 3697void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, 3698 struct page *page, struct inode *dir, 3699 struct inode *inode); 3700bool f2fs_empty_inline_dir(struct inode *dir); 3701int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3702 struct fscrypt_str *fstr); 3703int f2fs_inline_data_fiemap(struct inode *inode, --- 82 unchanged lines hidden (view full) --- 3786 */ 3787#ifdef CONFIG_F2FS_FS_COMPRESSION 3788bool f2fs_is_compressed_page(struct page *page); 3789struct page *f2fs_compress_control_page(struct page *page); 3790int f2fs_prepare_compress_overwrite(struct inode *inode, 3791 struct page **pagep, pgoff_t index, void **fsdata); 3792bool f2fs_compress_write_end(struct inode *inode, void *fsdata, 3793 pgoff_t index, unsigned copied); |
3794void f2fs_compress_write_end_io(struct bio *bio, struct page *page); 3795bool f2fs_is_compress_backend_ready(struct inode *inode); |
3796void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity); 3797bool f2fs_cluster_is_empty(struct compress_ctx *cc); 3798bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index); 3799void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page); 3800int f2fs_write_multi_pages(struct compress_ctx *cc, 3801 int *submitted, 3802 struct writeback_control *wbc, 3803 enum iostat_type io_type); --- 17 unchanged lines hidden (view full) --- 3821 /* not support compression */ 3822 return false; 3823} 3824static inline struct page *f2fs_compress_control_page(struct page *page) 3825{ 3826 WARN_ON_ONCE(1); 3827 return ERR_PTR(-EINVAL); 3828} |
3829#endif 3830 3831static inline void set_compress_context(struct inode *inode) 3832{ 3833 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3834 3835 F2FS_I(inode)->i_compress_algorithm = 3836 F2FS_OPTION(sbi).compress_algorithm; --- 130 unchanged lines hidden (view full) --- 3967 return S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode); 3968} 3969 3970static inline void f2fs_i_compr_blocks_update(struct inode *inode, 3971 u64 blocks, bool add) 3972{ 3973 int diff = F2FS_I(inode)->i_cluster_size - blocks; 3974 |
3975 if (add) { 3976 F2FS_I(inode)->i_compr_blocks += diff; 3977 stat_add_compr_blocks(inode, diff); 3978 } else { 3979 F2FS_I(inode)->i_compr_blocks -= diff; 3980 stat_sub_compr_blocks(inode, diff); 3981 } 3982 f2fs_mark_inode_dirty_sync(inode, true); --- 25 unchanged lines hidden (view full) --- 4008{ 4009 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4010 int rw = iov_iter_rw(iter); 4011 4012 if (f2fs_post_read_required(inode)) 4013 return true; 4014 if (f2fs_is_multi_device(sbi)) 4015 return true; |
4016 if (f2fs_compressed_file(inode)) 4017 return true; |
4018 /* 4019 * for blkzoned device, fallback direct IO to buffered IO, so 4020 * all IOs can be serialized by log-structured write. 4021 */ 4022 if (f2fs_sb_has_blkzoned(sbi)) 4023 return true; 4024 if (f2fs_lfs_mode(sbi) && (rw == WRITE)) { 4025 if (block_unaligned_IO(inode, iocb, iter)) --- 35 unchanged lines hidden --- |