diff options
Diffstat (limited to 'fs/nilfs2/the_nilfs.h')
-rw-r--r-- | fs/nilfs2/the_nilfs.h | 101 |
1 files changed, 42 insertions, 59 deletions
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h index f785a7b0ab99..69226e14b745 100644 --- a/fs/nilfs2/the_nilfs.h +++ b/fs/nilfs2/the_nilfs.h | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <linux/types.h> | 27 | #include <linux/types.h> |
28 | #include <linux/buffer_head.h> | 28 | #include <linux/buffer_head.h> |
29 | #include <linux/rbtree.h> | ||
29 | #include <linux/fs.h> | 30 | #include <linux/fs.h> |
30 | #include <linux/blkdev.h> | 31 | #include <linux/blkdev.h> |
31 | #include <linux/backing-dev.h> | 32 | #include <linux/backing-dev.h> |
@@ -45,22 +46,13 @@ enum { | |||
45 | /** | 46 | /** |
46 | * struct the_nilfs - struct to supervise multiple nilfs mount points | 47 | * struct the_nilfs - struct to supervise multiple nilfs mount points |
47 | * @ns_flags: flags | 48 | * @ns_flags: flags |
48 | * @ns_count: reference count | ||
49 | * @ns_list: list head for nilfs_list | ||
50 | * @ns_bdev: block device | 49 | * @ns_bdev: block device |
51 | * @ns_bdi: backing dev info | ||
52 | * @ns_writer: back pointer to writable nilfs_sb_info | ||
53 | * @ns_sem: semaphore for shared states | 50 | * @ns_sem: semaphore for shared states |
54 | * @ns_super_sem: semaphore for global operations across super block instances | ||
55 | * @ns_mount_mutex: mutex protecting mount process of nilfs | ||
56 | * @ns_writer_sem: semaphore protecting ns_writer attach/detach | ||
57 | * @ns_current: back pointer to current mount | ||
58 | * @ns_sbh: buffer heads of on-disk super blocks | 51 | * @ns_sbh: buffer heads of on-disk super blocks |
59 | * @ns_sbp: pointers to super block data | 52 | * @ns_sbp: pointers to super block data |
60 | * @ns_sbwtime: previous write time of super block | 53 | * @ns_sbwtime: previous write time of super block |
61 | * @ns_sbwcount: write count of super block | 54 | * @ns_sbwcount: write count of super block |
62 | * @ns_sbsize: size of valid data in super block | 55 | * @ns_sbsize: size of valid data in super block |
63 | * @ns_supers: list of nilfs super block structs | ||
64 | * @ns_seg_seq: segment sequence counter | 56 | * @ns_seg_seq: segment sequence counter |
65 | * @ns_segnum: index number of the latest full segment. | 57 | * @ns_segnum: index number of the latest full segment. |
66 | * @ns_nextnum: index number of the full segment index to be used next | 58 | * @ns_nextnum: index number of the full segment index to be used next |
@@ -79,9 +71,9 @@ enum { | |||
79 | * @ns_dat: DAT file inode | 71 | * @ns_dat: DAT file inode |
80 | * @ns_cpfile: checkpoint file inode | 72 | * @ns_cpfile: checkpoint file inode |
81 | * @ns_sufile: segusage file inode | 73 | * @ns_sufile: segusage file inode |
82 | * @ns_gc_dat: shadow inode of the DAT file inode for GC | 74 | * @ns_cptree: rb-tree of all mounted checkpoints (nilfs_root) |
75 | * @ns_cptree_lock: lock protecting @ns_cptree | ||
83 | * @ns_gc_inodes: dummy inodes to keep live blocks | 76 | * @ns_gc_inodes: dummy inodes to keep live blocks |
84 | * @ns_gc_inodes_h: hash list to keep dummy inode holding live blocks | ||
85 | * @ns_blocksize_bits: bit length of block size | 77 | * @ns_blocksize_bits: bit length of block size |
86 | * @ns_blocksize: block size | 78 | * @ns_blocksize: block size |
87 | * @ns_nsegments: number of segments in filesystem | 79 | * @ns_nsegments: number of segments in filesystem |
@@ -95,22 +87,9 @@ enum { | |||
95 | */ | 87 | */ |
96 | struct the_nilfs { | 88 | struct the_nilfs { |
97 | unsigned long ns_flags; | 89 | unsigned long ns_flags; |
98 | atomic_t ns_count; | ||
99 | struct list_head ns_list; | ||
100 | 90 | ||
101 | struct block_device *ns_bdev; | 91 | struct block_device *ns_bdev; |
102 | struct backing_dev_info *ns_bdi; | ||
103 | struct nilfs_sb_info *ns_writer; | ||
104 | struct rw_semaphore ns_sem; | 92 | struct rw_semaphore ns_sem; |
105 | struct rw_semaphore ns_super_sem; | ||
106 | struct mutex ns_mount_mutex; | ||
107 | struct rw_semaphore ns_writer_sem; | ||
108 | |||
109 | /* | ||
110 | * components protected by ns_super_sem | ||
111 | */ | ||
112 | struct nilfs_sb_info *ns_current; | ||
113 | struct list_head ns_supers; | ||
114 | 93 | ||
115 | /* | 94 | /* |
116 | * used for | 95 | * used for |
@@ -163,11 +142,13 @@ struct the_nilfs { | |||
163 | struct inode *ns_dat; | 142 | struct inode *ns_dat; |
164 | struct inode *ns_cpfile; | 143 | struct inode *ns_cpfile; |
165 | struct inode *ns_sufile; | 144 | struct inode *ns_sufile; |
166 | struct inode *ns_gc_dat; | ||
167 | 145 | ||
168 | /* GC inode list and hash table head */ | 146 | /* Checkpoint tree */ |
147 | struct rb_root ns_cptree; | ||
148 | spinlock_t ns_cptree_lock; | ||
149 | |||
150 | /* GC inode list */ | ||
169 | struct list_head ns_gc_inodes; | 151 | struct list_head ns_gc_inodes; |
170 | struct hlist_head *ns_gc_inodes_h; | ||
171 | 152 | ||
172 | /* Disk layout information (static) */ | 153 | /* Disk layout information (static) */ |
173 | unsigned int ns_blocksize_bits; | 154 | unsigned int ns_blocksize_bits; |
@@ -182,9 +163,6 @@ struct the_nilfs { | |||
182 | u32 ns_crc_seed; | 163 | u32 ns_crc_seed; |
183 | }; | 164 | }; |
184 | 165 | ||
185 | #define NILFS_GCINODE_HASH_BITS 8 | ||
186 | #define NILFS_GCINODE_HASH_SIZE (1<<NILFS_GCINODE_HASH_BITS) | ||
187 | |||
188 | #define THE_NILFS_FNS(bit, name) \ | 166 | #define THE_NILFS_FNS(bit, name) \ |
189 | static inline void set_nilfs_##name(struct the_nilfs *nilfs) \ | 167 | static inline void set_nilfs_##name(struct the_nilfs *nilfs) \ |
190 | { \ | 168 | { \ |
@@ -205,6 +183,32 @@ THE_NILFS_FNS(DISCONTINUED, discontinued) | |||
205 | THE_NILFS_FNS(GC_RUNNING, gc_running) | 183 | THE_NILFS_FNS(GC_RUNNING, gc_running) |
206 | THE_NILFS_FNS(SB_DIRTY, sb_dirty) | 184 | THE_NILFS_FNS(SB_DIRTY, sb_dirty) |
207 | 185 | ||
186 | /** | ||
187 | * struct nilfs_root - nilfs root object | ||
188 | * @cno: checkpoint number | ||
189 | * @rb_node: red-black tree node | ||
190 | * @count: refcount of this structure | ||
191 | * @nilfs: nilfs object | ||
192 | * @ifile: inode file | ||
193 | * @root: root inode | ||
194 | * @inodes_count: number of inodes | ||
195 | * @blocks_count: number of blocks (Reserved) | ||
196 | */ | ||
197 | struct nilfs_root { | ||
198 | __u64 cno; | ||
199 | struct rb_node rb_node; | ||
200 | |||
201 | atomic_t count; | ||
202 | struct the_nilfs *nilfs; | ||
203 | struct inode *ifile; | ||
204 | |||
205 | atomic_t inodes_count; | ||
206 | atomic_t blocks_count; | ||
207 | }; | ||
208 | |||
209 | /* Special checkpoint number */ | ||
210 | #define NILFS_CPTREE_CURRENT_CNO 0 | ||
211 | |||
208 | /* Minimum interval of periodical update of superblocks (in seconds) */ | 212 | /* Minimum interval of periodical update of superblocks (in seconds) */ |
209 | #define NILFS_SB_FREQ 10 | 213 | #define NILFS_SB_FREQ 10 |
210 | 214 | ||
@@ -221,46 +225,25 @@ static inline int nilfs_sb_will_flip(struct the_nilfs *nilfs) | |||
221 | } | 225 | } |
222 | 226 | ||
223 | void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64); | 227 | void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64); |
224 | struct the_nilfs *find_or_create_nilfs(struct block_device *); | 228 | struct the_nilfs *alloc_nilfs(struct block_device *bdev); |
225 | void put_nilfs(struct the_nilfs *); | 229 | void destroy_nilfs(struct the_nilfs *nilfs); |
226 | int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *); | 230 | int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *); |
227 | int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *); | 231 | int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *); |
228 | int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t); | 232 | int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t); |
229 | int nilfs_count_free_blocks(struct the_nilfs *, sector_t *); | 233 | int nilfs_count_free_blocks(struct the_nilfs *, sector_t *); |
234 | struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno); | ||
235 | struct nilfs_root *nilfs_find_or_create_root(struct the_nilfs *nilfs, | ||
236 | __u64 cno); | ||
237 | void nilfs_put_root(struct nilfs_root *root); | ||
230 | struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64); | 238 | struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64); |
231 | int nilfs_checkpoint_is_mounted(struct the_nilfs *, __u64, int); | ||
232 | int nilfs_near_disk_full(struct the_nilfs *); | 239 | int nilfs_near_disk_full(struct the_nilfs *); |
233 | void nilfs_fall_back_super_block(struct the_nilfs *); | 240 | void nilfs_fall_back_super_block(struct the_nilfs *); |
234 | void nilfs_swap_super_block(struct the_nilfs *); | 241 | void nilfs_swap_super_block(struct the_nilfs *); |
235 | 242 | ||
236 | 243 | ||
237 | static inline void get_nilfs(struct the_nilfs *nilfs) | 244 | static inline void nilfs_get_root(struct nilfs_root *root) |
238 | { | ||
239 | /* Caller must have at least one reference of the_nilfs. */ | ||
240 | atomic_inc(&nilfs->ns_count); | ||
241 | } | ||
242 | |||
243 | static inline void | ||
244 | nilfs_attach_writer(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | ||
245 | { | ||
246 | down_write(&nilfs->ns_writer_sem); | ||
247 | nilfs->ns_writer = sbi; | ||
248 | up_write(&nilfs->ns_writer_sem); | ||
249 | } | ||
250 | |||
251 | static inline void | ||
252 | nilfs_detach_writer(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | ||
253 | { | ||
254 | down_write(&nilfs->ns_writer_sem); | ||
255 | if (sbi == nilfs->ns_writer) | ||
256 | nilfs->ns_writer = NULL; | ||
257 | up_write(&nilfs->ns_writer_sem); | ||
258 | } | ||
259 | |||
260 | static inline void nilfs_put_sbinfo(struct nilfs_sb_info *sbi) | ||
261 | { | 245 | { |
262 | if (atomic_dec_and_test(&sbi->s_count)) | 246 | atomic_inc(&root->count); |
263 | kfree(sbi); | ||
264 | } | 247 | } |
265 | 248 | ||
266 | static inline int nilfs_valid_fs(struct the_nilfs *nilfs) | 249 | static inline int nilfs_valid_fs(struct the_nilfs *nilfs) |