xref: /openbmc/linux/fs/nilfs2/segment.h (revision 7554e9c4cfa208acf3164a86c05aaa967b043425)
19ff05123SRyusuke Konishi /*
29ff05123SRyusuke Konishi  * segment.h - NILFS Segment constructor prototypes and definitions
39ff05123SRyusuke Konishi  *
49ff05123SRyusuke Konishi  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
59ff05123SRyusuke Konishi  *
69ff05123SRyusuke Konishi  * This program is free software; you can redistribute it and/or modify
79ff05123SRyusuke Konishi  * it under the terms of the GNU General Public License as published by
89ff05123SRyusuke Konishi  * the Free Software Foundation; either version 2 of the License, or
99ff05123SRyusuke Konishi  * (at your option) any later version.
109ff05123SRyusuke Konishi  *
119ff05123SRyusuke Konishi  * This program is distributed in the hope that it will be useful,
129ff05123SRyusuke Konishi  * but WITHOUT ANY WARRANTY; without even the implied warranty of
139ff05123SRyusuke Konishi  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
149ff05123SRyusuke Konishi  * GNU General Public License for more details.
159ff05123SRyusuke Konishi  *
164b420ab4SRyusuke Konishi  * Written by Ryusuke Konishi.
179ff05123SRyusuke Konishi  *
189ff05123SRyusuke Konishi  */
199ff05123SRyusuke Konishi #ifndef _NILFS_SEGMENT_H
209ff05123SRyusuke Konishi #define _NILFS_SEGMENT_H
219ff05123SRyusuke Konishi 
229ff05123SRyusuke Konishi #include <linux/types.h>
239ff05123SRyusuke Konishi #include <linux/fs.h>
249ff05123SRyusuke Konishi #include <linux/buffer_head.h>
257ef3ff2fSRyusuke Konishi #include <linux/workqueue.h>
26e3154e97SRyusuke Konishi #include "nilfs.h"
279ff05123SRyusuke Konishi 
28e912a5b6SRyusuke Konishi struct nilfs_root;
29e912a5b6SRyusuke Konishi 
309ff05123SRyusuke Konishi /**
317a65004bSRyusuke Konishi  * struct nilfs_recovery_info - Recovery information
329ff05123SRyusuke Konishi  * @ri_need_recovery: Recovery status
339ff05123SRyusuke Konishi  * @ri_super_root: Block number of the last super root
349ff05123SRyusuke Konishi  * @ri_ri_cno: Number of the last checkpoint
359ff05123SRyusuke Konishi  * @ri_lsegs_start: Region for roll-forwarding (start block number)
369ff05123SRyusuke Konishi  * @ri_lsegs_end: Region for roll-forwarding (end block number)
379ff05123SRyusuke Konishi  * @ri_lseg_start_seq: Sequence value of the segment at ri_lsegs_start
389ff05123SRyusuke Konishi  * @ri_used_segments: List of segments to be mark active
399ff05123SRyusuke Konishi  * @ri_pseg_start: Block number of the last partial segment
409ff05123SRyusuke Konishi  * @ri_seq: Sequence number on the last partial segment
419ff05123SRyusuke Konishi  * @ri_segnum: Segment number on the last partial segment
429ff05123SRyusuke Konishi  * @ri_nextnum: Next segment number on the last partial segment
439ff05123SRyusuke Konishi  */
449ff05123SRyusuke Konishi struct nilfs_recovery_info {
459ff05123SRyusuke Konishi 	int			ri_need_recovery;
469ff05123SRyusuke Konishi 	sector_t		ri_super_root;
479ff05123SRyusuke Konishi 	__u64			ri_cno;
489ff05123SRyusuke Konishi 
499ff05123SRyusuke Konishi 	sector_t		ri_lsegs_start;
509ff05123SRyusuke Konishi 	sector_t		ri_lsegs_end;
519ff05123SRyusuke Konishi 	u64			ri_lsegs_start_seq;
529ff05123SRyusuke Konishi 	struct list_head	ri_used_segments;
539ff05123SRyusuke Konishi 	sector_t		ri_pseg_start;
549ff05123SRyusuke Konishi 	u64			ri_seq;
559ff05123SRyusuke Konishi 	__u64			ri_segnum;
569ff05123SRyusuke Konishi 	__u64			ri_nextnum;
579ff05123SRyusuke Konishi };
589ff05123SRyusuke Konishi 
599ff05123SRyusuke Konishi /* ri_need_recovery */
609ff05123SRyusuke Konishi #define NILFS_RECOVERY_SR_UPDATED	 1  /* The super root was updated */
619ff05123SRyusuke Konishi #define NILFS_RECOVERY_ROLLFORWARD_DONE	 2  /* Rollforward was carried out */
629ff05123SRyusuke Konishi 
639ff05123SRyusuke Konishi /**
649ff05123SRyusuke Konishi  * struct nilfs_cstage - Context of collection stage
6558497703SHitoshi Mitake  * @scnt: Stage count, must be accessed via wrappers:
6658497703SHitoshi Mitake  *        nilfs_sc_cstage_inc(), nilfs_sc_cstage_set(), nilfs_sc_cstage_get()
679ff05123SRyusuke Konishi  * @flags: State flags
689ff05123SRyusuke Konishi  * @dirty_file_ptr: Pointer on dirty_files list, or inode of a target file
699ff05123SRyusuke Konishi  * @gc_inode_ptr: Pointer on the list of gc-inodes
709ff05123SRyusuke Konishi  */
719ff05123SRyusuke Konishi struct nilfs_cstage {
729ff05123SRyusuke Konishi 	int			scnt;
730c6c44cbSRyusuke Konishi 	unsigned int		flags;
749ff05123SRyusuke Konishi 	struct nilfs_inode_info *dirty_file_ptr;
759ff05123SRyusuke Konishi 	struct nilfs_inode_info *gc_inode_ptr;
769ff05123SRyusuke Konishi };
779ff05123SRyusuke Konishi 
789ff05123SRyusuke Konishi struct nilfs_segment_buffer;
799ff05123SRyusuke Konishi 
809ff05123SRyusuke Konishi struct nilfs_segsum_pointer {
819ff05123SRyusuke Konishi 	struct buffer_head     *bh;
820c6c44cbSRyusuke Konishi 	unsigned int		offset; /* offset in bytes */
839ff05123SRyusuke Konishi };
849ff05123SRyusuke Konishi 
859ff05123SRyusuke Konishi /**
869ff05123SRyusuke Konishi  * struct nilfs_sc_info - Segment constructor information
879ff05123SRyusuke Konishi  * @sc_super: Back pointer to super_block struct
88e912a5b6SRyusuke Konishi  * @sc_root: root object of the current filesystem tree
899ff05123SRyusuke Konishi  * @sc_nblk_inc: Block count of current generation
909ff05123SRyusuke Konishi  * @sc_dirty_files: List of files to be written
919ff05123SRyusuke Konishi  * @sc_gc_inodes: List of GC inodes having blocks to be written
927ef3ff2fSRyusuke Konishi  * @sc_iput_queue: list of inodes for which iput should be done
937ef3ff2fSRyusuke Konishi  * @sc_iput_work: work struct to defer iput call
94071cb4b8SRyusuke Konishi  * @sc_freesegs: array of segment numbers to be freed
95071cb4b8SRyusuke Konishi  * @sc_nfreesegs: number of segments on @sc_freesegs
96f30bf3e4SRyusuke Konishi  * @sc_dsync_inode: inode whose data pages are written for a sync operation
97f30bf3e4SRyusuke Konishi  * @sc_dsync_start: start byte offset of data pages
98f30bf3e4SRyusuke Konishi  * @sc_dsync_end: end byte offset of data pages (inclusive)
999ff05123SRyusuke Konishi  * @sc_segbufs: List of segment buffers
100a694291aSRyusuke Konishi  * @sc_write_logs: List of segment buffers to hold logs under writing
1019ff05123SRyusuke Konishi  * @sc_segbuf_nblocks: Number of available blocks in segment buffers.
1029ff05123SRyusuke Konishi  * @sc_curseg: Current segment buffer
1039ff05123SRyusuke Konishi  * @sc_stage: Collection stage
1049ff05123SRyusuke Konishi  * @sc_finfo_ptr: pointer to the current finfo struct in the segment summary
1059ff05123SRyusuke Konishi  * @sc_binfo_ptr: pointer to the current binfo struct in the segment summary
1069ff05123SRyusuke Konishi  * @sc_blk_cnt:	Block count of a file
1079ff05123SRyusuke Konishi  * @sc_datablk_cnt: Data block count of a file
1089ff05123SRyusuke Konishi  * @sc_nblk_this_inc: Number of blocks included in the current logical segment
1099ff05123SRyusuke Konishi  * @sc_seg_ctime: Creation time
1106c43f410SRyusuke Konishi  * @sc_cno: checkpoint number of current log
1119ff05123SRyusuke Konishi  * @sc_flags: Internal flags
1129ff05123SRyusuke Konishi  * @sc_state_lock: spinlock for sc_state and so on
1139ff05123SRyusuke Konishi  * @sc_state: Segctord state flags
1149ff05123SRyusuke Konishi  * @sc_flush_request: inode bitmap of metadata files to be flushed
1159ff05123SRyusuke Konishi  * @sc_wait_request: Client request queue
1169ff05123SRyusuke Konishi  * @sc_wait_daemon: Daemon wait queue
1179ff05123SRyusuke Konishi  * @sc_wait_task: Start/end wait queue to control segctord task
1189ff05123SRyusuke Konishi  * @sc_seq_request: Request counter
119dcd76186SRyusuke Konishi  * @sc_seq_accept: Accepted request count
1209ff05123SRyusuke Konishi  * @sc_seq_done: Completion counter
1219ff05123SRyusuke Konishi  * @sc_sync: Request of explicit sync operation
1229ff05123SRyusuke Konishi  * @sc_interval: Timeout value of background construction
1239ff05123SRyusuke Konishi  * @sc_mjcp_freq: Frequency of creating checkpoints
1249ff05123SRyusuke Konishi  * @sc_lseg_stime: Start time of the latest logical segment
1259ff05123SRyusuke Konishi  * @sc_watermark: Watermark for the number of dirty buffers
1269ff05123SRyusuke Konishi  * @sc_timer: Timer for segctord
1279ff05123SRyusuke Konishi  * @sc_task: current thread of segctord
1289ff05123SRyusuke Konishi  */
1299ff05123SRyusuke Konishi struct nilfs_sc_info {
1309ff05123SRyusuke Konishi 	struct super_block     *sc_super;
131e912a5b6SRyusuke Konishi 	struct nilfs_root      *sc_root;
1329ff05123SRyusuke Konishi 
1339ff05123SRyusuke Konishi 	unsigned long		sc_nblk_inc;
1349ff05123SRyusuke Konishi 
1359ff05123SRyusuke Konishi 	struct list_head	sc_dirty_files;
1369ff05123SRyusuke Konishi 	struct list_head	sc_gc_inodes;
1377ef3ff2fSRyusuke Konishi 	struct list_head	sc_iput_queue;
1387ef3ff2fSRyusuke Konishi 	struct work_struct	sc_iput_work;
1399ff05123SRyusuke Konishi 
140071cb4b8SRyusuke Konishi 	__u64		       *sc_freesegs;
141071cb4b8SRyusuke Konishi 	size_t			sc_nfreesegs;
142071cb4b8SRyusuke Konishi 
143f30bf3e4SRyusuke Konishi 	struct nilfs_inode_info *sc_dsync_inode;
144f30bf3e4SRyusuke Konishi 	loff_t			sc_dsync_start;
145f30bf3e4SRyusuke Konishi 	loff_t			sc_dsync_end;
146f30bf3e4SRyusuke Konishi 
1479ff05123SRyusuke Konishi 	/* Segment buffers */
1489ff05123SRyusuke Konishi 	struct list_head	sc_segbufs;
149a694291aSRyusuke Konishi 	struct list_head	sc_write_logs;
1509ff05123SRyusuke Konishi 	unsigned long		sc_segbuf_nblocks;
1519ff05123SRyusuke Konishi 	struct nilfs_segment_buffer *sc_curseg;
1529ff05123SRyusuke Konishi 
1539ff05123SRyusuke Konishi 	struct nilfs_cstage	sc_stage;
1549ff05123SRyusuke Konishi 
1559ff05123SRyusuke Konishi 	struct nilfs_segsum_pointer sc_finfo_ptr;
1569ff05123SRyusuke Konishi 	struct nilfs_segsum_pointer sc_binfo_ptr;
1579ff05123SRyusuke Konishi 	unsigned long		sc_blk_cnt;
1589ff05123SRyusuke Konishi 	unsigned long		sc_datablk_cnt;
1599ff05123SRyusuke Konishi 	unsigned long		sc_nblk_this_inc;
1609ff05123SRyusuke Konishi 	time_t			sc_seg_ctime;
1616c43f410SRyusuke Konishi 	__u64			sc_cno;
1629ff05123SRyusuke Konishi 	unsigned long		sc_flags;
1639ff05123SRyusuke Konishi 
1649ff05123SRyusuke Konishi 	spinlock_t		sc_state_lock;
1659ff05123SRyusuke Konishi 	unsigned long		sc_state;
1669ff05123SRyusuke Konishi 	unsigned long		sc_flush_request;
1679ff05123SRyusuke Konishi 
1689ff05123SRyusuke Konishi 	wait_queue_head_t	sc_wait_request;
1699ff05123SRyusuke Konishi 	wait_queue_head_t	sc_wait_daemon;
1709ff05123SRyusuke Konishi 	wait_queue_head_t	sc_wait_task;
1719ff05123SRyusuke Konishi 
1729ff05123SRyusuke Konishi 	__u32			sc_seq_request;
173dcd76186SRyusuke Konishi 	__u32			sc_seq_accepted;
1749ff05123SRyusuke Konishi 	__u32			sc_seq_done;
1759ff05123SRyusuke Konishi 
1769ff05123SRyusuke Konishi 	int			sc_sync;
1779ff05123SRyusuke Konishi 	unsigned long		sc_interval;
1789ff05123SRyusuke Konishi 	unsigned long		sc_mjcp_freq;
1799ff05123SRyusuke Konishi 	unsigned long		sc_lseg_stime;	/* in 1/HZ seconds */
1809ff05123SRyusuke Konishi 	unsigned long		sc_watermark;
1819ff05123SRyusuke Konishi 
182fdce895eSLi Hong 	struct timer_list	sc_timer;
183*7554e9c4SKees Cook 	struct task_struct     *sc_timer_task;
1849ff05123SRyusuke Konishi 	struct task_struct     *sc_task;
1859ff05123SRyusuke Konishi };
1869ff05123SRyusuke Konishi 
1879ff05123SRyusuke Konishi /* sc_flags */
1889ff05123SRyusuke Konishi enum {
1899ff05123SRyusuke Konishi 	NILFS_SC_DIRTY,		/* One or more dirty meta-data blocks exist */
1909ff05123SRyusuke Konishi 	NILFS_SC_UNCLOSED,	/* Logical segment is not closed */
1919ff05123SRyusuke Konishi 	NILFS_SC_SUPER_ROOT,	/* The latest segment has a super root */
192076a378bSRyusuke Konishi 	NILFS_SC_PRIOR_FLUSH,	/*
193076a378bSRyusuke Konishi 				 * Requesting immediate flush without making a
194076a378bSRyusuke Konishi 				 * checkpoint
195076a378bSRyusuke Konishi 				 */
196076a378bSRyusuke Konishi 	NILFS_SC_HAVE_DELTA,	/*
197076a378bSRyusuke Konishi 				 * Next checkpoint will have update of files
198076a378bSRyusuke Konishi 				 * other than DAT, cpfile, sufile, or files
199076a378bSRyusuke Konishi 				 * moved by GC.
200076a378bSRyusuke Konishi 				 */
2019ff05123SRyusuke Konishi };
2029ff05123SRyusuke Konishi 
2039ff05123SRyusuke Konishi /* sc_state */
2049ff05123SRyusuke Konishi #define NILFS_SEGCTOR_QUIT	    0x0001  /* segctord is being destroyed */
2059ff05123SRyusuke Konishi #define NILFS_SEGCTOR_COMMIT	    0x0004  /* committed transaction exists */
2069ff05123SRyusuke Konishi 
2079ff05123SRyusuke Konishi /*
2089ff05123SRyusuke Konishi  * Constant parameters
2099ff05123SRyusuke Konishi  */
210076a378bSRyusuke Konishi #define NILFS_SC_CLEANUP_RETRY	    3  /*
211076a378bSRyusuke Konishi 					* Retry count of construction when
212076a378bSRyusuke Konishi 					* destroying segctord
213076a378bSRyusuke Konishi 					*/
2149ff05123SRyusuke Konishi 
2159ff05123SRyusuke Konishi /*
2169ff05123SRyusuke Konishi  * Default values of timeout, in seconds.
2179ff05123SRyusuke Konishi  */
218076a378bSRyusuke Konishi #define NILFS_SC_DEFAULT_TIMEOUT    5   /*
219076a378bSRyusuke Konishi 					 * Timeout value of dirty blocks.
220076a378bSRyusuke Konishi 					 * It triggers construction of a
221076a378bSRyusuke Konishi 					 * logical segment with a super root.
222076a378bSRyusuke Konishi 					 */
223076a378bSRyusuke Konishi #define NILFS_SC_DEFAULT_SR_FREQ    30  /*
224076a378bSRyusuke Konishi 					 * Maximum frequency of super root
225076a378bSRyusuke Konishi 					 * creation
226076a378bSRyusuke Konishi 					 */
2279ff05123SRyusuke Konishi 
2289ff05123SRyusuke Konishi /*
2299ff05123SRyusuke Konishi  * The default threshold amount of data, in block counts.
2309ff05123SRyusuke Konishi  */
2319ff05123SRyusuke Konishi #define NILFS_SC_DEFAULT_WATERMARK  3600
2329ff05123SRyusuke Konishi 
23341c88bd7SLi Hong /* super.c */
23441c88bd7SLi Hong extern struct kmem_cache *nilfs_transaction_cachep;
2359ff05123SRyusuke Konishi 
2369ff05123SRyusuke Konishi /* segment.c */
2379ff05123SRyusuke Konishi extern void nilfs_relax_pressure_in_lock(struct super_block *);
2389ff05123SRyusuke Konishi 
2399ff05123SRyusuke Konishi extern int nilfs_construct_segment(struct super_block *);
240f30bf3e4SRyusuke Konishi extern int nilfs_construct_dsync_segment(struct super_block *, struct inode *,
241f30bf3e4SRyusuke Konishi 					 loff_t, loff_t);
2429ff05123SRyusuke Konishi extern void nilfs_flush_segment(struct super_block *, ino_t);
2434f6b8288SRyusuke Konishi extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *,
2444f6b8288SRyusuke Konishi 				void **);
2459ff05123SRyusuke Konishi 
246f7545144SRyusuke Konishi int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root);
247f7545144SRyusuke Konishi void nilfs_detach_log_writer(struct super_block *sb);
2489ff05123SRyusuke Konishi 
2499ff05123SRyusuke Konishi /* recovery.c */
2508b94025cSRyusuke Konishi extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t,
2519ff05123SRyusuke Konishi 				       struct buffer_head **, int);
2528b94025cSRyusuke Konishi extern int nilfs_search_super_root(struct the_nilfs *,
2539ff05123SRyusuke Konishi 				   struct nilfs_recovery_info *);
254f7545144SRyusuke Konishi int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, struct super_block *sb,
255f7545144SRyusuke Konishi 			      struct nilfs_recovery_info *ri);
256654137ddSRyusuke Konishi extern void nilfs_dispose_segment_list(struct list_head *);
2579ff05123SRyusuke Konishi 
2589ff05123SRyusuke Konishi #endif /* _NILFS_SEGMENT_H */
259