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> 269ff05123SRyusuke Konishi #include <linux/nilfs2_fs.h> 27e3154e97SRyusuke Konishi #include "nilfs.h" 289ff05123SRyusuke Konishi 29e912a5b6SRyusuke Konishi struct nilfs_root; 30e912a5b6SRyusuke Konishi 319ff05123SRyusuke Konishi /** 327a65004bSRyusuke Konishi * struct nilfs_recovery_info - Recovery information 339ff05123SRyusuke Konishi * @ri_need_recovery: Recovery status 349ff05123SRyusuke Konishi * @ri_super_root: Block number of the last super root 359ff05123SRyusuke Konishi * @ri_ri_cno: Number of the last checkpoint 369ff05123SRyusuke Konishi * @ri_lsegs_start: Region for roll-forwarding (start block number) 379ff05123SRyusuke Konishi * @ri_lsegs_end: Region for roll-forwarding (end block number) 389ff05123SRyusuke Konishi * @ri_lseg_start_seq: Sequence value of the segment at ri_lsegs_start 399ff05123SRyusuke Konishi * @ri_used_segments: List of segments to be mark active 409ff05123SRyusuke Konishi * @ri_pseg_start: Block number of the last partial segment 419ff05123SRyusuke Konishi * @ri_seq: Sequence number on the last partial segment 429ff05123SRyusuke Konishi * @ri_segnum: Segment number on the last partial segment 439ff05123SRyusuke Konishi * @ri_nextnum: Next segment number on the last partial segment 449ff05123SRyusuke Konishi */ 459ff05123SRyusuke Konishi struct nilfs_recovery_info { 469ff05123SRyusuke Konishi int ri_need_recovery; 479ff05123SRyusuke Konishi sector_t ri_super_root; 489ff05123SRyusuke Konishi __u64 ri_cno; 499ff05123SRyusuke Konishi 509ff05123SRyusuke Konishi sector_t ri_lsegs_start; 519ff05123SRyusuke Konishi sector_t ri_lsegs_end; 529ff05123SRyusuke Konishi u64 ri_lsegs_start_seq; 539ff05123SRyusuke Konishi struct list_head ri_used_segments; 549ff05123SRyusuke Konishi sector_t ri_pseg_start; 559ff05123SRyusuke Konishi u64 ri_seq; 569ff05123SRyusuke Konishi __u64 ri_segnum; 579ff05123SRyusuke Konishi __u64 ri_nextnum; 589ff05123SRyusuke Konishi }; 599ff05123SRyusuke Konishi 609ff05123SRyusuke Konishi /* ri_need_recovery */ 619ff05123SRyusuke Konishi #define NILFS_RECOVERY_SR_UPDATED 1 /* The super root was updated */ 629ff05123SRyusuke Konishi #define NILFS_RECOVERY_ROLLFORWARD_DONE 2 /* Rollforward was carried out */ 639ff05123SRyusuke Konishi 649ff05123SRyusuke Konishi /** 659ff05123SRyusuke Konishi * struct nilfs_cstage - Context of collection stage 6658497703SHitoshi Mitake * @scnt: Stage count, must be accessed via wrappers: 6758497703SHitoshi Mitake * nilfs_sc_cstage_inc(), nilfs_sc_cstage_set(), nilfs_sc_cstage_get() 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; 740c6c44cbSRyusuke Konishi unsigned int 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; 830c6c44cbSRyusuke Konishi unsigned int 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 89e912a5b6SRyusuke Konishi * @sc_root: root object of the current filesystem tree 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 937ef3ff2fSRyusuke Konishi * @sc_iput_queue: list of inodes for which iput should be done 947ef3ff2fSRyusuke Konishi * @sc_iput_work: work struct to defer iput call 95071cb4b8SRyusuke Konishi * @sc_freesegs: array of segment numbers to be freed 96071cb4b8SRyusuke Konishi * @sc_nfreesegs: number of segments on @sc_freesegs 97f30bf3e4SRyusuke Konishi * @sc_dsync_inode: inode whose data pages are written for a sync operation 98f30bf3e4SRyusuke Konishi * @sc_dsync_start: start byte offset of data pages 99f30bf3e4SRyusuke Konishi * @sc_dsync_end: end byte offset of data pages (inclusive) 1009ff05123SRyusuke Konishi * @sc_segbufs: List of segment buffers 101a694291aSRyusuke Konishi * @sc_write_logs: List of segment buffers to hold logs under writing 1029ff05123SRyusuke Konishi * @sc_segbuf_nblocks: Number of available blocks in segment buffers. 1039ff05123SRyusuke Konishi * @sc_curseg: Current segment 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 1116c43f410SRyusuke Konishi * @sc_cno: checkpoint number of current log 1129ff05123SRyusuke Konishi * @sc_flags: Internal flags 1139ff05123SRyusuke Konishi * @sc_state_lock: spinlock for sc_state and so on 1149ff05123SRyusuke Konishi * @sc_state: Segctord state flags 1159ff05123SRyusuke Konishi * @sc_flush_request: inode bitmap of metadata files to be flushed 1169ff05123SRyusuke Konishi * @sc_wait_request: Client request queue 1179ff05123SRyusuke Konishi * @sc_wait_daemon: Daemon wait queue 1189ff05123SRyusuke Konishi * @sc_wait_task: Start/end wait queue to control segctord task 1199ff05123SRyusuke Konishi * @sc_seq_request: Request counter 120dcd76186SRyusuke Konishi * @sc_seq_accept: Accepted request count 1219ff05123SRyusuke Konishi * @sc_seq_done: Completion counter 1229ff05123SRyusuke Konishi * @sc_sync: Request of explicit sync operation 1239ff05123SRyusuke Konishi * @sc_interval: Timeout value of background construction 1249ff05123SRyusuke Konishi * @sc_mjcp_freq: Frequency of creating checkpoints 1259ff05123SRyusuke Konishi * @sc_lseg_stime: Start time of the latest logical segment 1269ff05123SRyusuke Konishi * @sc_watermark: Watermark for the number of dirty buffers 1279ff05123SRyusuke Konishi * @sc_timer: Timer for segctord 1289ff05123SRyusuke Konishi * @sc_task: current thread of segctord 1299ff05123SRyusuke Konishi */ 1309ff05123SRyusuke Konishi struct nilfs_sc_info { 1319ff05123SRyusuke Konishi struct super_block *sc_super; 132e912a5b6SRyusuke Konishi struct nilfs_root *sc_root; 1339ff05123SRyusuke Konishi 1349ff05123SRyusuke Konishi unsigned long sc_nblk_inc; 1359ff05123SRyusuke Konishi 1369ff05123SRyusuke Konishi struct list_head sc_dirty_files; 1379ff05123SRyusuke Konishi struct list_head sc_gc_inodes; 1387ef3ff2fSRyusuke Konishi struct list_head sc_iput_queue; 1397ef3ff2fSRyusuke Konishi struct work_struct sc_iput_work; 1409ff05123SRyusuke Konishi 141071cb4b8SRyusuke Konishi __u64 *sc_freesegs; 142071cb4b8SRyusuke Konishi size_t sc_nfreesegs; 143071cb4b8SRyusuke Konishi 144f30bf3e4SRyusuke Konishi struct nilfs_inode_info *sc_dsync_inode; 145f30bf3e4SRyusuke Konishi loff_t sc_dsync_start; 146f30bf3e4SRyusuke Konishi loff_t sc_dsync_end; 147f30bf3e4SRyusuke Konishi 1489ff05123SRyusuke Konishi /* Segment buffers */ 1499ff05123SRyusuke Konishi struct list_head sc_segbufs; 150a694291aSRyusuke Konishi struct list_head sc_write_logs; 1519ff05123SRyusuke Konishi unsigned long sc_segbuf_nblocks; 1529ff05123SRyusuke Konishi struct nilfs_segment_buffer *sc_curseg; 1539ff05123SRyusuke Konishi 1549ff05123SRyusuke Konishi struct nilfs_cstage sc_stage; 1559ff05123SRyusuke Konishi 1569ff05123SRyusuke Konishi struct nilfs_segsum_pointer sc_finfo_ptr; 1579ff05123SRyusuke Konishi struct nilfs_segsum_pointer sc_binfo_ptr; 1589ff05123SRyusuke Konishi unsigned long sc_blk_cnt; 1599ff05123SRyusuke Konishi unsigned long sc_datablk_cnt; 1609ff05123SRyusuke Konishi unsigned long sc_nblk_this_inc; 1619ff05123SRyusuke Konishi time_t sc_seg_ctime; 1626c43f410SRyusuke Konishi __u64 sc_cno; 1639ff05123SRyusuke Konishi unsigned long sc_flags; 1649ff05123SRyusuke Konishi 1659ff05123SRyusuke Konishi spinlock_t sc_state_lock; 1669ff05123SRyusuke Konishi unsigned long sc_state; 1679ff05123SRyusuke Konishi unsigned long sc_flush_request; 1689ff05123SRyusuke Konishi 1699ff05123SRyusuke Konishi wait_queue_head_t sc_wait_request; 1709ff05123SRyusuke Konishi wait_queue_head_t sc_wait_daemon; 1719ff05123SRyusuke Konishi wait_queue_head_t sc_wait_task; 1729ff05123SRyusuke Konishi 1739ff05123SRyusuke Konishi __u32 sc_seq_request; 174dcd76186SRyusuke Konishi __u32 sc_seq_accepted; 1759ff05123SRyusuke Konishi __u32 sc_seq_done; 1769ff05123SRyusuke Konishi 1779ff05123SRyusuke Konishi int sc_sync; 1789ff05123SRyusuke Konishi unsigned long sc_interval; 1799ff05123SRyusuke Konishi unsigned long sc_mjcp_freq; 1809ff05123SRyusuke Konishi unsigned long sc_lseg_stime; /* in 1/HZ seconds */ 1819ff05123SRyusuke Konishi unsigned long sc_watermark; 1829ff05123SRyusuke Konishi 183fdce895eSLi Hong struct timer_list sc_timer; 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 */ 192*076a378bSRyusuke Konishi NILFS_SC_PRIOR_FLUSH, /* 193*076a378bSRyusuke Konishi * Requesting immediate flush without making a 194*076a378bSRyusuke Konishi * checkpoint 195*076a378bSRyusuke Konishi */ 196*076a378bSRyusuke Konishi NILFS_SC_HAVE_DELTA, /* 197*076a378bSRyusuke Konishi * Next checkpoint will have update of files 198*076a378bSRyusuke Konishi * other than DAT, cpfile, sufile, or files 199*076a378bSRyusuke Konishi * moved by GC. 200*076a378bSRyusuke 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 */ 210*076a378bSRyusuke Konishi #define NILFS_SC_CLEANUP_RETRY 3 /* 211*076a378bSRyusuke Konishi * Retry count of construction when 212*076a378bSRyusuke Konishi * destroying segctord 213*076a378bSRyusuke Konishi */ 2149ff05123SRyusuke Konishi 2159ff05123SRyusuke Konishi /* 2169ff05123SRyusuke Konishi * Default values of timeout, in seconds. 2179ff05123SRyusuke Konishi */ 218*076a378bSRyusuke Konishi #define NILFS_SC_DEFAULT_TIMEOUT 5 /* 219*076a378bSRyusuke Konishi * Timeout value of dirty blocks. 220*076a378bSRyusuke Konishi * It triggers construction of a 221*076a378bSRyusuke Konishi * logical segment with a super root. 222*076a378bSRyusuke Konishi */ 223*076a378bSRyusuke Konishi #define NILFS_SC_DEFAULT_SR_FREQ 30 /* 224*076a378bSRyusuke Konishi * Maximum frequency of super root 225*076a378bSRyusuke Konishi * creation 226*076a378bSRyusuke 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