diff options
Diffstat (limited to 'fs/nilfs2/the_nilfs.c')
-rw-r--r-- | fs/nilfs2/the_nilfs.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index ad4ac607cf57..d2acd1a651f3 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
26 | #include <linux/blkdev.h> | 26 | #include <linux/blkdev.h> |
27 | #include <linux/backing-dev.h> | 27 | #include <linux/backing-dev.h> |
28 | #include <linux/random.h> | ||
28 | #include <linux/crc32.h> | 29 | #include <linux/crc32.h> |
29 | #include "nilfs.h" | 30 | #include "nilfs.h" |
30 | #include "segment.h" | 31 | #include "segment.h" |
@@ -75,7 +76,10 @@ struct the_nilfs *alloc_nilfs(struct block_device *bdev) | |||
75 | nilfs->ns_bdev = bdev; | 76 | nilfs->ns_bdev = bdev; |
76 | atomic_set(&nilfs->ns_ndirtyblks, 0); | 77 | atomic_set(&nilfs->ns_ndirtyblks, 0); |
77 | init_rwsem(&nilfs->ns_sem); | 78 | init_rwsem(&nilfs->ns_sem); |
79 | INIT_LIST_HEAD(&nilfs->ns_dirty_files); | ||
78 | INIT_LIST_HEAD(&nilfs->ns_gc_inodes); | 80 | INIT_LIST_HEAD(&nilfs->ns_gc_inodes); |
81 | spin_lock_init(&nilfs->ns_inode_lock); | ||
82 | spin_lock_init(&nilfs->ns_next_gen_lock); | ||
79 | spin_lock_init(&nilfs->ns_last_segment_lock); | 83 | spin_lock_init(&nilfs->ns_last_segment_lock); |
80 | nilfs->ns_cptree = RB_ROOT; | 84 | nilfs->ns_cptree = RB_ROOT; |
81 | spin_lock_init(&nilfs->ns_cptree_lock); | 85 | spin_lock_init(&nilfs->ns_cptree_lock); |
@@ -197,16 +201,16 @@ static int nilfs_store_log_cursor(struct the_nilfs *nilfs, | |||
197 | /** | 201 | /** |
198 | * load_nilfs - load and recover the nilfs | 202 | * load_nilfs - load and recover the nilfs |
199 | * @nilfs: the_nilfs structure to be released | 203 | * @nilfs: the_nilfs structure to be released |
200 | * @sbi: nilfs_sb_info used to recover past segment | 204 | * @sb: super block isntance used to recover past segment |
201 | * | 205 | * |
202 | * load_nilfs() searches and load the latest super root, | 206 | * load_nilfs() searches and load the latest super root, |
203 | * attaches the last segment, and does recovery if needed. | 207 | * attaches the last segment, and does recovery if needed. |
204 | * The caller must call this exclusively for simultaneous mounts. | 208 | * The caller must call this exclusively for simultaneous mounts. |
205 | */ | 209 | */ |
206 | int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | 210 | int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb) |
207 | { | 211 | { |
208 | struct nilfs_recovery_info ri; | 212 | struct nilfs_recovery_info ri; |
209 | unsigned int s_flags = sbi->s_super->s_flags; | 213 | unsigned int s_flags = sb->s_flags; |
210 | int really_read_only = bdev_read_only(nilfs->ns_bdev); | 214 | int really_read_only = bdev_read_only(nilfs->ns_bdev); |
211 | int valid_fs = nilfs_valid_fs(nilfs); | 215 | int valid_fs = nilfs_valid_fs(nilfs); |
212 | int err; | 216 | int err; |
@@ -271,7 +275,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | |||
271 | goto scan_error; | 275 | goto scan_error; |
272 | } | 276 | } |
273 | 277 | ||
274 | err = nilfs_load_super_root(nilfs, sbi->s_super, ri.ri_super_root); | 278 | err = nilfs_load_super_root(nilfs, sb, ri.ri_super_root); |
275 | if (unlikely(err)) { | 279 | if (unlikely(err)) { |
276 | printk(KERN_ERR "NILFS: error loading super root.\n"); | 280 | printk(KERN_ERR "NILFS: error loading super root.\n"); |
277 | goto failed; | 281 | goto failed; |
@@ -283,7 +287,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | |||
283 | if (s_flags & MS_RDONLY) { | 287 | if (s_flags & MS_RDONLY) { |
284 | __u64 features; | 288 | __u64 features; |
285 | 289 | ||
286 | if (nilfs_test_opt(sbi, NORECOVERY)) { | 290 | if (nilfs_test_opt(nilfs, NORECOVERY)) { |
287 | printk(KERN_INFO "NILFS: norecovery option specified. " | 291 | printk(KERN_INFO "NILFS: norecovery option specified. " |
288 | "skipping roll-forward recovery\n"); | 292 | "skipping roll-forward recovery\n"); |
289 | goto skip_recovery; | 293 | goto skip_recovery; |
@@ -304,21 +308,21 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | |||
304 | err = -EROFS; | 308 | err = -EROFS; |
305 | goto failed_unload; | 309 | goto failed_unload; |
306 | } | 310 | } |
307 | sbi->s_super->s_flags &= ~MS_RDONLY; | 311 | sb->s_flags &= ~MS_RDONLY; |
308 | } else if (nilfs_test_opt(sbi, NORECOVERY)) { | 312 | } else if (nilfs_test_opt(nilfs, NORECOVERY)) { |
309 | printk(KERN_ERR "NILFS: recovery cancelled because norecovery " | 313 | printk(KERN_ERR "NILFS: recovery cancelled because norecovery " |
310 | "option was specified for a read/write mount\n"); | 314 | "option was specified for a read/write mount\n"); |
311 | err = -EINVAL; | 315 | err = -EINVAL; |
312 | goto failed_unload; | 316 | goto failed_unload; |
313 | } | 317 | } |
314 | 318 | ||
315 | err = nilfs_salvage_orphan_logs(nilfs, sbi, &ri); | 319 | err = nilfs_salvage_orphan_logs(nilfs, sb, &ri); |
316 | if (err) | 320 | if (err) |
317 | goto failed_unload; | 321 | goto failed_unload; |
318 | 322 | ||
319 | down_write(&nilfs->ns_sem); | 323 | down_write(&nilfs->ns_sem); |
320 | nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */ | 324 | nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */ |
321 | err = nilfs_cleanup_super(sbi); | 325 | err = nilfs_cleanup_super(sb); |
322 | up_write(&nilfs->ns_sem); | 326 | up_write(&nilfs->ns_sem); |
323 | 327 | ||
324 | if (err) { | 328 | if (err) { |
@@ -330,7 +334,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | |||
330 | 334 | ||
331 | skip_recovery: | 335 | skip_recovery: |
332 | nilfs_clear_recovery_info(&ri); | 336 | nilfs_clear_recovery_info(&ri); |
333 | sbi->s_super->s_flags = s_flags; | 337 | sb->s_flags = s_flags; |
334 | return 0; | 338 | return 0; |
335 | 339 | ||
336 | scan_error: | 340 | scan_error: |
@@ -344,7 +348,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) | |||
344 | 348 | ||
345 | failed: | 349 | failed: |
346 | nilfs_clear_recovery_info(&ri); | 350 | nilfs_clear_recovery_info(&ri); |
347 | sbi->s_super->s_flags = s_flags; | 351 | sb->s_flags = s_flags; |
348 | return err; | 352 | return err; |
349 | } | 353 | } |
350 | 354 | ||
@@ -475,10 +479,13 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs, | |||
475 | return -EIO; | 479 | return -EIO; |
476 | } | 480 | } |
477 | printk(KERN_WARNING | 481 | printk(KERN_WARNING |
478 | "NILFS warning: unable to read primary superblock\n"); | 482 | "NILFS warning: unable to read primary superblock " |
479 | } else if (!sbp[1]) | 483 | "(blocksize = %d)\n", blocksize); |
484 | } else if (!sbp[1]) { | ||
480 | printk(KERN_WARNING | 485 | printk(KERN_WARNING |
481 | "NILFS warning: unable to read secondary superblock\n"); | 486 | "NILFS warning: unable to read secondary superblock " |
487 | "(blocksize = %d)\n", blocksize); | ||
488 | } | ||
482 | 489 | ||
483 | /* | 490 | /* |
484 | * Compare two super blocks and set 1 in swp if the secondary | 491 | * Compare two super blocks and set 1 in swp if the secondary |
@@ -505,7 +512,7 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs, | |||
505 | 512 | ||
506 | if (!valid[!swp]) | 513 | if (!valid[!swp]) |
507 | printk(KERN_WARNING "NILFS warning: broken superblock. " | 514 | printk(KERN_WARNING "NILFS warning: broken superblock. " |
508 | "using spare superblock.\n"); | 515 | "using spare superblock (blocksize = %d).\n", blocksize); |
509 | if (swp) | 516 | if (swp) |
510 | nilfs_swap_super_block(nilfs); | 517 | nilfs_swap_super_block(nilfs); |
511 | 518 | ||
@@ -519,7 +526,6 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs, | |||
519 | /** | 526 | /** |
520 | * init_nilfs - initialize a NILFS instance. | 527 | * init_nilfs - initialize a NILFS instance. |
521 | * @nilfs: the_nilfs structure | 528 | * @nilfs: the_nilfs structure |
522 | * @sbi: nilfs_sb_info | ||
523 | * @sb: super block | 529 | * @sb: super block |
524 | * @data: mount options | 530 | * @data: mount options |
525 | * | 531 | * |
@@ -530,9 +536,8 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs, | |||
530 | * Return Value: On success, 0 is returned. On error, a negative error | 536 | * Return Value: On success, 0 is returned. On error, a negative error |
531 | * code is returned. | 537 | * code is returned. |
532 | */ | 538 | */ |
533 | int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data) | 539 | int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data) |
534 | { | 540 | { |
535 | struct super_block *sb = sbi->s_super; | ||
536 | struct nilfs_super_block *sbp; | 541 | struct nilfs_super_block *sbp; |
537 | int blocksize; | 542 | int blocksize; |
538 | int err; | 543 | int err; |
@@ -588,6 +593,9 @@ int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data) | |||
588 | nilfs->ns_blocksize_bits = sb->s_blocksize_bits; | 593 | nilfs->ns_blocksize_bits = sb->s_blocksize_bits; |
589 | nilfs->ns_blocksize = blocksize; | 594 | nilfs->ns_blocksize = blocksize; |
590 | 595 | ||
596 | get_random_bytes(&nilfs->ns_next_generation, | ||
597 | sizeof(nilfs->ns_next_generation)); | ||
598 | |||
591 | err = nilfs_store_disk_layout(nilfs, sbp); | 599 | err = nilfs_store_disk_layout(nilfs, sbp); |
592 | if (err) | 600 | if (err) |
593 | goto failed_sbh; | 601 | goto failed_sbh; |