xref: /openbmc/linux/fs/nilfs2/segment.h (revision 7a65004bbaa6a21a0438aac9c64814e46084dc3f)
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  *
169ff05123SRyusuke Konishi  * You should have received a copy of the GNU General Public License
179ff05123SRyusuke Konishi  * along with this program; if not, write to the Free Software
189ff05123SRyusuke Konishi  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
199ff05123SRyusuke Konishi  *
209ff05123SRyusuke Konishi  * Written by Ryusuke Konishi <ryusuke@osrg.net>
219ff05123SRyusuke Konishi  *
229ff05123SRyusuke Konishi  */
239ff05123SRyusuke Konishi #ifndef _NILFS_SEGMENT_H
249ff05123SRyusuke Konishi #define _NILFS_SEGMENT_H
259ff05123SRyusuke Konishi 
269ff05123SRyusuke Konishi #include <linux/types.h>
279ff05123SRyusuke Konishi #include <linux/fs.h>
289ff05123SRyusuke Konishi #include <linux/buffer_head.h>
299ff05123SRyusuke Konishi #include <linux/nilfs2_fs.h>
309ff05123SRyusuke Konishi #include "sb.h"
319ff05123SRyusuke Konishi 
329ff05123SRyusuke Konishi /**
33*7a65004bSRyusuke Konishi  * struct nilfs_recovery_info - Recovery information
349ff05123SRyusuke Konishi  * @ri_need_recovery: Recovery status
359ff05123SRyusuke Konishi  * @ri_super_root: Block number of the last super root
369ff05123SRyusuke Konishi  * @ri_ri_cno: Number of the last checkpoint
379ff05123SRyusuke Konishi  * @ri_lsegs_start: Region for roll-forwarding (start block number)
389ff05123SRyusuke Konishi  * @ri_lsegs_end: Region for roll-forwarding (end block number)
399ff05123SRyusuke Konishi  * @ri_lseg_start_seq: Sequence value of the segment at ri_lsegs_start
409ff05123SRyusuke Konishi  * @ri_used_segments: List of segments to be mark active
419ff05123SRyusuke Konishi  * @ri_pseg_start: Block number of the last partial segment
429ff05123SRyusuke Konishi  * @ri_seq: Sequence number on the last partial segment
439ff05123SRyusuke Konishi  * @ri_segnum: Segment number on the last partial segment
449ff05123SRyusuke Konishi  * @ri_nextnum: Next segment number on the last partial segment
459ff05123SRyusuke Konishi  */
469ff05123SRyusuke Konishi struct nilfs_recovery_info {
479ff05123SRyusuke Konishi 	int			ri_need_recovery;
489ff05123SRyusuke Konishi 	sector_t		ri_super_root;
499ff05123SRyusuke Konishi 	__u64			ri_cno;
509ff05123SRyusuke Konishi 
519ff05123SRyusuke Konishi 	sector_t		ri_lsegs_start;
529ff05123SRyusuke Konishi 	sector_t		ri_lsegs_end;
539ff05123SRyusuke Konishi 	u64			ri_lsegs_start_seq;
549ff05123SRyusuke Konishi 	struct list_head	ri_used_segments;
559ff05123SRyusuke Konishi 	sector_t		ri_pseg_start;
569ff05123SRyusuke Konishi 	u64			ri_seq;
579ff05123SRyusuke Konishi 	__u64			ri_segnum;
589ff05123SRyusuke Konishi 	__u64			ri_nextnum;
599ff05123SRyusuke Konishi };
609ff05123SRyusuke Konishi 
619ff05123SRyusuke Konishi /* ri_need_recovery */
629ff05123SRyusuke Konishi #define NILFS_RECOVERY_SR_UPDATED	 1  /* The super root was updated */
639ff05123SRyusuke Konishi #define NILFS_RECOVERY_ROLLFORWARD_DONE	 2  /* Rollforward was carried out */
649ff05123SRyusuke Konishi 
659ff05123SRyusuke Konishi /**
669ff05123SRyusuke Konishi  * struct nilfs_cstage - Context of collection stage
679ff05123SRyusuke Konishi  * @scnt: Stage count
689ff05123SRyusuke Konishi  * @flags: State flags
699ff05123SRyusuke Konishi  * @dirty_file_ptr: Pointer on dirty_files list, or inode of a target file
709ff05123SRyusuke Konishi  * @gc_inode_ptr: Pointer on the list of gc-inodes
719ff05123SRyusuke Konishi  */
729ff05123SRyusuke Konishi struct nilfs_cstage {
739ff05123SRyusuke Konishi 	int			scnt;
749ff05123SRyusuke Konishi 	unsigned 		flags;
759ff05123SRyusuke Konishi 	struct nilfs_inode_info *dirty_file_ptr;
769ff05123SRyusuke Konishi 	struct nilfs_inode_info *gc_inode_ptr;
779ff05123SRyusuke Konishi };
789ff05123SRyusuke Konishi 
799ff05123SRyusuke Konishi struct nilfs_segment_buffer;
809ff05123SRyusuke Konishi 
819ff05123SRyusuke Konishi struct nilfs_segsum_pointer {
829ff05123SRyusuke Konishi 	struct buffer_head     *bh;
839ff05123SRyusuke Konishi 	unsigned		offset; /* offset in bytes */
849ff05123SRyusuke Konishi };
859ff05123SRyusuke Konishi 
869ff05123SRyusuke Konishi /**
879ff05123SRyusuke Konishi  * struct nilfs_sc_info - Segment constructor information
889ff05123SRyusuke Konishi  * @sc_super: Back pointer to super_block struct
899ff05123SRyusuke Konishi  * @sc_sbi: Back pointer to nilfs_sb_info struct
909ff05123SRyusuke Konishi  * @sc_nblk_inc: Block count of current generation
919ff05123SRyusuke Konishi  * @sc_dirty_files: List of files to be written
929ff05123SRyusuke Konishi  * @sc_gc_inodes: List of GC inodes having blocks to be written
939ff05123SRyusuke Konishi  * @sc_copied_buffers: List of copied buffers (buffer heads) to freeze data
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_super_root: Pointer to the super root buffer
1049ff05123SRyusuke Konishi  * @sc_stage: Collection stage
1059ff05123SRyusuke Konishi  * @sc_finfo_ptr: pointer to the current finfo struct in the segment summary
1069ff05123SRyusuke Konishi  * @sc_binfo_ptr: pointer to the current binfo struct in the segment summary
1079ff05123SRyusuke Konishi  * @sc_blk_cnt:	Block count of a file
1089ff05123SRyusuke Konishi  * @sc_datablk_cnt: Data block count of a file
1099ff05123SRyusuke Konishi  * @sc_nblk_this_inc: Number of blocks included in the current logical segment
1109ff05123SRyusuke Konishi  * @sc_seg_ctime: Creation time
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;
1319ff05123SRyusuke Konishi 	struct nilfs_sb_info   *sc_sbi;
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;
1379ff05123SRyusuke Konishi 	struct list_head	sc_copied_buffers;
1389ff05123SRyusuke Konishi 
139071cb4b8SRyusuke Konishi 	__u64		       *sc_freesegs;
140071cb4b8SRyusuke Konishi 	size_t			sc_nfreesegs;
141071cb4b8SRyusuke Konishi 
142f30bf3e4SRyusuke Konishi 	struct nilfs_inode_info *sc_dsync_inode;
143f30bf3e4SRyusuke Konishi 	loff_t			sc_dsync_start;
144f30bf3e4SRyusuke Konishi 	loff_t			sc_dsync_end;
145f30bf3e4SRyusuke Konishi 
1469ff05123SRyusuke Konishi 	/* Segment buffers */
1479ff05123SRyusuke Konishi 	struct list_head	sc_segbufs;
148a694291aSRyusuke Konishi 	struct list_head	sc_write_logs;
1499ff05123SRyusuke Konishi 	unsigned long		sc_segbuf_nblocks;
1509ff05123SRyusuke Konishi 	struct nilfs_segment_buffer *sc_curseg;
1519ff05123SRyusuke Konishi 	struct buffer_head     *sc_super_root;
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;
1619ff05123SRyusuke Konishi 
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 
1829ff05123SRyusuke Konishi 	struct timer_list      *sc_timer;
1839ff05123SRyusuke Konishi 	struct task_struct     *sc_task;
1849ff05123SRyusuke Konishi };
1859ff05123SRyusuke Konishi 
1869ff05123SRyusuke Konishi /* sc_flags */
1879ff05123SRyusuke Konishi enum {
1889ff05123SRyusuke Konishi 	NILFS_SC_DIRTY,		/* One or more dirty meta-data blocks exist */
1899ff05123SRyusuke Konishi 	NILFS_SC_UNCLOSED,	/* Logical segment is not closed */
1909ff05123SRyusuke Konishi 	NILFS_SC_SUPER_ROOT,	/* The latest segment has a super root */
1919ff05123SRyusuke Konishi 	NILFS_SC_PRIOR_FLUSH,	/* Requesting immediate flush without making a
1929ff05123SRyusuke Konishi 				   checkpoint */
193c96fa464SRyusuke Konishi 	NILFS_SC_HAVE_DELTA,	/* Next checkpoint will have update of files
194c96fa464SRyusuke Konishi 				   other than DAT, cpfile, sufile, or files
195c96fa464SRyusuke Konishi 				   moved by GC */
1969ff05123SRyusuke Konishi };
1979ff05123SRyusuke Konishi 
1989ff05123SRyusuke Konishi /* sc_state */
1999ff05123SRyusuke Konishi #define NILFS_SEGCTOR_QUIT	    0x0001  /* segctord is being destroyed */
2009ff05123SRyusuke Konishi #define NILFS_SEGCTOR_COMMIT	    0x0004  /* committed transaction exists */
2019ff05123SRyusuke Konishi 
2029ff05123SRyusuke Konishi /*
2039ff05123SRyusuke Konishi  * Constant parameters
2049ff05123SRyusuke Konishi  */
2059ff05123SRyusuke Konishi #define NILFS_SC_CLEANUP_RETRY	    3  /* Retry count of construction when
2069ff05123SRyusuke Konishi 					  destroying segctord */
2079ff05123SRyusuke Konishi 
2089ff05123SRyusuke Konishi /*
2099ff05123SRyusuke Konishi  * Default values of timeout, in seconds.
2109ff05123SRyusuke Konishi  */
2119ff05123SRyusuke Konishi #define NILFS_SC_DEFAULT_TIMEOUT    5   /* Timeout value of dirty blocks.
2129ff05123SRyusuke Konishi 					   It triggers construction of a
2139ff05123SRyusuke Konishi 					   logical segment with a super root */
2149ff05123SRyusuke Konishi #define NILFS_SC_DEFAULT_SR_FREQ    30  /* Maximum frequency of super root
2159ff05123SRyusuke Konishi 					   creation */
2169ff05123SRyusuke Konishi 
2179ff05123SRyusuke Konishi /*
2189ff05123SRyusuke Konishi  * The default threshold amount of data, in block counts.
2199ff05123SRyusuke Konishi  */
2209ff05123SRyusuke Konishi #define NILFS_SC_DEFAULT_WATERMARK  3600
2219ff05123SRyusuke Konishi 
2229ff05123SRyusuke Konishi 
2239ff05123SRyusuke Konishi /* segment.c */
2249ff05123SRyusuke Konishi extern int nilfs_init_transaction_cache(void);
2259ff05123SRyusuke Konishi extern void nilfs_destroy_transaction_cache(void);
2269ff05123SRyusuke Konishi extern void nilfs_relax_pressure_in_lock(struct super_block *);
2279ff05123SRyusuke Konishi 
2289ff05123SRyusuke Konishi extern int nilfs_construct_segment(struct super_block *);
229f30bf3e4SRyusuke Konishi extern int nilfs_construct_dsync_segment(struct super_block *, struct inode *,
230f30bf3e4SRyusuke Konishi 					 loff_t, loff_t);
2319ff05123SRyusuke Konishi extern void nilfs_flush_segment(struct super_block *, ino_t);
2324f6b8288SRyusuke Konishi extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *,
2334f6b8288SRyusuke Konishi 				void **);
2349ff05123SRyusuke Konishi 
235cece5520SRyusuke Konishi extern int nilfs_attach_segment_constructor(struct nilfs_sb_info *);
2369ff05123SRyusuke Konishi extern void nilfs_detach_segment_constructor(struct nilfs_sb_info *);
2379ff05123SRyusuke Konishi 
2389ff05123SRyusuke Konishi /* recovery.c */
2399ff05123SRyusuke Konishi extern int nilfs_read_super_root_block(struct super_block *, sector_t,
2409ff05123SRyusuke Konishi 				       struct buffer_head **, int);
2419ff05123SRyusuke Konishi extern int nilfs_search_super_root(struct the_nilfs *, struct nilfs_sb_info *,
2429ff05123SRyusuke Konishi 				   struct nilfs_recovery_info *);
2439ff05123SRyusuke Konishi extern int nilfs_recover_logical_segments(struct the_nilfs *,
2449ff05123SRyusuke Konishi 					  struct nilfs_sb_info *,
2459ff05123SRyusuke Konishi 					  struct nilfs_recovery_info *);
246654137ddSRyusuke Konishi extern void nilfs_dispose_segment_list(struct list_head *);
2479ff05123SRyusuke Konishi 
2489ff05123SRyusuke Konishi #endif /* _NILFS_SEGMENT_H */
249