Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * NILFS Segment constructor prototypes and definitions
0004  *
0005  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
0006  *
0007  * Written by Ryusuke Konishi.
0008  *
0009  */
0010 #ifndef _NILFS_SEGMENT_H
0011 #define _NILFS_SEGMENT_H
0012 
0013 #include <linux/types.h>
0014 #include <linux/fs.h>
0015 #include <linux/buffer_head.h>
0016 #include <linux/workqueue.h>
0017 #include "nilfs.h"
0018 
0019 struct nilfs_root;
0020 
0021 /**
0022  * struct nilfs_recovery_info - Recovery information
0023  * @ri_need_recovery: Recovery status
0024  * @ri_super_root: Block number of the last super root
0025  * @ri_ri_cno: Number of the last checkpoint
0026  * @ri_lsegs_start: Region for roll-forwarding (start block number)
0027  * @ri_lsegs_end: Region for roll-forwarding (end block number)
0028  * @ri_lseg_start_seq: Sequence value of the segment at ri_lsegs_start
0029  * @ri_used_segments: List of segments to be mark active
0030  * @ri_pseg_start: Block number of the last partial segment
0031  * @ri_seq: Sequence number on the last partial segment
0032  * @ri_segnum: Segment number on the last partial segment
0033  * @ri_nextnum: Next segment number on the last partial segment
0034  */
0035 struct nilfs_recovery_info {
0036     int         ri_need_recovery;
0037     sector_t        ri_super_root;
0038     __u64           ri_cno;
0039 
0040     sector_t        ri_lsegs_start;
0041     sector_t        ri_lsegs_end;
0042     u64         ri_lsegs_start_seq;
0043     struct list_head    ri_used_segments;
0044     sector_t        ri_pseg_start;
0045     u64         ri_seq;
0046     __u64           ri_segnum;
0047     __u64           ri_nextnum;
0048 };
0049 
0050 /* ri_need_recovery */
0051 #define NILFS_RECOVERY_SR_UPDATED    1  /* The super root was updated */
0052 #define NILFS_RECOVERY_ROLLFORWARD_DONE  2  /* Rollforward was carried out */
0053 
0054 /**
0055  * struct nilfs_cstage - Context of collection stage
0056  * @scnt: Stage count, must be accessed via wrappers:
0057  *        nilfs_sc_cstage_inc(), nilfs_sc_cstage_set(), nilfs_sc_cstage_get()
0058  * @flags: State flags
0059  * @dirty_file_ptr: Pointer on dirty_files list, or inode of a target file
0060  * @gc_inode_ptr: Pointer on the list of gc-inodes
0061  */
0062 struct nilfs_cstage {
0063     int         scnt;
0064     unsigned int        flags;
0065     struct nilfs_inode_info *dirty_file_ptr;
0066     struct nilfs_inode_info *gc_inode_ptr;
0067 };
0068 
0069 struct nilfs_segment_buffer;
0070 
0071 struct nilfs_segsum_pointer {
0072     struct buffer_head     *bh;
0073     unsigned int        offset; /* offset in bytes */
0074 };
0075 
0076 /**
0077  * struct nilfs_sc_info - Segment constructor information
0078  * @sc_super: Back pointer to super_block struct
0079  * @sc_root: root object of the current filesystem tree
0080  * @sc_nblk_inc: Block count of current generation
0081  * @sc_dirty_files: List of files to be written
0082  * @sc_gc_inodes: List of GC inodes having blocks to be written
0083  * @sc_iput_queue: list of inodes for which iput should be done
0084  * @sc_iput_work: work struct to defer iput call
0085  * @sc_freesegs: array of segment numbers to be freed
0086  * @sc_nfreesegs: number of segments on @sc_freesegs
0087  * @sc_dsync_inode: inode whose data pages are written for a sync operation
0088  * @sc_dsync_start: start byte offset of data pages
0089  * @sc_dsync_end: end byte offset of data pages (inclusive)
0090  * @sc_segbufs: List of segment buffers
0091  * @sc_write_logs: List of segment buffers to hold logs under writing
0092  * @sc_segbuf_nblocks: Number of available blocks in segment buffers.
0093  * @sc_curseg: Current segment buffer
0094  * @sc_stage: Collection stage
0095  * @sc_finfo_ptr: pointer to the current finfo struct in the segment summary
0096  * @sc_binfo_ptr: pointer to the current binfo struct in the segment summary
0097  * @sc_blk_cnt: Block count of a file
0098  * @sc_datablk_cnt: Data block count of a file
0099  * @sc_nblk_this_inc: Number of blocks included in the current logical segment
0100  * @sc_seg_ctime: Creation time
0101  * @sc_cno: checkpoint number of current log
0102  * @sc_flags: Internal flags
0103  * @sc_state_lock: spinlock for sc_state and so on
0104  * @sc_state: Segctord state flags
0105  * @sc_flush_request: inode bitmap of metadata files to be flushed
0106  * @sc_wait_request: Client request queue
0107  * @sc_wait_daemon: Daemon wait queue
0108  * @sc_wait_task: Start/end wait queue to control segctord task
0109  * @sc_seq_request: Request counter
0110  * @sc_seq_accept: Accepted request count
0111  * @sc_seq_done: Completion counter
0112  * @sc_sync: Request of explicit sync operation
0113  * @sc_interval: Timeout value of background construction
0114  * @sc_mjcp_freq: Frequency of creating checkpoints
0115  * @sc_lseg_stime: Start time of the latest logical segment
0116  * @sc_watermark: Watermark for the number of dirty buffers
0117  * @sc_timer: Timer for segctord
0118  * @sc_task: current thread of segctord
0119  */
0120 struct nilfs_sc_info {
0121     struct super_block     *sc_super;
0122     struct nilfs_root      *sc_root;
0123 
0124     unsigned long       sc_nblk_inc;
0125 
0126     struct list_head    sc_dirty_files;
0127     struct list_head    sc_gc_inodes;
0128     struct list_head    sc_iput_queue;
0129     struct work_struct  sc_iput_work;
0130 
0131     __u64              *sc_freesegs;
0132     size_t          sc_nfreesegs;
0133 
0134     struct nilfs_inode_info *sc_dsync_inode;
0135     loff_t          sc_dsync_start;
0136     loff_t          sc_dsync_end;
0137 
0138     /* Segment buffers */
0139     struct list_head    sc_segbufs;
0140     struct list_head    sc_write_logs;
0141     unsigned long       sc_segbuf_nblocks;
0142     struct nilfs_segment_buffer *sc_curseg;
0143 
0144     struct nilfs_cstage sc_stage;
0145 
0146     struct nilfs_segsum_pointer sc_finfo_ptr;
0147     struct nilfs_segsum_pointer sc_binfo_ptr;
0148     unsigned long       sc_blk_cnt;
0149     unsigned long       sc_datablk_cnt;
0150     unsigned long       sc_nblk_this_inc;
0151     time64_t        sc_seg_ctime;
0152     __u64           sc_cno;
0153     unsigned long       sc_flags;
0154 
0155     spinlock_t      sc_state_lock;
0156     unsigned long       sc_state;
0157     unsigned long       sc_flush_request;
0158 
0159     wait_queue_head_t   sc_wait_request;
0160     wait_queue_head_t   sc_wait_daemon;
0161     wait_queue_head_t   sc_wait_task;
0162 
0163     __u32           sc_seq_request;
0164     __u32           sc_seq_accepted;
0165     __u32           sc_seq_done;
0166 
0167     int         sc_sync;
0168     unsigned long       sc_interval;
0169     unsigned long       sc_mjcp_freq;
0170     unsigned long       sc_lseg_stime;  /* in 1/HZ seconds */
0171     unsigned long       sc_watermark;
0172 
0173     struct timer_list   sc_timer;
0174     struct task_struct     *sc_timer_task;
0175     struct task_struct     *sc_task;
0176 };
0177 
0178 /* sc_flags */
0179 enum {
0180     NILFS_SC_DIRTY,     /* One or more dirty meta-data blocks exist */
0181     NILFS_SC_UNCLOSED,  /* Logical segment is not closed */
0182     NILFS_SC_SUPER_ROOT,    /* The latest segment has a super root */
0183     NILFS_SC_PRIOR_FLUSH,   /*
0184                  * Requesting immediate flush without making a
0185                  * checkpoint
0186                  */
0187     NILFS_SC_HAVE_DELTA,    /*
0188                  * Next checkpoint will have update of files
0189                  * other than DAT, cpfile, sufile, or files
0190                  * moved by GC.
0191                  */
0192 };
0193 
0194 /* sc_state */
0195 #define NILFS_SEGCTOR_QUIT      0x0001  /* segctord is being destroyed */
0196 #define NILFS_SEGCTOR_COMMIT        0x0004  /* committed transaction exists */
0197 
0198 /*
0199  * Constant parameters
0200  */
0201 #define NILFS_SC_CLEANUP_RETRY      3  /*
0202                     * Retry count of construction when
0203                     * destroying segctord
0204                     */
0205 
0206 /*
0207  * Default values of timeout, in seconds.
0208  */
0209 #define NILFS_SC_DEFAULT_TIMEOUT    5   /*
0210                      * Timeout value of dirty blocks.
0211                      * It triggers construction of a
0212                      * logical segment with a super root.
0213                      */
0214 #define NILFS_SC_DEFAULT_SR_FREQ    30  /*
0215                      * Maximum frequency of super root
0216                      * creation
0217                      */
0218 
0219 /*
0220  * The default threshold amount of data, in block counts.
0221  */
0222 #define NILFS_SC_DEFAULT_WATERMARK  3600
0223 
0224 /* super.c */
0225 extern struct kmem_cache *nilfs_transaction_cachep;
0226 
0227 /* segment.c */
0228 extern void nilfs_relax_pressure_in_lock(struct super_block *);
0229 
0230 extern int nilfs_construct_segment(struct super_block *);
0231 extern int nilfs_construct_dsync_segment(struct super_block *, struct inode *,
0232                      loff_t, loff_t);
0233 extern void nilfs_flush_segment(struct super_block *, ino_t);
0234 extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *,
0235                 void **);
0236 
0237 int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root);
0238 void nilfs_detach_log_writer(struct super_block *sb);
0239 
0240 /* recovery.c */
0241 extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t,
0242                        struct buffer_head **, int);
0243 extern int nilfs_search_super_root(struct the_nilfs *,
0244                    struct nilfs_recovery_info *);
0245 int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, struct super_block *sb,
0246                   struct nilfs_recovery_info *ri);
0247 extern void nilfs_dispose_segment_list(struct list_head *);
0248 
0249 #endif /* _NILFS_SEGMENT_H */