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 32*e912a5b6SRyusuke Konishi struct nilfs_root; 33*e912a5b6SRyusuke Konishi 349ff05123SRyusuke Konishi /** 357a65004bSRyusuke Konishi * struct nilfs_recovery_info - Recovery information 369ff05123SRyusuke Konishi * @ri_need_recovery: Recovery status 379ff05123SRyusuke Konishi * @ri_super_root: Block number of the last super root 389ff05123SRyusuke Konishi * @ri_ri_cno: Number of the last checkpoint 399ff05123SRyusuke Konishi * @ri_lsegs_start: Region for roll-forwarding (start block number) 409ff05123SRyusuke Konishi * @ri_lsegs_end: Region for roll-forwarding (end block number) 419ff05123SRyusuke Konishi * @ri_lseg_start_seq: Sequence value of the segment at ri_lsegs_start 429ff05123SRyusuke Konishi * @ri_used_segments: List of segments to be mark active 439ff05123SRyusuke Konishi * @ri_pseg_start: Block number of the last partial segment 449ff05123SRyusuke Konishi * @ri_seq: Sequence number on the last partial segment 459ff05123SRyusuke Konishi * @ri_segnum: Segment number on the last partial segment 469ff05123SRyusuke Konishi * @ri_nextnum: Next segment number on the last partial segment 479ff05123SRyusuke Konishi */ 489ff05123SRyusuke Konishi struct nilfs_recovery_info { 499ff05123SRyusuke Konishi int ri_need_recovery; 509ff05123SRyusuke Konishi sector_t ri_super_root; 519ff05123SRyusuke Konishi __u64 ri_cno; 529ff05123SRyusuke Konishi 539ff05123SRyusuke Konishi sector_t ri_lsegs_start; 549ff05123SRyusuke Konishi sector_t ri_lsegs_end; 559ff05123SRyusuke Konishi u64 ri_lsegs_start_seq; 569ff05123SRyusuke Konishi struct list_head ri_used_segments; 579ff05123SRyusuke Konishi sector_t ri_pseg_start; 589ff05123SRyusuke Konishi u64 ri_seq; 599ff05123SRyusuke Konishi __u64 ri_segnum; 609ff05123SRyusuke Konishi __u64 ri_nextnum; 619ff05123SRyusuke Konishi }; 629ff05123SRyusuke Konishi 639ff05123SRyusuke Konishi /* ri_need_recovery */ 649ff05123SRyusuke Konishi #define NILFS_RECOVERY_SR_UPDATED 1 /* The super root was updated */ 659ff05123SRyusuke Konishi #define NILFS_RECOVERY_ROLLFORWARD_DONE 2 /* Rollforward was carried out */ 669ff05123SRyusuke Konishi 679ff05123SRyusuke Konishi /** 689ff05123SRyusuke Konishi * struct nilfs_cstage - Context of collection stage 699ff05123SRyusuke Konishi * @scnt: Stage count 709ff05123SRyusuke Konishi * @flags: State flags 719ff05123SRyusuke Konishi * @dirty_file_ptr: Pointer on dirty_files list, or inode of a target file 729ff05123SRyusuke Konishi * @gc_inode_ptr: Pointer on the list of gc-inodes 739ff05123SRyusuke Konishi */ 749ff05123SRyusuke Konishi struct nilfs_cstage { 759ff05123SRyusuke Konishi int scnt; 769ff05123SRyusuke Konishi unsigned flags; 779ff05123SRyusuke Konishi struct nilfs_inode_info *dirty_file_ptr; 789ff05123SRyusuke Konishi struct nilfs_inode_info *gc_inode_ptr; 799ff05123SRyusuke Konishi }; 809ff05123SRyusuke Konishi 819ff05123SRyusuke Konishi struct nilfs_segment_buffer; 829ff05123SRyusuke Konishi 839ff05123SRyusuke Konishi struct nilfs_segsum_pointer { 849ff05123SRyusuke Konishi struct buffer_head *bh; 859ff05123SRyusuke Konishi unsigned offset; /* offset in bytes */ 869ff05123SRyusuke Konishi }; 879ff05123SRyusuke Konishi 889ff05123SRyusuke Konishi /** 899ff05123SRyusuke Konishi * struct nilfs_sc_info - Segment constructor information 909ff05123SRyusuke Konishi * @sc_super: Back pointer to super_block struct 919ff05123SRyusuke Konishi * @sc_sbi: Back pointer to nilfs_sb_info struct 92*e912a5b6SRyusuke Konishi * @sc_root: root object of the current filesystem tree 939ff05123SRyusuke Konishi * @sc_nblk_inc: Block count of current generation 949ff05123SRyusuke Konishi * @sc_dirty_files: List of files to be written 959ff05123SRyusuke Konishi * @sc_gc_inodes: List of GC inodes having blocks to be written 969ff05123SRyusuke Konishi * @sc_copied_buffers: List of copied buffers (buffer heads) to freeze data 97071cb4b8SRyusuke Konishi * @sc_freesegs: array of segment numbers to be freed 98071cb4b8SRyusuke Konishi * @sc_nfreesegs: number of segments on @sc_freesegs 99f30bf3e4SRyusuke Konishi * @sc_dsync_inode: inode whose data pages are written for a sync operation 100f30bf3e4SRyusuke Konishi * @sc_dsync_start: start byte offset of data pages 101f30bf3e4SRyusuke Konishi * @sc_dsync_end: end byte offset of data pages (inclusive) 1029ff05123SRyusuke Konishi * @sc_segbufs: List of segment buffers 103a694291aSRyusuke Konishi * @sc_write_logs: List of segment buffers to hold logs under writing 1049ff05123SRyusuke Konishi * @sc_segbuf_nblocks: Number of available blocks in segment buffers. 1059ff05123SRyusuke Konishi * @sc_curseg: Current segment buffer 1069ff05123SRyusuke Konishi * @sc_stage: Collection stage 1079ff05123SRyusuke Konishi * @sc_finfo_ptr: pointer to the current finfo struct in the segment summary 1089ff05123SRyusuke Konishi * @sc_binfo_ptr: pointer to the current binfo struct in the segment summary 1099ff05123SRyusuke Konishi * @sc_blk_cnt: Block count of a file 1109ff05123SRyusuke Konishi * @sc_datablk_cnt: Data block count of a file 1119ff05123SRyusuke Konishi * @sc_nblk_this_inc: Number of blocks included in the current logical segment 1129ff05123SRyusuke Konishi * @sc_seg_ctime: Creation time 1136c43f410SRyusuke Konishi * @sc_cno: checkpoint number of current log 1149ff05123SRyusuke Konishi * @sc_flags: Internal flags 1159ff05123SRyusuke Konishi * @sc_state_lock: spinlock for sc_state and so on 1169ff05123SRyusuke Konishi * @sc_state: Segctord state flags 1179ff05123SRyusuke Konishi * @sc_flush_request: inode bitmap of metadata files to be flushed 1189ff05123SRyusuke Konishi * @sc_wait_request: Client request queue 1199ff05123SRyusuke Konishi * @sc_wait_daemon: Daemon wait queue 1209ff05123SRyusuke Konishi * @sc_wait_task: Start/end wait queue to control segctord task 1219ff05123SRyusuke Konishi * @sc_seq_request: Request counter 122dcd76186SRyusuke Konishi * @sc_seq_accept: Accepted request count 1239ff05123SRyusuke Konishi * @sc_seq_done: Completion counter 1249ff05123SRyusuke Konishi * @sc_sync: Request of explicit sync operation 1259ff05123SRyusuke Konishi * @sc_interval: Timeout value of background construction 1269ff05123SRyusuke Konishi * @sc_mjcp_freq: Frequency of creating checkpoints 1279ff05123SRyusuke Konishi * @sc_lseg_stime: Start time of the latest logical segment 1289ff05123SRyusuke Konishi * @sc_watermark: Watermark for the number of dirty buffers 1299ff05123SRyusuke Konishi * @sc_timer: Timer for segctord 1309ff05123SRyusuke Konishi * @sc_task: current thread of segctord 1319ff05123SRyusuke Konishi */ 1329ff05123SRyusuke Konishi struct nilfs_sc_info { 1339ff05123SRyusuke Konishi struct super_block *sc_super; 1349ff05123SRyusuke Konishi struct nilfs_sb_info *sc_sbi; 135*e912a5b6SRyusuke Konishi struct nilfs_root *sc_root; 1369ff05123SRyusuke Konishi 1379ff05123SRyusuke Konishi unsigned long sc_nblk_inc; 1389ff05123SRyusuke Konishi 1399ff05123SRyusuke Konishi struct list_head sc_dirty_files; 1409ff05123SRyusuke Konishi struct list_head sc_gc_inodes; 1419ff05123SRyusuke Konishi struct list_head sc_copied_buffers; 1429ff05123SRyusuke Konishi 143071cb4b8SRyusuke Konishi __u64 *sc_freesegs; 144071cb4b8SRyusuke Konishi size_t sc_nfreesegs; 145071cb4b8SRyusuke Konishi 146f30bf3e4SRyusuke Konishi struct nilfs_inode_info *sc_dsync_inode; 147f30bf3e4SRyusuke Konishi loff_t sc_dsync_start; 148f30bf3e4SRyusuke Konishi loff_t sc_dsync_end; 149f30bf3e4SRyusuke Konishi 1509ff05123SRyusuke Konishi /* Segment buffers */ 1519ff05123SRyusuke Konishi struct list_head sc_segbufs; 152a694291aSRyusuke Konishi struct list_head sc_write_logs; 1539ff05123SRyusuke Konishi unsigned long sc_segbuf_nblocks; 1549ff05123SRyusuke Konishi struct nilfs_segment_buffer *sc_curseg; 1559ff05123SRyusuke Konishi 1569ff05123SRyusuke Konishi struct nilfs_cstage sc_stage; 1579ff05123SRyusuke Konishi 1589ff05123SRyusuke Konishi struct nilfs_segsum_pointer sc_finfo_ptr; 1599ff05123SRyusuke Konishi struct nilfs_segsum_pointer sc_binfo_ptr; 1609ff05123SRyusuke Konishi unsigned long sc_blk_cnt; 1619ff05123SRyusuke Konishi unsigned long sc_datablk_cnt; 1629ff05123SRyusuke Konishi unsigned long sc_nblk_this_inc; 1639ff05123SRyusuke Konishi time_t sc_seg_ctime; 1646c43f410SRyusuke Konishi __u64 sc_cno; 1659ff05123SRyusuke Konishi unsigned long sc_flags; 1669ff05123SRyusuke Konishi 1679ff05123SRyusuke Konishi spinlock_t sc_state_lock; 1689ff05123SRyusuke Konishi unsigned long sc_state; 1699ff05123SRyusuke Konishi unsigned long sc_flush_request; 1709ff05123SRyusuke Konishi 1719ff05123SRyusuke Konishi wait_queue_head_t sc_wait_request; 1729ff05123SRyusuke Konishi wait_queue_head_t sc_wait_daemon; 1739ff05123SRyusuke Konishi wait_queue_head_t sc_wait_task; 1749ff05123SRyusuke Konishi 1759ff05123SRyusuke Konishi __u32 sc_seq_request; 176dcd76186SRyusuke Konishi __u32 sc_seq_accepted; 1779ff05123SRyusuke Konishi __u32 sc_seq_done; 1789ff05123SRyusuke Konishi 1799ff05123SRyusuke Konishi int sc_sync; 1809ff05123SRyusuke Konishi unsigned long sc_interval; 1819ff05123SRyusuke Konishi unsigned long sc_mjcp_freq; 1829ff05123SRyusuke Konishi unsigned long sc_lseg_stime; /* in 1/HZ seconds */ 1839ff05123SRyusuke Konishi unsigned long sc_watermark; 1849ff05123SRyusuke Konishi 185fdce895eSLi Hong struct timer_list sc_timer; 1869ff05123SRyusuke Konishi struct task_struct *sc_task; 1879ff05123SRyusuke Konishi }; 1889ff05123SRyusuke Konishi 1899ff05123SRyusuke Konishi /* sc_flags */ 1909ff05123SRyusuke Konishi enum { 1919ff05123SRyusuke Konishi NILFS_SC_DIRTY, /* One or more dirty meta-data blocks exist */ 1929ff05123SRyusuke Konishi NILFS_SC_UNCLOSED, /* Logical segment is not closed */ 1939ff05123SRyusuke Konishi NILFS_SC_SUPER_ROOT, /* The latest segment has a super root */ 1949ff05123SRyusuke Konishi NILFS_SC_PRIOR_FLUSH, /* Requesting immediate flush without making a 1959ff05123SRyusuke Konishi checkpoint */ 196c96fa464SRyusuke Konishi NILFS_SC_HAVE_DELTA, /* Next checkpoint will have update of files 197c96fa464SRyusuke Konishi other than DAT, cpfile, sufile, or files 198c96fa464SRyusuke Konishi moved by GC */ 1999ff05123SRyusuke Konishi }; 2009ff05123SRyusuke Konishi 2019ff05123SRyusuke Konishi /* sc_state */ 2029ff05123SRyusuke Konishi #define NILFS_SEGCTOR_QUIT 0x0001 /* segctord is being destroyed */ 2039ff05123SRyusuke Konishi #define NILFS_SEGCTOR_COMMIT 0x0004 /* committed transaction exists */ 2049ff05123SRyusuke Konishi 2059ff05123SRyusuke Konishi /* 2069ff05123SRyusuke Konishi * Constant parameters 2079ff05123SRyusuke Konishi */ 2089ff05123SRyusuke Konishi #define NILFS_SC_CLEANUP_RETRY 3 /* Retry count of construction when 2099ff05123SRyusuke Konishi destroying segctord */ 2109ff05123SRyusuke Konishi 2119ff05123SRyusuke Konishi /* 2129ff05123SRyusuke Konishi * Default values of timeout, in seconds. 2139ff05123SRyusuke Konishi */ 2149ff05123SRyusuke Konishi #define NILFS_SC_DEFAULT_TIMEOUT 5 /* Timeout value of dirty blocks. 2159ff05123SRyusuke Konishi It triggers construction of a 2169ff05123SRyusuke Konishi logical segment with a super root */ 2179ff05123SRyusuke Konishi #define NILFS_SC_DEFAULT_SR_FREQ 30 /* Maximum frequency of super root 2189ff05123SRyusuke Konishi creation */ 2199ff05123SRyusuke Konishi 2209ff05123SRyusuke Konishi /* 2219ff05123SRyusuke Konishi * The default threshold amount of data, in block counts. 2229ff05123SRyusuke Konishi */ 2239ff05123SRyusuke Konishi #define NILFS_SC_DEFAULT_WATERMARK 3600 2249ff05123SRyusuke Konishi 22541c88bd7SLi Hong /* super.c */ 22641c88bd7SLi Hong extern struct kmem_cache *nilfs_transaction_cachep; 2279ff05123SRyusuke Konishi 2289ff05123SRyusuke Konishi /* segment.c */ 2299ff05123SRyusuke Konishi extern void nilfs_relax_pressure_in_lock(struct super_block *); 2309ff05123SRyusuke Konishi 2319ff05123SRyusuke Konishi extern int nilfs_construct_segment(struct super_block *); 232f30bf3e4SRyusuke Konishi extern int nilfs_construct_dsync_segment(struct super_block *, struct inode *, 233f30bf3e4SRyusuke Konishi loff_t, loff_t); 2349ff05123SRyusuke Konishi extern void nilfs_flush_segment(struct super_block *, ino_t); 2354f6b8288SRyusuke Konishi extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *, 2364f6b8288SRyusuke Konishi void **); 2379ff05123SRyusuke Konishi 238*e912a5b6SRyusuke Konishi int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi, 239*e912a5b6SRyusuke Konishi struct nilfs_root *root); 2409ff05123SRyusuke Konishi extern void nilfs_detach_segment_constructor(struct nilfs_sb_info *); 2419ff05123SRyusuke Konishi 2429ff05123SRyusuke Konishi /* recovery.c */ 2438b94025cSRyusuke Konishi extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t, 2449ff05123SRyusuke Konishi struct buffer_head **, int); 2458b94025cSRyusuke Konishi extern int nilfs_search_super_root(struct the_nilfs *, 2469ff05123SRyusuke Konishi struct nilfs_recovery_info *); 247aee5ce2fSRyusuke Konishi extern int nilfs_salvage_orphan_logs(struct the_nilfs *, 2489ff05123SRyusuke Konishi struct nilfs_sb_info *, 2499ff05123SRyusuke Konishi struct nilfs_recovery_info *); 250654137ddSRyusuke Konishi extern void nilfs_dispose_segment_list(struct list_head *); 2519ff05123SRyusuke Konishi 2529ff05123SRyusuke Konishi #endif /* _NILFS_SEGMENT_H */ 253