Blame view

fs/nilfs2/segment.h 8.42 KB
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  /*
   * segment.h - NILFS Segment constructor prototypes and definitions
   *
   * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   *
   * Written by Ryusuke Konishi <ryusuke@osrg.net>
   *
   */
  #ifndef _NILFS_SEGMENT_H
  #define _NILFS_SEGMENT_H
  
  #include <linux/types.h>
  #include <linux/fs.h>
  #include <linux/buffer_head.h>
7ef3ff2fe   Ryusuke Konishi   nilfs2: fix deadl...
29
  #include <linux/workqueue.h>
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
30
  #include <linux/nilfs2_fs.h>
e3154e974   Ryusuke Konishi   nilfs2: get rid o...
31
  #include "nilfs.h"
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
32

e912a5b66   Ryusuke Konishi   nilfs2: use root ...
33
  struct nilfs_root;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
34
  /**
7a65004bb   Ryusuke Konishi   nilfs2: fix vario...
35
   * struct nilfs_recovery_info - Recovery information
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
   * @ri_need_recovery: Recovery status
   * @ri_super_root: Block number of the last super root
   * @ri_ri_cno: Number of the last checkpoint
   * @ri_lsegs_start: Region for roll-forwarding (start block number)
   * @ri_lsegs_end: Region for roll-forwarding (end block number)
   * @ri_lseg_start_seq: Sequence value of the segment at ri_lsegs_start
   * @ri_used_segments: List of segments to be mark active
   * @ri_pseg_start: Block number of the last partial segment
   * @ri_seq: Sequence number on the last partial segment
   * @ri_segnum: Segment number on the last partial segment
   * @ri_nextnum: Next segment number on the last partial segment
   */
  struct nilfs_recovery_info {
  	int			ri_need_recovery;
  	sector_t		ri_super_root;
  	__u64			ri_cno;
  
  	sector_t		ri_lsegs_start;
  	sector_t		ri_lsegs_end;
  	u64			ri_lsegs_start_seq;
  	struct list_head	ri_used_segments;
  	sector_t		ri_pseg_start;
  	u64			ri_seq;
  	__u64			ri_segnum;
  	__u64			ri_nextnum;
  };
  
  /* ri_need_recovery */
  #define NILFS_RECOVERY_SR_UPDATED	 1  /* The super root was updated */
  #define NILFS_RECOVERY_ROLLFORWARD_DONE	 2  /* Rollforward was carried out */
  
  /**
   * struct nilfs_cstage - Context of collection stage
584977038   Hitoshi Mitake   nilfs2: add a tra...
69
70
   * @scnt: Stage count, must be accessed via wrappers:
   *        nilfs_sc_cstage_inc(), nilfs_sc_cstage_set(), nilfs_sc_cstage_get()
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
71
72
73
74
75
76
   * @flags: State flags
   * @dirty_file_ptr: Pointer on dirty_files list, or inode of a target file
   * @gc_inode_ptr: Pointer on the list of gc-inodes
   */
  struct nilfs_cstage {
  	int			scnt;
55480a06e   Ryusuke Konishi   nilfs2: remove sp...
77
  	unsigned		flags;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  	struct nilfs_inode_info *dirty_file_ptr;
  	struct nilfs_inode_info *gc_inode_ptr;
  };
  
  struct nilfs_segment_buffer;
  
  struct nilfs_segsum_pointer {
  	struct buffer_head     *bh;
  	unsigned		offset; /* offset in bytes */
  };
  
  /**
   * struct nilfs_sc_info - Segment constructor information
   * @sc_super: Back pointer to super_block struct
e912a5b66   Ryusuke Konishi   nilfs2: use root ...
92
   * @sc_root: root object of the current filesystem tree
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
93
94
95
   * @sc_nblk_inc: Block count of current generation
   * @sc_dirty_files: List of files to be written
   * @sc_gc_inodes: List of GC inodes having blocks to be written
7ef3ff2fe   Ryusuke Konishi   nilfs2: fix deadl...
96
97
   * @sc_iput_queue: list of inodes for which iput should be done
   * @sc_iput_work: work struct to defer iput call
071cb4b81   Ryusuke Konishi   nilfs2: eliminate...
98
99
   * @sc_freesegs: array of segment numbers to be freed
   * @sc_nfreesegs: number of segments on @sc_freesegs
f30bf3e40   Ryusuke Konishi   nilfs2: fix misse...
100
101
102
   * @sc_dsync_inode: inode whose data pages are written for a sync operation
   * @sc_dsync_start: start byte offset of data pages
   * @sc_dsync_end: end byte offset of data pages (inclusive)
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
103
   * @sc_segbufs: List of segment buffers
a694291a6   Ryusuke Konishi   nilfs2: separate ...
104
   * @sc_write_logs: List of segment buffers to hold logs under writing
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
105
106
   * @sc_segbuf_nblocks: Number of available blocks in segment buffers.
   * @sc_curseg: Current segment buffer
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
107
108
109
110
111
112
113
   * @sc_stage: Collection stage
   * @sc_finfo_ptr: pointer to the current finfo struct in the segment summary
   * @sc_binfo_ptr: pointer to the current binfo struct in the segment summary
   * @sc_blk_cnt:	Block count of a file
   * @sc_datablk_cnt: Data block count of a file
   * @sc_nblk_this_inc: Number of blocks included in the current logical segment
   * @sc_seg_ctime: Creation time
6c43f4100   Ryusuke Konishi   nilfs2: keep zero...
114
   * @sc_cno: checkpoint number of current log
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
115
   * @sc_flags: Internal flags
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
116
117
118
119
120
121
122
   * @sc_state_lock: spinlock for sc_state and so on
   * @sc_state: Segctord state flags
   * @sc_flush_request: inode bitmap of metadata files to be flushed
   * @sc_wait_request: Client request queue
   * @sc_wait_daemon: Daemon wait queue
   * @sc_wait_task: Start/end wait queue to control segctord task
   * @sc_seq_request: Request counter
dcd761869   Ryusuke Konishi   nilfs2: get rid o...
123
   * @sc_seq_accept: Accepted request count
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
124
125
126
127
128
129
130
131
132
133
134
   * @sc_seq_done: Completion counter
   * @sc_sync: Request of explicit sync operation
   * @sc_interval: Timeout value of background construction
   * @sc_mjcp_freq: Frequency of creating checkpoints
   * @sc_lseg_stime: Start time of the latest logical segment
   * @sc_watermark: Watermark for the number of dirty buffers
   * @sc_timer: Timer for segctord
   * @sc_task: current thread of segctord
   */
  struct nilfs_sc_info {
  	struct super_block     *sc_super;
e912a5b66   Ryusuke Konishi   nilfs2: use root ...
135
  	struct nilfs_root      *sc_root;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
136
137
138
139
140
  
  	unsigned long		sc_nblk_inc;
  
  	struct list_head	sc_dirty_files;
  	struct list_head	sc_gc_inodes;
7ef3ff2fe   Ryusuke Konishi   nilfs2: fix deadl...
141
142
  	struct list_head	sc_iput_queue;
  	struct work_struct	sc_iput_work;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
143

071cb4b81   Ryusuke Konishi   nilfs2: eliminate...
144
145
  	__u64		       *sc_freesegs;
  	size_t			sc_nfreesegs;
f30bf3e40   Ryusuke Konishi   nilfs2: fix misse...
146
147
148
  	struct nilfs_inode_info *sc_dsync_inode;
  	loff_t			sc_dsync_start;
  	loff_t			sc_dsync_end;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
149
150
  	/* Segment buffers */
  	struct list_head	sc_segbufs;
a694291a6   Ryusuke Konishi   nilfs2: separate ...
151
  	struct list_head	sc_write_logs;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
152
153
  	unsigned long		sc_segbuf_nblocks;
  	struct nilfs_segment_buffer *sc_curseg;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
154
155
156
157
158
159
160
161
162
  
  	struct nilfs_cstage	sc_stage;
  
  	struct nilfs_segsum_pointer sc_finfo_ptr;
  	struct nilfs_segsum_pointer sc_binfo_ptr;
  	unsigned long		sc_blk_cnt;
  	unsigned long		sc_datablk_cnt;
  	unsigned long		sc_nblk_this_inc;
  	time_t			sc_seg_ctime;
6c43f4100   Ryusuke Konishi   nilfs2: keep zero...
163
  	__u64			sc_cno;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
164
  	unsigned long		sc_flags;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
165
166
167
168
169
170
171
172
173
  	spinlock_t		sc_state_lock;
  	unsigned long		sc_state;
  	unsigned long		sc_flush_request;
  
  	wait_queue_head_t	sc_wait_request;
  	wait_queue_head_t	sc_wait_daemon;
  	wait_queue_head_t	sc_wait_task;
  
  	__u32			sc_seq_request;
dcd761869   Ryusuke Konishi   nilfs2: get rid o...
174
  	__u32			sc_seq_accepted;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
175
176
177
178
179
180
181
  	__u32			sc_seq_done;
  
  	int			sc_sync;
  	unsigned long		sc_interval;
  	unsigned long		sc_mjcp_freq;
  	unsigned long		sc_lseg_stime;	/* in 1/HZ seconds */
  	unsigned long		sc_watermark;
fdce895ea   Li Hong   nilfs2: change sc...
182
  	struct timer_list	sc_timer;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
183
184
185
186
187
188
189
190
191
192
  	struct task_struct     *sc_task;
  };
  
  /* sc_flags */
  enum {
  	NILFS_SC_DIRTY,		/* One or more dirty meta-data blocks exist */
  	NILFS_SC_UNCLOSED,	/* Logical segment is not closed */
  	NILFS_SC_SUPER_ROOT,	/* The latest segment has a super root */
  	NILFS_SC_PRIOR_FLUSH,	/* Requesting immediate flush without making a
  				   checkpoint */
c96fa464a   Ryusuke Konishi   nilfs2: mark mino...
193
194
195
  	NILFS_SC_HAVE_DELTA,	/* Next checkpoint will have update of files
  				   other than DAT, cpfile, sufile, or files
  				   moved by GC */
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
  };
  
  /* sc_state */
  #define NILFS_SEGCTOR_QUIT	    0x0001  /* segctord is being destroyed */
  #define NILFS_SEGCTOR_COMMIT	    0x0004  /* committed transaction exists */
  
  /*
   * Constant parameters
   */
  #define NILFS_SC_CLEANUP_RETRY	    3  /* Retry count of construction when
  					  destroying segctord */
  
  /*
   * Default values of timeout, in seconds.
   */
  #define NILFS_SC_DEFAULT_TIMEOUT    5   /* Timeout value of dirty blocks.
  					   It triggers construction of a
  					   logical segment with a super root */
  #define NILFS_SC_DEFAULT_SR_FREQ    30  /* Maximum frequency of super root
  					   creation */
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
216
217
218
219
220
  
  /*
   * The default threshold amount of data, in block counts.
   */
  #define NILFS_SC_DEFAULT_WATERMARK  3600
41c88bd74   Li Hong   nilfs2: cleanup m...
221
222
  /* super.c */
  extern struct kmem_cache *nilfs_transaction_cachep;
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
223
224
  
  /* segment.c */
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
225
226
227
  extern void nilfs_relax_pressure_in_lock(struct super_block *);
  
  extern int nilfs_construct_segment(struct super_block *);
f30bf3e40   Ryusuke Konishi   nilfs2: fix misse...
228
229
  extern int nilfs_construct_dsync_segment(struct super_block *, struct inode *,
  					 loff_t, loff_t);
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
230
  extern void nilfs_flush_segment(struct super_block *, ino_t);
4f6b82883   Ryusuke Konishi   nilfs2: fix lock ...
231
232
  extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *,
  				void **);
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
233

f7545144c   Ryusuke Konishi   nilfs2: use sb in...
234
235
  int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root);
  void nilfs_detach_log_writer(struct super_block *sb);
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
236
237
  
  /* recovery.c */
8b94025c0   Ryusuke Konishi   nilfs2: refactor ...
238
  extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t,
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
239
  				       struct buffer_head **, int);
8b94025c0   Ryusuke Konishi   nilfs2: refactor ...
240
  extern int nilfs_search_super_root(struct the_nilfs *,
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
241
  				   struct nilfs_recovery_info *);
f7545144c   Ryusuke Konishi   nilfs2: use sb in...
242
243
  int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, struct super_block *sb,
  			      struct nilfs_recovery_info *ri);
654137dd4   Ryusuke Konishi   nilfs2: remove he...
244
  extern void nilfs_dispose_segment_list(struct list_head *);
9ff05123e   Ryusuke Konishi   nilfs2: segment c...
245
246
  
  #endif /* _NILFS_SEGMENT_H */