Merge tag 'idmapped-mounts-v5.12' of git://git.kernel.org/pub/scm/linux/kernel/git...
[platform/kernel/linux-rpi.git] / fs / f2fs / f2fs.h
index c9002b1..e2d302a 100644 (file)
@@ -43,7 +43,6 @@ enum {
        FAULT_KVMALLOC,
        FAULT_PAGE_ALLOC,
        FAULT_PAGE_GET,
-       FAULT_ALLOC_BIO,
        FAULT_ALLOC_NID,
        FAULT_ORPHAN,
        FAULT_BLOCK,
@@ -97,6 +96,7 @@ extern const char *f2fs_fault_name[FAULT_MAX];
 #define F2FS_MOUNT_DISABLE_CHECKPOINT  0x02000000
 #define F2FS_MOUNT_NORECOVERY          0x04000000
 #define F2FS_MOUNT_ATGC                        0x08000000
+#define F2FS_MOUNT_MERGE_CHECKPOINT    0x10000000
 
 #define F2FS_OPTION(sbi)       ((sbi)->mount_opt)
 #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
@@ -146,6 +146,7 @@ struct f2fs_mount_info {
        /* For compression */
        unsigned char compress_algorithm;       /* algorithm type */
        unsigned char compress_log_size;        /* cluster log size */
+       unsigned char compress_level;           /* compress level */
        bool compress_chksum;                   /* compressed data chksum */
        unsigned char compress_ext_cnt;         /* extension count */
        int compress_mode;                      /* compression mode */
@@ -266,6 +267,26 @@ struct fsync_node_entry {
        unsigned int seq_id;    /* sequence id */
 };
 
+struct ckpt_req {
+       struct completion wait;         /* completion for checkpoint done */
+       struct llist_node llnode;       /* llist_node to be linked in wait queue */
+       int ret;                        /* return code of checkpoint */
+       ktime_t queue_time;             /* request queued time */
+};
+
+struct ckpt_req_control {
+       struct task_struct *f2fs_issue_ckpt;    /* checkpoint task */
+       int ckpt_thread_ioprio;                 /* checkpoint merge thread ioprio */
+       wait_queue_head_t ckpt_wait_queue;      /* waiting queue for wake-up */
+       atomic_t issued_ckpt;           /* # of actually issued ckpts */
+       atomic_t total_ckpt;            /* # of total ckpts */
+       atomic_t queued_ckpt;           /* # of queued ckpts */
+       struct llist_head issue_list;   /* list for command issue */
+       spinlock_t stat_lock;           /* lock for below checkpoint time stats */
+       unsigned int cur_time;          /* cur wait time in msec for currently issued checkpoint */
+       unsigned int peak_time;         /* peak wait time in msec until now */
+};
+
 /* for the bitmap indicate blocks to be discarded */
 struct discard_entry {
        struct list_head list;  /* list head */
@@ -717,7 +738,6 @@ struct f2fs_inode_info {
        struct list_head inmem_pages;   /* inmemory pages managed by f2fs */
        struct task_struct *inmem_task; /* store inmemory task */
        struct mutex inmem_lock;        /* lock for inmemory pages */
-       pgoff_t ra_offset;              /* ongoing readahead offset */
        struct extent_tree *extent_tree;        /* cached extent_tree entry */
 
        /* avoid racing between foreground op and gc */
@@ -735,6 +755,7 @@ struct f2fs_inode_info {
        atomic_t i_compr_blocks;                /* # of compressed blocks */
        unsigned char i_compress_algorithm;     /* algorithm type */
        unsigned char i_log_cluster_size;       /* log of cluster size */
+       unsigned char i_compress_level;         /* compress level (lz4hc,zstd) */
        unsigned short i_compress_flag;         /* compress flag */
        unsigned int i_cluster_size;            /* cluster size */
 };
@@ -1310,6 +1331,8 @@ struct compress_data {
 
 #define F2FS_COMPRESSED_PAGE_MAGIC     0xF5F2C000
 
+#define        COMPRESS_LEVEL_OFFSET   8
+
 /* compress context */
 struct compress_ctx {
        struct inode *inode;            /* inode the context belong to */
@@ -1337,7 +1360,7 @@ struct compress_io_ctx {
        atomic_t pending_pages;         /* in-flight compressed page count */
 };
 
-/* decompress io context for read IO path */
+/* Context for decompressing one cluster on the read IO path */
 struct decompress_io_ctx {
        u32 magic;                      /* magic number to indicate page is compressed */
        struct inode *inode;            /* inode the context belong to */
@@ -1353,11 +1376,37 @@ struct decompress_io_ctx {
        struct compress_data *cbuf;     /* virtual mapped address on cpages */
        size_t rlen;                    /* valid data length in rbuf */
        size_t clen;                    /* valid data length in cbuf */
-       atomic_t pending_pages;         /* in-flight compressed page count */
-       atomic_t verity_pages;          /* in-flight page count for verity */
-       bool failed;                    /* indicate IO error during decompression */
+
+       /*
+        * The number of compressed pages remaining to be read in this cluster.
+        * This is initially nr_cpages.  It is decremented by 1 each time a page
+        * has been read (or failed to be read).  When it reaches 0, the cluster
+        * is decompressed (or an error is reported).
+        *
+        * If an error occurs before all the pages have been submitted for I/O,
+        * then this will never reach 0.  In this case the I/O submitter is
+        * responsible for calling f2fs_decompress_end_io() instead.
+        */
+       atomic_t remaining_pages;
+
+       /*
+        * Number of references to this decompress_io_ctx.
+        *
+        * One reference is held for I/O completion.  This reference is dropped
+        * after the pagecache pages are updated and unlocked -- either after
+        * decompression (and verity if enabled), or after an error.
+        *
+        * In addition, each compressed page holds a reference while it is in a
+        * bio.  These references are necessary prevent compressed pages from
+        * being freed while they are still in a bio.
+        */
+       refcount_t refcnt;
+
+       bool failed;                    /* IO error occurred before decompression? */
+       bool need_verity;               /* need fs-verity verification after decompression? */
        void *private;                  /* payload buffer for specified decompression algorithm */
        void *private2;                 /* extra payload buffer */
+       struct work_struct verity_work; /* work to verify the decompressed pages */
 };
 
 #define NULL_CLUSTER                   ((unsigned int)(~0))
@@ -1404,6 +1453,7 @@ struct f2fs_sb_info {
        wait_queue_head_t cp_wait;
        unsigned long last_time[MAX_TIME];      /* to store time in jiffies */
        long interval_time[MAX_TIME];           /* to store thresholds */
+       struct ckpt_req_control cprc_info;      /* for checkpoint request control */
 
        struct inode_management im[MAX_INO_ENTRY];      /* manage inode cache */
 
@@ -1444,7 +1494,6 @@ struct f2fs_sb_info {
        unsigned int total_sections;            /* total section count */
        unsigned int total_node_count;          /* total node block count */
        unsigned int total_valid_node_count;    /* valid node block count */
-       loff_t max_file_blocks;                 /* max block index of file */
        int dir_level;                          /* directory level */
        int readdir_ra;                         /* readahead inode in readdir */
        u64 max_io_bytes;                       /* max io bytes to merge IOs */
@@ -1541,9 +1590,12 @@ struct f2fs_sb_info {
        unsigned int node_io_flag;
 
        /* For sysfs suppport */
-       struct kobject s_kobj;
+       struct kobject s_kobj;                  /* /sys/fs/f2fs/<devname> */
        struct completion s_kobj_unregister;
 
+       struct kobject s_stat_kobj;             /* /sys/fs/f2fs/<devname>/stat */
+       struct completion s_stat_kobj_unregister;
+
        /* For shrinker support */
        struct list_head s_list;
        int s_ndevs;                            /* number of devices */
@@ -3233,6 +3285,7 @@ int f2fs_inode_dirtied(struct inode *inode, bool sync);
 void f2fs_inode_synced(struct inode *inode);
 int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly);
 int f2fs_quota_sync(struct super_block *sb, int type);
+loff_t max_file_blocks(struct inode *inode);
 void f2fs_quota_off_umount(struct super_block *sb);
 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
 int f2fs_sync_fs(struct super_block *sb, int sync);
@@ -3419,13 +3472,16 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc);
 void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi);
 int __init f2fs_create_checkpoint_caches(void);
 void f2fs_destroy_checkpoint_caches(void);
+int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi);
+int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi);
+void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi);
+void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi);
 
 /*
  * data.c
  */
 int __init f2fs_init_bioset(void);
 void f2fs_destroy_bioset(void);
-struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, int npages, bool noio);
 int f2fs_init_bio_entry_cache(void);
 void f2fs_destroy_bio_entry_cache(void);
 void f2fs_submit_bio(struct f2fs_sb_info *sbi,
@@ -3470,7 +3526,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted,
                                struct bio **bio, sector_t *last_block,
                                struct writeback_control *wbc,
                                enum iostat_type io_type,
-                               int compr_blocks);
+                               int compr_blocks, bool allow_balance);
 void f2fs_invalidate_page(struct page *page, unsigned int offset,
                        unsigned int length);
 int f2fs_release_page(struct page *page, gfp_t wait);
@@ -3531,6 +3587,8 @@ struct f2fs_stat_info {
        int nr_discarding, nr_discarded;
        int nr_discard_cmd;
        unsigned int undiscard_blks;
+       int nr_issued_ckpt, nr_total_ckpt, nr_queued_ckpt;
+       unsigned int cur_ckpt_time, peak_ckpt_time;
        int inline_xattr, inline_inode, inline_dir, append, update, orphans;
        int compr_inode;
        unsigned long long compr_blocks;
@@ -3716,8 +3774,6 @@ void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
 #define stat_dec_compr_inode(inode)                    do { } while (0)
 #define stat_add_compr_blocks(inode, blocks)           do { } while (0)
 #define stat_sub_compr_blocks(inode, blocks)           do { } while (0)
-#define stat_inc_atomic_write(inode)                   do { } while (0)
-#define stat_dec_atomic_write(inode)                   do { } while (0)
 #define stat_update_max_atomic_write(inode)            do { } while (0)
 #define stat_inc_volatile_write(inode)                 do { } while (0)
 #define stat_dec_volatile_write(inode)                 do { } while (0)
@@ -3877,7 +3933,7 @@ void f2fs_compress_write_end_io(struct bio *bio, struct page *page);
 bool f2fs_is_compress_backend_ready(struct inode *inode);
 int f2fs_init_compress_mempool(void);
 void f2fs_destroy_compress_mempool(void);
-void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity);
+void f2fs_end_read_compressed_page(struct page *page, bool failed);
 bool f2fs_cluster_is_empty(struct compress_ctx *cc);
 bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index);
 void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page);
@@ -3890,9 +3946,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
                                unsigned nr_pages, sector_t *last_block_in_bio,
                                bool is_readahead, bool for_write);
 struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc);
-void f2fs_free_dic(struct decompress_io_ctx *dic);
-void f2fs_decompress_end_io(struct page **rpages,
-                       unsigned int cluster_size, bool err, bool verity);
+void f2fs_decompress_end_io(struct decompress_io_ctx *dic, bool failed);
+void f2fs_put_page_dic(struct page *page);
 int f2fs_init_compress_ctx(struct compress_ctx *cc);
 void f2fs_destroy_compress_ctx(struct compress_ctx *cc);
 void f2fs_init_compress_info(struct f2fs_sb_info *sbi);
@@ -3916,6 +3971,14 @@ static inline struct page *f2fs_compress_control_page(struct page *page)
 }
 static inline int f2fs_init_compress_mempool(void) { return 0; }
 static inline void f2fs_destroy_compress_mempool(void) { }
+static inline void f2fs_end_read_compressed_page(struct page *page, bool failed)
+{
+       WARN_ON_ONCE(1);
+}
+static inline void f2fs_put_page_dic(struct page *page)
+{
+       WARN_ON_ONCE(1);
+}
 static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; }
 static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { }
 static inline int __init f2fs_init_compress_cache(void) { return 0; }
@@ -3935,6 +3998,11 @@ static inline void set_compress_context(struct inode *inode)
                                1 << COMPRESS_CHKSUM : 0;
        F2FS_I(inode)->i_cluster_size =
                        1 << F2FS_I(inode)->i_log_cluster_size;
+       if (F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 &&
+                       F2FS_OPTION(sbi).compress_level)
+               F2FS_I(inode)->i_compress_flag |=
+                               F2FS_OPTION(sbi).compress_level <<
+                               COMPRESS_LEVEL_OFFSET;
        F2FS_I(inode)->i_flags |= F2FS_COMPR_FL;
        set_inode_flag(inode, FI_COMPRESSED_FILE);
        stat_inc_compr_inode(inode);
@@ -4115,6 +4183,12 @@ static inline bool f2fs_force_buffered_io(struct inode *inode,
        return false;
 }
 
+static inline bool f2fs_need_verity(const struct inode *inode, pgoff_t idx)
+{
+       return fsverity_active(inode) &&
+              idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
+}
+
 #ifdef CONFIG_F2FS_FAULT_INJECTION
 extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
                                                        unsigned int type);