xref: /openbmc/linux/fs/nilfs2/segment.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1ae98043fSRyusuke Konishi /* SPDX-License-Identifier: GPL-2.0+ */
29ff05123SRyusuke Konishi /*
3*94ee1d91SRyusuke Konishi  * NILFS Segment constructor prototypes and definitions
49ff05123SRyusuke Konishi  *
59ff05123SRyusuke Konishi  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
69ff05123SRyusuke Konishi  *
74b420ab4SRyusuke Konishi  * Written by Ryusuke Konishi.
89ff05123SRyusuke Konishi  *
99ff05123SRyusuke Konishi  */
109ff05123SRyusuke Konishi #ifndef _NILFS_SEGMENT_H
119ff05123SRyusuke Konishi #define _NILFS_SEGMENT_H
129ff05123SRyusuke Konishi 
139ff05123SRyusuke Konishi #include <linux/types.h>
149ff05123SRyusuke Konishi #include <linux/fs.h>
159ff05123SRyusuke Konishi #include <linux/buffer_head.h>
167ef3ff2fSRyusuke Konishi #include <linux/workqueue.h>
17e3154e97SRyusuke Konishi #include "nilfs.h"
189ff05123SRyusuke Konishi 
19e912a5b6SRyusuke Konishi struct nilfs_root;
20e912a5b6SRyusuke Konishi 
219ff05123SRyusuke Konishi /**
227a65004bSRyusuke Konishi  * struct nilfs_recovery_info - Recovery information
239ff05123SRyusuke Konishi  * @ri_need_recovery: Recovery status
249ff05123SRyusuke Konishi  * @ri_super_root: Block number of the last super root
259ff05123SRyusuke Konishi  * @ri_ri_cno: Number of the last checkpoint
269ff05123SRyusuke Konishi  * @ri_lsegs_start: Region for roll-forwarding (start block number)
279ff05123SRyusuke Konishi  * @ri_lsegs_end: Region for roll-forwarding (end block number)
289ff05123SRyusuke Konishi  * @ri_lseg_start_seq: Sequence value of the segment at ri_lsegs_start
299ff05123SRyusuke Konishi  * @ri_used_segments: List of segments to be mark active
309ff05123SRyusuke Konishi  * @ri_pseg_start: Block number of the last partial segment
319ff05123SRyusuke Konishi  * @ri_seq: Sequence number on the last partial segment
329ff05123SRyusuke Konishi  * @ri_segnum: Segment number on the last partial segment
339ff05123SRyusuke Konishi  * @ri_nextnum: Next segment number on the last partial segment
349ff05123SRyusuke Konishi  */
359ff05123SRyusuke Konishi struct nilfs_recovery_info {
369ff05123SRyusuke Konishi 	int			ri_need_recovery;
379ff05123SRyusuke Konishi 	sector_t		ri_super_root;
389ff05123SRyusuke Konishi 	__u64			ri_cno;
399ff05123SRyusuke Konishi 
409ff05123SRyusuke Konishi 	sector_t		ri_lsegs_start;
419ff05123SRyusuke Konishi 	sector_t		ri_lsegs_end;
429ff05123SRyusuke Konishi 	u64			ri_lsegs_start_seq;
439ff05123SRyusuke Konishi 	struct list_head	ri_used_segments;
449ff05123SRyusuke Konishi 	sector_t		ri_pseg_start;
459ff05123SRyusuke Konishi 	u64			ri_seq;
469ff05123SRyusuke Konishi 	__u64			ri_segnum;
479ff05123SRyusuke Konishi 	__u64			ri_nextnum;
489ff05123SRyusuke Konishi };
499ff05123SRyusuke Konishi 
509ff05123SRyusuke Konishi /* ri_need_recovery */
519ff05123SRyusuke Konishi #define NILFS_RECOVERY_SR_UPDATED	 1  /* The super root was updated */
529ff05123SRyusuke Konishi #define NILFS_RECOVERY_ROLLFORWARD_DONE	 2  /* Rollforward was carried out */
539ff05123SRyusuke Konishi 
549ff05123SRyusuke Konishi /**
559ff05123SRyusuke Konishi  * struct nilfs_cstage - Context of collection stage
5658497703SHitoshi Mitake  * @scnt: Stage count, must be accessed via wrappers:
5758497703SHitoshi Mitake  *        nilfs_sc_cstage_inc(), nilfs_sc_cstage_set(), nilfs_sc_cstage_get()
589ff05123SRyusuke Konishi  * @flags: State flags
599ff05123SRyusuke Konishi  * @dirty_file_ptr: Pointer on dirty_files list, or inode of a target file
609ff05123SRyusuke Konishi  * @gc_inode_ptr: Pointer on the list of gc-inodes
619ff05123SRyusuke Konishi  */
629ff05123SRyusuke Konishi struct nilfs_cstage {
639ff05123SRyusuke Konishi 	int			scnt;
640c6c44cbSRyusuke Konishi 	unsigned int		flags;
659ff05123SRyusuke Konishi 	struct nilfs_inode_info *dirty_file_ptr;
669ff05123SRyusuke Konishi 	struct nilfs_inode_info *gc_inode_ptr;
679ff05123SRyusuke Konishi };
689ff05123SRyusuke Konishi 
699ff05123SRyusuke Konishi struct nilfs_segment_buffer;
709ff05123SRyusuke Konishi 
719ff05123SRyusuke Konishi struct nilfs_segsum_pointer {
729ff05123SRyusuke Konishi 	struct buffer_head     *bh;
730c6c44cbSRyusuke Konishi 	unsigned int		offset; /* offset in bytes */
749ff05123SRyusuke Konishi };
759ff05123SRyusuke Konishi 
769ff05123SRyusuke Konishi /**
779ff05123SRyusuke Konishi  * struct nilfs_sc_info - Segment constructor information
789ff05123SRyusuke Konishi  * @sc_super: Back pointer to super_block struct
79e912a5b6SRyusuke Konishi  * @sc_root: root object of the current filesystem tree
809ff05123SRyusuke Konishi  * @sc_nblk_inc: Block count of current generation
819ff05123SRyusuke Konishi  * @sc_dirty_files: List of files to be written
829ff05123SRyusuke Konishi  * @sc_gc_inodes: List of GC inodes having blocks to be written
837ef3ff2fSRyusuke Konishi  * @sc_iput_queue: list of inodes for which iput should be done
847ef3ff2fSRyusuke Konishi  * @sc_iput_work: work struct to defer iput call
85071cb4b8SRyusuke Konishi  * @sc_freesegs: array of segment numbers to be freed
86071cb4b8SRyusuke Konishi  * @sc_nfreesegs: number of segments on @sc_freesegs
87f30bf3e4SRyusuke Konishi  * @sc_dsync_inode: inode whose data pages are written for a sync operation
88f30bf3e4SRyusuke Konishi  * @sc_dsync_start: start byte offset of data pages
89f30bf3e4SRyusuke Konishi  * @sc_dsync_end: end byte offset of data pages (inclusive)
909ff05123SRyusuke Konishi  * @sc_segbufs: List of segment buffers
91a694291aSRyusuke Konishi  * @sc_write_logs: List of segment buffers to hold logs under writing
929ff05123SRyusuke Konishi  * @sc_segbuf_nblocks: Number of available blocks in segment buffers.
939ff05123SRyusuke Konishi  * @sc_curseg: Current segment buffer
949ff05123SRyusuke Konishi  * @sc_stage: Collection stage
959ff05123SRyusuke Konishi  * @sc_finfo_ptr: pointer to the current finfo struct in the segment summary
969ff05123SRyusuke Konishi  * @sc_binfo_ptr: pointer to the current binfo struct in the segment summary
979ff05123SRyusuke Konishi  * @sc_blk_cnt:	Block count of a file
989ff05123SRyusuke Konishi  * @sc_datablk_cnt: Data block count of a file
999ff05123SRyusuke Konishi  * @sc_nblk_this_inc: Number of blocks included in the current logical segment
1009ff05123SRyusuke Konishi  * @sc_seg_ctime: Creation time
1016c43f410SRyusuke Konishi  * @sc_cno: checkpoint number of current log
1029ff05123SRyusuke Konishi  * @sc_flags: Internal flags
1039ff05123SRyusuke Konishi  * @sc_state_lock: spinlock for sc_state and so on
1049ff05123SRyusuke Konishi  * @sc_state: Segctord state flags
1059ff05123SRyusuke Konishi  * @sc_flush_request: inode bitmap of metadata files to be flushed
1069ff05123SRyusuke Konishi  * @sc_wait_request: Client request queue
1079ff05123SRyusuke Konishi  * @sc_wait_daemon: Daemon wait queue
1089ff05123SRyusuke Konishi  * @sc_wait_task: Start/end wait queue to control segctord task
1099ff05123SRyusuke Konishi  * @sc_seq_request: Request counter
110dcd76186SRyusuke Konishi  * @sc_seq_accept: Accepted request count
1119ff05123SRyusuke Konishi  * @sc_seq_done: Completion counter
1129ff05123SRyusuke Konishi  * @sc_sync: Request of explicit sync operation
1139ff05123SRyusuke Konishi  * @sc_interval: Timeout value of background construction
1149ff05123SRyusuke Konishi  * @sc_mjcp_freq: Frequency of creating checkpoints
1159ff05123SRyusuke Konishi  * @sc_lseg_stime: Start time of the latest logical segment
1169ff05123SRyusuke Konishi  * @sc_watermark: Watermark for the number of dirty buffers
1179ff05123SRyusuke Konishi  * @sc_timer: Timer for segctord
1189ff05123SRyusuke Konishi  * @sc_task: current thread of segctord
1199ff05123SRyusuke Konishi  */
1209ff05123SRyusuke Konishi struct nilfs_sc_info {
1219ff05123SRyusuke Konishi 	struct super_block     *sc_super;
122e912a5b6SRyusuke Konishi 	struct nilfs_root      *sc_root;
1239ff05123SRyusuke Konishi 
1249ff05123SRyusuke Konishi 	unsigned long		sc_nblk_inc;
1259ff05123SRyusuke Konishi 
1269ff05123SRyusuke Konishi 	struct list_head	sc_dirty_files;
1279ff05123SRyusuke Konishi 	struct list_head	sc_gc_inodes;
1287ef3ff2fSRyusuke Konishi 	struct list_head	sc_iput_queue;
1297ef3ff2fSRyusuke Konishi 	struct work_struct	sc_iput_work;
1309ff05123SRyusuke Konishi 
131071cb4b8SRyusuke Konishi 	__u64		       *sc_freesegs;
132071cb4b8SRyusuke Konishi 	size_t			sc_nfreesegs;
133071cb4b8SRyusuke Konishi 
134f30bf3e4SRyusuke Konishi 	struct nilfs_inode_info *sc_dsync_inode;
135f30bf3e4SRyusuke Konishi 	loff_t			sc_dsync_start;
136f30bf3e4SRyusuke Konishi 	loff_t			sc_dsync_end;
137f30bf3e4SRyusuke Konishi 
1389ff05123SRyusuke Konishi 	/* Segment buffers */
1399ff05123SRyusuke Konishi 	struct list_head	sc_segbufs;
140a694291aSRyusuke Konishi 	struct list_head	sc_write_logs;
1419ff05123SRyusuke Konishi 	unsigned long		sc_segbuf_nblocks;
1429ff05123SRyusuke Konishi 	struct nilfs_segment_buffer *sc_curseg;
1439ff05123SRyusuke Konishi 
1449ff05123SRyusuke Konishi 	struct nilfs_cstage	sc_stage;
1459ff05123SRyusuke Konishi 
1469ff05123SRyusuke Konishi 	struct nilfs_segsum_pointer sc_finfo_ptr;
1479ff05123SRyusuke Konishi 	struct nilfs_segsum_pointer sc_binfo_ptr;
1489ff05123SRyusuke Konishi 	unsigned long		sc_blk_cnt;
1499ff05123SRyusuke Konishi 	unsigned long		sc_datablk_cnt;
1509ff05123SRyusuke Konishi 	unsigned long		sc_nblk_this_inc;
151fb04b91bSArnd Bergmann 	time64_t		sc_seg_ctime;
1526c43f410SRyusuke Konishi 	__u64			sc_cno;
1539ff05123SRyusuke Konishi 	unsigned long		sc_flags;
1549ff05123SRyusuke Konishi 
1559ff05123SRyusuke Konishi 	spinlock_t		sc_state_lock;
1569ff05123SRyusuke Konishi 	unsigned long		sc_state;
1579ff05123SRyusuke Konishi 	unsigned long		sc_flush_request;
1589ff05123SRyusuke Konishi 
1599ff05123SRyusuke Konishi 	wait_queue_head_t	sc_wait_request;
1609ff05123SRyusuke Konishi 	wait_queue_head_t	sc_wait_daemon;
1619ff05123SRyusuke Konishi 	wait_queue_head_t	sc_wait_task;
1629ff05123SRyusuke Konishi 
1639ff05123SRyusuke Konishi 	__u32			sc_seq_request;
164dcd76186SRyusuke Konishi 	__u32			sc_seq_accepted;
1659ff05123SRyusuke Konishi 	__u32			sc_seq_done;
1669ff05123SRyusuke Konishi 
1679ff05123SRyusuke Konishi 	int			sc_sync;
1689ff05123SRyusuke Konishi 	unsigned long		sc_interval;
1699ff05123SRyusuke Konishi 	unsigned long		sc_mjcp_freq;
1709ff05123SRyusuke Konishi 	unsigned long		sc_lseg_stime;	/* in 1/HZ seconds */
1719ff05123SRyusuke Konishi 	unsigned long		sc_watermark;
1729ff05123SRyusuke Konishi 
173fdce895eSLi Hong 	struct timer_list	sc_timer;
1747554e9c4SKees Cook 	struct task_struct     *sc_timer_task;
1759ff05123SRyusuke Konishi 	struct task_struct     *sc_task;
1769ff05123SRyusuke Konishi };
1779ff05123SRyusuke Konishi 
1789ff05123SRyusuke Konishi /* sc_flags */
1799ff05123SRyusuke Konishi enum {
1809ff05123SRyusuke Konishi 	NILFS_SC_DIRTY,		/* One or more dirty meta-data blocks exist */
1819ff05123SRyusuke Konishi 	NILFS_SC_UNCLOSED,	/* Logical segment is not closed */
1829ff05123SRyusuke Konishi 	NILFS_SC_SUPER_ROOT,	/* The latest segment has a super root */
183076a378bSRyusuke Konishi 	NILFS_SC_PRIOR_FLUSH,	/*
184076a378bSRyusuke Konishi 				 * Requesting immediate flush without making a
185076a378bSRyusuke Konishi 				 * checkpoint
186076a378bSRyusuke Konishi 				 */
187076a378bSRyusuke Konishi 	NILFS_SC_HAVE_DELTA,	/*
188076a378bSRyusuke Konishi 				 * Next checkpoint will have update of files
189076a378bSRyusuke Konishi 				 * other than DAT, cpfile, sufile, or files
190076a378bSRyusuke Konishi 				 * moved by GC.
191076a378bSRyusuke Konishi 				 */
1929ff05123SRyusuke Konishi };
1939ff05123SRyusuke Konishi 
1949ff05123SRyusuke Konishi /* sc_state */
1959ff05123SRyusuke Konishi #define NILFS_SEGCTOR_QUIT	    0x0001  /* segctord is being destroyed */
1969ff05123SRyusuke Konishi #define NILFS_SEGCTOR_COMMIT	    0x0004  /* committed transaction exists */
1979ff05123SRyusuke Konishi 
1989ff05123SRyusuke Konishi /*
1999ff05123SRyusuke Konishi  * Constant parameters
2009ff05123SRyusuke Konishi  */
201076a378bSRyusuke Konishi #define NILFS_SC_CLEANUP_RETRY	    3  /*
202076a378bSRyusuke Konishi 					* Retry count of construction when
203076a378bSRyusuke Konishi 					* destroying segctord
204076a378bSRyusuke Konishi 					*/
2059ff05123SRyusuke Konishi 
2069ff05123SRyusuke Konishi /*
2079ff05123SRyusuke Konishi  * Default values of timeout, in seconds.
2089ff05123SRyusuke Konishi  */
209076a378bSRyusuke Konishi #define NILFS_SC_DEFAULT_TIMEOUT    5   /*
210076a378bSRyusuke Konishi 					 * Timeout value of dirty blocks.
211076a378bSRyusuke Konishi 					 * It triggers construction of a
212076a378bSRyusuke Konishi 					 * logical segment with a super root.
213076a378bSRyusuke Konishi 					 */
214076a378bSRyusuke Konishi #define NILFS_SC_DEFAULT_SR_FREQ    30  /*
215076a378bSRyusuke Konishi 					 * Maximum frequency of super root
216076a378bSRyusuke Konishi 					 * creation
217076a378bSRyusuke Konishi 					 */
2189ff05123SRyusuke Konishi 
2199ff05123SRyusuke Konishi /*
2209ff05123SRyusuke Konishi  * The default threshold amount of data, in block counts.
2219ff05123SRyusuke Konishi  */
2229ff05123SRyusuke Konishi #define NILFS_SC_DEFAULT_WATERMARK  3600
2239ff05123SRyusuke Konishi 
22441c88bd7SLi Hong /* super.c */
22541c88bd7SLi Hong extern struct kmem_cache *nilfs_transaction_cachep;
2269ff05123SRyusuke Konishi 
2279ff05123SRyusuke Konishi /* segment.c */
2289ff05123SRyusuke Konishi extern void nilfs_relax_pressure_in_lock(struct super_block *);
2299ff05123SRyusuke Konishi 
2309ff05123SRyusuke Konishi extern int nilfs_construct_segment(struct super_block *);
231f30bf3e4SRyusuke Konishi extern int nilfs_construct_dsync_segment(struct super_block *, struct inode *,
232f30bf3e4SRyusuke Konishi 					 loff_t, loff_t);
2339ff05123SRyusuke Konishi extern void nilfs_flush_segment(struct super_block *, ino_t);
2344f6b8288SRyusuke Konishi extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *,
2354f6b8288SRyusuke Konishi 				void **);
2369ff05123SRyusuke Konishi 
237f7545144SRyusuke Konishi int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root);
238f7545144SRyusuke Konishi void nilfs_detach_log_writer(struct super_block *sb);
2399ff05123SRyusuke Konishi 
2409ff05123SRyusuke Konishi /* recovery.c */
2418b94025cSRyusuke Konishi extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t,
2429ff05123SRyusuke Konishi 				       struct buffer_head **, int);
2438b94025cSRyusuke Konishi extern int nilfs_search_super_root(struct the_nilfs *,
2449ff05123SRyusuke Konishi 				   struct nilfs_recovery_info *);
245f7545144SRyusuke Konishi int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, struct super_block *sb,
246f7545144SRyusuke Konishi 			      struct nilfs_recovery_info *ri);
247654137ddSRyusuke Konishi extern void nilfs_dispose_segment_list(struct list_head *);
2489ff05123SRyusuke Konishi 
2499ff05123SRyusuke Konishi #endif /* _NILFS_SEGMENT_H */
250