aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/the_nilfs.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nilfs2/the_nilfs.h')
-rw-r--r--fs/nilfs2/the_nilfs.h101
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 */
96struct the_nilfs { 88struct 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) \
189static inline void set_nilfs_##name(struct the_nilfs *nilfs) \ 167static inline void set_nilfs_##name(struct the_nilfs *nilfs) \
190{ \ 168{ \
@@ -205,6 +183,32 @@ THE_NILFS_FNS(DISCONTINUED, discontinued)
205THE_NILFS_FNS(GC_RUNNING, gc_running) 183THE_NILFS_FNS(GC_RUNNING, gc_running)
206THE_NILFS_FNS(SB_DIRTY, sb_dirty) 184THE_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 */
197struct 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
223void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64); 227void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64);
224struct the_nilfs *find_or_create_nilfs(struct block_device *); 228struct the_nilfs *alloc_nilfs(struct block_device *bdev);
225void put_nilfs(struct the_nilfs *); 229void destroy_nilfs(struct the_nilfs *nilfs);
226int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *); 230int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *);
227int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *); 231int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *);
228int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t); 232int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t);
229int nilfs_count_free_blocks(struct the_nilfs *, sector_t *); 233int nilfs_count_free_blocks(struct the_nilfs *, sector_t *);
234struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno);
235struct nilfs_root *nilfs_find_or_create_root(struct the_nilfs *nilfs,
236 __u64 cno);
237void nilfs_put_root(struct nilfs_root *root);
230struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64); 238struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64);
231int nilfs_checkpoint_is_mounted(struct the_nilfs *, __u64, int);
232int nilfs_near_disk_full(struct the_nilfs *); 239int nilfs_near_disk_full(struct the_nilfs *);
233void nilfs_fall_back_super_block(struct the_nilfs *); 240void nilfs_fall_back_super_block(struct the_nilfs *);
234void nilfs_swap_super_block(struct the_nilfs *); 241void nilfs_swap_super_block(struct the_nilfs *);
235 242
236 243
237static inline void get_nilfs(struct the_nilfs *nilfs) 244static 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
243static inline void
244nilfs_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
251static inline void
252nilfs_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
260static 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
266static inline int nilfs_valid_fs(struct the_nilfs *nilfs) 249static inline int nilfs_valid_fs(struct the_nilfs *nilfs)