aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/nilfs2/nilfs.h10
-rw-r--r--fs/nilfs2/recovery.c32
-rw-r--r--fs/nilfs2/segment.c90
-rw-r--r--fs/nilfs2/segment.h10
-rw-r--r--fs/nilfs2/super.c105
-rw-r--r--fs/nilfs2/the_nilfs.c22
-rw-r--r--fs/nilfs2/the_nilfs.h5
7 files changed, 129 insertions, 145 deletions
diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h
index 03ba4d88083f..eba1aaa7fb7b 100644
--- a/fs/nilfs2/nilfs.h
+++ b/fs/nilfs2/nilfs.h
@@ -295,11 +295,11 @@ extern int nilfs_check_feature_compatibility(struct super_block *,
295 struct nilfs_super_block *); 295 struct nilfs_super_block *);
296extern void nilfs_set_log_cursor(struct nilfs_super_block *, 296extern void nilfs_set_log_cursor(struct nilfs_super_block *,
297 struct the_nilfs *); 297 struct the_nilfs *);
298extern struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *, 298struct nilfs_super_block **nilfs_prepare_super(struct super_block *sb,
299 int flip); 299 int flip);
300extern int nilfs_commit_super(struct nilfs_sb_info *, int); 300int nilfs_commit_super(struct super_block *sb, int flag);
301extern int nilfs_cleanup_super(struct nilfs_sb_info *); 301int nilfs_cleanup_super(struct super_block *sb);
302int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt, 302int nilfs_attach_checkpoint(struct super_block *sb, __u64 cno, int curr_mnt,
303 struct nilfs_root **root); 303 struct nilfs_root **root);
304int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno); 304int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno);
305 305
diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c
index 3dfcd3b7d389..ba4a64518f38 100644
--- a/fs/nilfs2/recovery.c
+++ b/fs/nilfs2/recovery.c
@@ -425,7 +425,7 @@ void nilfs_dispose_segment_list(struct list_head *head)
425} 425}
426 426
427static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs, 427static int nilfs_prepare_segment_for_recovery(struct the_nilfs *nilfs,
428 struct nilfs_sb_info *sbi, 428 struct super_block *sb,
429 struct nilfs_recovery_info *ri) 429 struct nilfs_recovery_info *ri)
430{ 430{
431 struct list_head *head = &ri->ri_used_segments; 431 struct list_head *head = &ri->ri_used_segments;
@@ -501,7 +501,7 @@ static int nilfs_recovery_copy_block(struct the_nilfs *nilfs,
501} 501}
502 502
503static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs, 503static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
504 struct nilfs_sb_info *sbi, 504 struct super_block *sb,
505 struct nilfs_root *root, 505 struct nilfs_root *root,
506 struct list_head *head, 506 struct list_head *head,
507 unsigned long *nr_salvaged_blocks) 507 unsigned long *nr_salvaged_blocks)
@@ -514,7 +514,7 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
514 int err = 0, err2 = 0; 514 int err = 0, err2 = 0;
515 515
516 list_for_each_entry_safe(rb, n, head, list) { 516 list_for_each_entry_safe(rb, n, head, list) {
517 inode = nilfs_iget(sbi->s_super, root, rb->ino); 517 inode = nilfs_iget(sb, root, rb->ino);
518 if (IS_ERR(inode)) { 518 if (IS_ERR(inode)) {
519 err = PTR_ERR(inode); 519 err = PTR_ERR(inode);
520 inode = NULL; 520 inode = NULL;
@@ -572,11 +572,11 @@ static int nilfs_recover_dsync_blocks(struct the_nilfs *nilfs,
572 * nilfs_do_roll_forward - salvage logical segments newer than the latest 572 * nilfs_do_roll_forward - salvage logical segments newer than the latest
573 * checkpoint 573 * checkpoint
574 * @nilfs: nilfs object 574 * @nilfs: nilfs object
575 * @sbi: nilfs_sb_info 575 * @sb: super block instance
576 * @ri: pointer to a nilfs_recovery_info 576 * @ri: pointer to a nilfs_recovery_info
577 */ 577 */
578static int nilfs_do_roll_forward(struct the_nilfs *nilfs, 578static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
579 struct nilfs_sb_info *sbi, 579 struct super_block *sb,
580 struct nilfs_root *root, 580 struct nilfs_root *root,
581 struct nilfs_recovery_info *ri) 581 struct nilfs_recovery_info *ri)
582{ 582{
@@ -648,7 +648,7 @@ static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
648 goto failed; 648 goto failed;
649 if (flags & NILFS_SS_LOGEND) { 649 if (flags & NILFS_SS_LOGEND) {
650 err = nilfs_recover_dsync_blocks( 650 err = nilfs_recover_dsync_blocks(
651 nilfs, sbi, root, &dsync_blocks, 651 nilfs, sb, root, &dsync_blocks,
652 &nsalvaged_blocks); 652 &nsalvaged_blocks);
653 if (unlikely(err)) 653 if (unlikely(err))
654 goto failed; 654 goto failed;
@@ -681,7 +681,7 @@ static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
681 681
682 if (nsalvaged_blocks) { 682 if (nsalvaged_blocks) {
683 printk(KERN_INFO "NILFS (device %s): salvaged %lu blocks\n", 683 printk(KERN_INFO "NILFS (device %s): salvaged %lu blocks\n",
684 sbi->s_super->s_id, nsalvaged_blocks); 684 sb->s_id, nsalvaged_blocks);
685 ri->ri_need_recovery = NILFS_RECOVERY_ROLLFORWARD_DONE; 685 ri->ri_need_recovery = NILFS_RECOVERY_ROLLFORWARD_DONE;
686 } 686 }
687 out: 687 out:
@@ -695,7 +695,7 @@ static int nilfs_do_roll_forward(struct the_nilfs *nilfs,
695 printk(KERN_ERR 695 printk(KERN_ERR
696 "NILFS (device %s): Error roll-forwarding " 696 "NILFS (device %s): Error roll-forwarding "
697 "(err=%d, pseg block=%llu). ", 697 "(err=%d, pseg block=%llu). ",
698 sbi->s_super->s_id, err, (unsigned long long)pseg_start); 698 sb->s_id, err, (unsigned long long)pseg_start);
699 goto out; 699 goto out;
700} 700}
701 701
@@ -724,7 +724,7 @@ static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
724/** 724/**
725 * nilfs_salvage_orphan_logs - salvage logs written after the latest checkpoint 725 * nilfs_salvage_orphan_logs - salvage logs written after the latest checkpoint
726 * @nilfs: nilfs object 726 * @nilfs: nilfs object
727 * @sbi: nilfs_sb_info 727 * @sb: super block instance
728 * @ri: pointer to a nilfs_recovery_info struct to store search results. 728 * @ri: pointer to a nilfs_recovery_info struct to store search results.
729 * 729 *
730 * Return Value: On success, 0 is returned. On error, one of the following 730 * Return Value: On success, 0 is returned. On error, one of the following
@@ -741,7 +741,7 @@ static void nilfs_finish_roll_forward(struct the_nilfs *nilfs,
741 * %-ENOMEM - Insufficient memory available. 741 * %-ENOMEM - Insufficient memory available.
742 */ 742 */
743int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, 743int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs,
744 struct nilfs_sb_info *sbi, 744 struct super_block *sb,
745 struct nilfs_recovery_info *ri) 745 struct nilfs_recovery_info *ri)
746{ 746{
747 struct nilfs_root *root; 747 struct nilfs_root *root;
@@ -750,32 +750,32 @@ int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs,
750 if (ri->ri_lsegs_start == 0 || ri->ri_lsegs_end == 0) 750 if (ri->ri_lsegs_start == 0 || ri->ri_lsegs_end == 0)
751 return 0; 751 return 0;
752 752
753 err = nilfs_attach_checkpoint(sbi, ri->ri_cno, true, &root); 753 err = nilfs_attach_checkpoint(sb, ri->ri_cno, true, &root);
754 if (unlikely(err)) { 754 if (unlikely(err)) {
755 printk(KERN_ERR 755 printk(KERN_ERR
756 "NILFS: error loading the latest checkpoint.\n"); 756 "NILFS: error loading the latest checkpoint.\n");
757 return err; 757 return err;
758 } 758 }
759 759
760 err = nilfs_do_roll_forward(nilfs, sbi, root, ri); 760 err = nilfs_do_roll_forward(nilfs, sb, root, ri);
761 if (unlikely(err)) 761 if (unlikely(err))
762 goto failed; 762 goto failed;
763 763
764 if (ri->ri_need_recovery == NILFS_RECOVERY_ROLLFORWARD_DONE) { 764 if (ri->ri_need_recovery == NILFS_RECOVERY_ROLLFORWARD_DONE) {
765 err = nilfs_prepare_segment_for_recovery(nilfs, sbi, ri); 765 err = nilfs_prepare_segment_for_recovery(nilfs, sb, ri);
766 if (unlikely(err)) { 766 if (unlikely(err)) {
767 printk(KERN_ERR "NILFS: Error preparing segments for " 767 printk(KERN_ERR "NILFS: Error preparing segments for "
768 "recovery.\n"); 768 "recovery.\n");
769 goto failed; 769 goto failed;
770 } 770 }
771 771
772 err = nilfs_attach_segment_constructor(sbi, root); 772 err = nilfs_attach_log_writer(sb, root);
773 if (unlikely(err)) 773 if (unlikely(err))
774 goto failed; 774 goto failed;
775 775
776 set_nilfs_discontinued(nilfs); 776 set_nilfs_discontinued(nilfs);
777 err = nilfs_construct_segment(sbi->s_super); 777 err = nilfs_construct_segment(sb);
778 nilfs_detach_segment_constructor(sbi); 778 nilfs_detach_log_writer(sb);
779 779
780 if (unlikely(err)) { 780 if (unlikely(err)) {
781 printk(KERN_ERR "NILFS: Oops! recovery failed. " 781 printk(KERN_ERR "NILFS: Oops! recovery failed. "
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index b14788ec0d15..90e3130303a3 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -181,7 +181,6 @@ int nilfs_transaction_begin(struct super_block *sb,
181 struct nilfs_transaction_info *ti, 181 struct nilfs_transaction_info *ti,
182 int vacancy_check) 182 int vacancy_check)
183{ 183{
184 struct nilfs_sb_info *sbi;
185 struct the_nilfs *nilfs; 184 struct the_nilfs *nilfs;
186 int ret = nilfs_prepare_segment_lock(ti); 185 int ret = nilfs_prepare_segment_lock(ti);
187 186
@@ -192,8 +191,7 @@ int nilfs_transaction_begin(struct super_block *sb,
192 191
193 vfs_check_frozen(sb, SB_FREEZE_WRITE); 192 vfs_check_frozen(sb, SB_FREEZE_WRITE);
194 193
195 sbi = NILFS_SB(sb); 194 nilfs = NILFS_SB(sb)->s_nilfs;
196 nilfs = sbi->s_nilfs;
197 down_read(&nilfs->ns_segctor_sem); 195 down_read(&nilfs->ns_segctor_sem);
198 if (vacancy_check && nilfs_near_disk_full(nilfs)) { 196 if (vacancy_check && nilfs_near_disk_full(nilfs)) {
199 up_read(&nilfs->ns_segctor_sem); 197 up_read(&nilfs->ns_segctor_sem);
@@ -290,12 +288,12 @@ void nilfs_relax_pressure_in_lock(struct super_block *sb)
290 downgrade_write(&nilfs->ns_segctor_sem); 288 downgrade_write(&nilfs->ns_segctor_sem);
291} 289}
292 290
293static void nilfs_transaction_lock(struct nilfs_sb_info *sbi, 291static void nilfs_transaction_lock(struct super_block *sb,
294 struct nilfs_transaction_info *ti, 292 struct nilfs_transaction_info *ti,
295 int gcflag) 293 int gcflag)
296{ 294{
297 struct nilfs_transaction_info *cur_ti = current->journal_info; 295 struct nilfs_transaction_info *cur_ti = current->journal_info;
298 struct the_nilfs *nilfs = sbi->s_nilfs; 296 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
299 struct nilfs_sc_info *sci = nilfs->ns_writer; 297 struct nilfs_sc_info *sci = nilfs->ns_writer;
300 298
301 WARN_ON(cur_ti); 299 WARN_ON(cur_ti);
@@ -313,17 +311,17 @@ static void nilfs_transaction_lock(struct nilfs_sb_info *sbi,
313 311
314 nilfs_segctor_do_immediate_flush(sci); 312 nilfs_segctor_do_immediate_flush(sci);
315 313
316 up_write(&sbi->s_nilfs->ns_segctor_sem); 314 up_write(&nilfs->ns_segctor_sem);
317 yield(); 315 yield();
318 } 316 }
319 if (gcflag) 317 if (gcflag)
320 ti->ti_flags |= NILFS_TI_GC; 318 ti->ti_flags |= NILFS_TI_GC;
321} 319}
322 320
323static void nilfs_transaction_unlock(struct nilfs_sb_info *sbi) 321static void nilfs_transaction_unlock(struct super_block *sb)
324{ 322{
325 struct nilfs_transaction_info *ti = current->journal_info; 323 struct nilfs_transaction_info *ti = current->journal_info;
326 struct the_nilfs *nilfs = sbi->s_nilfs; 324 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
327 325
328 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC); 326 BUG_ON(ti == NULL || ti->ti_magic != NILFS_TI_MAGIC);
329 BUG_ON(ti->ti_count > 0); 327 BUG_ON(ti->ti_count > 0);
@@ -2292,8 +2290,7 @@ int nilfs_construct_segment(struct super_block *sb)
2292int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode, 2290int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2293 loff_t start, loff_t end) 2291 loff_t start, loff_t end)
2294{ 2292{
2295 struct nilfs_sb_info *sbi = NILFS_SB(sb); 2293 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2296 struct the_nilfs *nilfs = sbi->s_nilfs;
2297 struct nilfs_sc_info *sci = nilfs->ns_writer; 2294 struct nilfs_sc_info *sci = nilfs->ns_writer;
2298 struct nilfs_inode_info *ii; 2295 struct nilfs_inode_info *ii;
2299 struct nilfs_transaction_info ti; 2296 struct nilfs_transaction_info ti;
@@ -2302,14 +2299,14 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2302 if (!sci) 2299 if (!sci)
2303 return -EROFS; 2300 return -EROFS;
2304 2301
2305 nilfs_transaction_lock(sbi, &ti, 0); 2302 nilfs_transaction_lock(sb, &ti, 0);
2306 2303
2307 ii = NILFS_I(inode); 2304 ii = NILFS_I(inode);
2308 if (test_bit(NILFS_I_INODE_DIRTY, &ii->i_state) || 2305 if (test_bit(NILFS_I_INODE_DIRTY, &ii->i_state) ||
2309 nilfs_test_opt(nilfs, STRICT_ORDER) || 2306 nilfs_test_opt(nilfs, STRICT_ORDER) ||
2310 test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) || 2307 test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags) ||
2311 nilfs_discontinued(nilfs)) { 2308 nilfs_discontinued(nilfs)) {
2312 nilfs_transaction_unlock(sbi); 2309 nilfs_transaction_unlock(sb);
2313 err = nilfs_segctor_sync(sci); 2310 err = nilfs_segctor_sync(sci);
2314 return err; 2311 return err;
2315 } 2312 }
@@ -2318,7 +2315,7 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2318 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) && 2315 if (!test_bit(NILFS_I_QUEUED, &ii->i_state) &&
2319 !test_bit(NILFS_I_BUSY, &ii->i_state)) { 2316 !test_bit(NILFS_I_BUSY, &ii->i_state)) {
2320 spin_unlock(&nilfs->ns_inode_lock); 2317 spin_unlock(&nilfs->ns_inode_lock);
2321 nilfs_transaction_unlock(sbi); 2318 nilfs_transaction_unlock(sb);
2322 return 0; 2319 return 0;
2323 } 2320 }
2324 spin_unlock(&nilfs->ns_inode_lock); 2321 spin_unlock(&nilfs->ns_inode_lock);
@@ -2328,7 +2325,7 @@ int nilfs_construct_dsync_segment(struct super_block *sb, struct inode *inode,
2328 2325
2329 err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC); 2326 err = nilfs_segctor_do_construct(sci, SC_LSEG_DSYNC);
2330 2327
2331 nilfs_transaction_unlock(sbi); 2328 nilfs_transaction_unlock(sb);
2332 return err; 2329 return err;
2333} 2330}
2334 2331
@@ -2384,8 +2381,7 @@ static void nilfs_segctor_notify(struct nilfs_sc_info *sci, int mode, int err)
2384 */ 2381 */
2385static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode) 2382static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode)
2386{ 2383{
2387 struct nilfs_sb_info *sbi = NILFS_SB(sci->sc_super); 2384 struct the_nilfs *nilfs = NILFS_SB(sci->sc_super)->s_nilfs;
2388 struct the_nilfs *nilfs = sbi->s_nilfs;
2389 struct nilfs_super_block **sbp; 2385 struct nilfs_super_block **sbp;
2390 int err = 0; 2386 int err = 0;
2391 2387
@@ -2403,11 +2399,12 @@ static int nilfs_segctor_construct(struct nilfs_sc_info *sci, int mode)
2403 nilfs_discontinued(nilfs)) { 2399 nilfs_discontinued(nilfs)) {
2404 down_write(&nilfs->ns_sem); 2400 down_write(&nilfs->ns_sem);
2405 err = -EIO; 2401 err = -EIO;
2406 sbp = nilfs_prepare_super(sbi, 2402 sbp = nilfs_prepare_super(sci->sc_super,
2407 nilfs_sb_will_flip(nilfs)); 2403 nilfs_sb_will_flip(nilfs));
2408 if (likely(sbp)) { 2404 if (likely(sbp)) {
2409 nilfs_set_log_cursor(sbp[0], nilfs); 2405 nilfs_set_log_cursor(sbp[0], nilfs);
2410 err = nilfs_commit_super(sbi, NILFS_SB_COMMIT); 2406 err = nilfs_commit_super(sci->sc_super,
2407 NILFS_SB_COMMIT);
2411 } 2408 }
2412 up_write(&nilfs->ns_sem); 2409 up_write(&nilfs->ns_sem);
2413 } 2410 }
@@ -2439,8 +2436,7 @@ nilfs_remove_written_gcinodes(struct the_nilfs *nilfs, struct list_head *head)
2439int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv, 2436int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2440 void **kbufs) 2437 void **kbufs)
2441{ 2438{
2442 struct nilfs_sb_info *sbi = NILFS_SB(sb); 2439 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2443 struct the_nilfs *nilfs = sbi->s_nilfs;
2444 struct nilfs_sc_info *sci = nilfs->ns_writer; 2440 struct nilfs_sc_info *sci = nilfs->ns_writer;
2445 struct nilfs_transaction_info ti; 2441 struct nilfs_transaction_info ti;
2446 int err; 2442 int err;
@@ -2448,7 +2444,7 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2448 if (unlikely(!sci)) 2444 if (unlikely(!sci))
2449 return -EROFS; 2445 return -EROFS;
2450 2446
2451 nilfs_transaction_lock(sbi, &ti, 1); 2447 nilfs_transaction_lock(sb, &ti, 1);
2452 2448
2453 err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat); 2449 err = nilfs_mdt_save_to_shadow_map(nilfs->ns_dat);
2454 if (unlikely(err)) 2450 if (unlikely(err))
@@ -2491,16 +2487,15 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
2491 sci->sc_freesegs = NULL; 2487 sci->sc_freesegs = NULL;
2492 sci->sc_nfreesegs = 0; 2488 sci->sc_nfreesegs = 0;
2493 nilfs_mdt_clear_shadow_map(nilfs->ns_dat); 2489 nilfs_mdt_clear_shadow_map(nilfs->ns_dat);
2494 nilfs_transaction_unlock(sbi); 2490 nilfs_transaction_unlock(sb);
2495 return err; 2491 return err;
2496} 2492}
2497 2493
2498static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode) 2494static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode)
2499{ 2495{
2500 struct nilfs_sb_info *sbi = NILFS_SB(sci->sc_super);
2501 struct nilfs_transaction_info ti; 2496 struct nilfs_transaction_info ti;
2502 2497
2503 nilfs_transaction_lock(sbi, &ti, 0); 2498 nilfs_transaction_lock(sci->sc_super, &ti, 0);
2504 nilfs_segctor_construct(sci, mode); 2499 nilfs_segctor_construct(sci, mode);
2505 2500
2506 /* 2501 /*
@@ -2511,7 +2506,7 @@ static void nilfs_segctor_thread_construct(struct nilfs_sc_info *sci, int mode)
2511 if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags)) 2506 if (test_bit(NILFS_SC_UNCLOSED, &sci->sc_flags))
2512 nilfs_segctor_start_timer(sci); 2507 nilfs_segctor_start_timer(sci);
2513 2508
2514 nilfs_transaction_unlock(sbi); 2509 nilfs_transaction_unlock(sci->sc_super);
2515} 2510}
2516 2511
2517static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci) 2512static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *sci)
@@ -2668,17 +2663,17 @@ static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci)
2668/* 2663/*
2669 * Setup & clean-up functions 2664 * Setup & clean-up functions
2670 */ 2665 */
2671static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi, 2666static struct nilfs_sc_info *nilfs_segctor_new(struct super_block *sb,
2672 struct nilfs_root *root) 2667 struct nilfs_root *root)
2673{ 2668{
2674 struct the_nilfs *nilfs = sbi->s_nilfs; 2669 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2675 struct nilfs_sc_info *sci; 2670 struct nilfs_sc_info *sci;
2676 2671
2677 sci = kzalloc(sizeof(*sci), GFP_KERNEL); 2672 sci = kzalloc(sizeof(*sci), GFP_KERNEL);
2678 if (!sci) 2673 if (!sci)
2679 return NULL; 2674 return NULL;
2680 2675
2681 sci->sc_super = sbi->s_super; 2676 sci->sc_super = sb;
2682 2677
2683 nilfs_get_root(root); 2678 nilfs_get_root(root);
2684 sci->sc_root = root; 2679 sci->sc_root = root;
@@ -2712,12 +2707,11 @@ static void nilfs_segctor_write_out(struct nilfs_sc_info *sci)
2712 /* The segctord thread was stopped and its timer was removed. 2707 /* The segctord thread was stopped and its timer was removed.
2713 But some tasks remain. */ 2708 But some tasks remain. */
2714 do { 2709 do {
2715 struct nilfs_sb_info *sbi = NILFS_SB(sci->sc_super);
2716 struct nilfs_transaction_info ti; 2710 struct nilfs_transaction_info ti;
2717 2711
2718 nilfs_transaction_lock(sbi, &ti, 0); 2712 nilfs_transaction_lock(sci->sc_super, &ti, 0);
2719 ret = nilfs_segctor_construct(sci, SC_LSEG_SR); 2713 ret = nilfs_segctor_construct(sci, SC_LSEG_SR);
2720 nilfs_transaction_unlock(sbi); 2714 nilfs_transaction_unlock(sci->sc_super);
2721 2715
2722 } while (ret && retrycount-- > 0); 2716 } while (ret && retrycount-- > 0);
2723} 2717}
@@ -2766,22 +2760,21 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci)
2766} 2760}
2767 2761
2768/** 2762/**
2769 * nilfs_attach_segment_constructor - attach a segment constructor 2763 * nilfs_attach_log_writer - attach log writer
2770 * @sbi: nilfs_sb_info 2764 * @sb: super block instance
2771 * @root: root object of the current filesystem tree 2765 * @root: root object of the current filesystem tree
2772 * 2766 *
2773 * nilfs_attach_segment_constructor() allocates a struct nilfs_sc_info, 2767 * This allocates a log writer object, initializes it, and starts the
2774 * initializes it, and starts the segment constructor. 2768 * log writer.
2775 * 2769 *
2776 * Return Value: On success, 0 is returned. On error, one of the following 2770 * Return Value: On success, 0 is returned. On error, one of the following
2777 * negative error code is returned. 2771 * negative error code is returned.
2778 * 2772 *
2779 * %-ENOMEM - Insufficient memory available. 2773 * %-ENOMEM - Insufficient memory available.
2780 */ 2774 */
2781int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi, 2775int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root)
2782 struct nilfs_root *root)
2783{ 2776{
2784 struct the_nilfs *nilfs = sbi->s_nilfs; 2777 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2785 int err; 2778 int err;
2786 2779
2787 if (nilfs->ns_writer) { 2780 if (nilfs->ns_writer) {
@@ -2790,10 +2783,10 @@ int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi,
2790 * read/write after nilfs_error degenerated it into a 2783 * read/write after nilfs_error degenerated it into a
2791 * read-only mount. 2784 * read-only mount.
2792 */ 2785 */
2793 nilfs_detach_segment_constructor(sbi); 2786 nilfs_detach_log_writer(sb);
2794 } 2787 }
2795 2788
2796 nilfs->ns_writer = nilfs_segctor_new(sbi, root); 2789 nilfs->ns_writer = nilfs_segctor_new(sb, root);
2797 if (!nilfs->ns_writer) 2790 if (!nilfs->ns_writer)
2798 return -ENOMEM; 2791 return -ENOMEM;
2799 2792
@@ -2806,15 +2799,15 @@ int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi,
2806} 2799}
2807 2800
2808/** 2801/**
2809 * nilfs_detach_segment_constructor - destroy the segment constructor 2802 * nilfs_detach_log_writer - destroy log writer
2810 * @sbi: nilfs_sb_info 2803 * @sb: super block instance
2811 * 2804 *
2812 * nilfs_detach_segment_constructor() kills the segment constructor daemon, 2805 * This kills log writer daemon, frees the log writer object, and
2813 * frees the struct nilfs_sc_info, and destroy the dirty file list. 2806 * destroys list of dirty files.
2814 */ 2807 */
2815void nilfs_detach_segment_constructor(struct nilfs_sb_info *sbi) 2808void nilfs_detach_log_writer(struct super_block *sb)
2816{ 2809{
2817 struct the_nilfs *nilfs = sbi->s_nilfs; 2810 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
2818 LIST_HEAD(garbage_list); 2811 LIST_HEAD(garbage_list);
2819 2812
2820 down_write(&nilfs->ns_segctor_sem); 2813 down_write(&nilfs->ns_segctor_sem);
@@ -2827,9 +2820,8 @@ void nilfs_detach_segment_constructor(struct nilfs_sb_info *sbi)
2827 spin_lock(&nilfs->ns_inode_lock); 2820 spin_lock(&nilfs->ns_inode_lock);
2828 if (!list_empty(&nilfs->ns_dirty_files)) { 2821 if (!list_empty(&nilfs->ns_dirty_files)) {
2829 list_splice_init(&nilfs->ns_dirty_files, &garbage_list); 2822 list_splice_init(&nilfs->ns_dirty_files, &garbage_list);
2830 nilfs_warning(sbi->s_super, __func__, 2823 nilfs_warning(sb, __func__,
2831 "Non empty dirty list after the last " 2824 "Hit dirty file after stopped log writer\n");
2832 "segment construction\n");
2833 } 2825 }
2834 spin_unlock(&nilfs->ns_inode_lock); 2826 spin_unlock(&nilfs->ns_inode_lock);
2835 up_write(&nilfs->ns_segctor_sem); 2827 up_write(&nilfs->ns_segctor_sem);
diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h
index 9544aa97dd49..e01998e33b31 100644
--- a/fs/nilfs2/segment.h
+++ b/fs/nilfs2/segment.h
@@ -233,18 +233,16 @@ extern void nilfs_flush_segment(struct super_block *, ino_t);
233extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *, 233extern int nilfs_clean_segments(struct super_block *, struct nilfs_argv *,
234 void **); 234 void **);
235 235
236int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi, 236int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *root);
237 struct nilfs_root *root); 237void nilfs_detach_log_writer(struct super_block *sb);
238extern void nilfs_detach_segment_constructor(struct nilfs_sb_info *);
239 238
240/* recovery.c */ 239/* recovery.c */
241extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t, 240extern int nilfs_read_super_root_block(struct the_nilfs *, sector_t,
242 struct buffer_head **, int); 241 struct buffer_head **, int);
243extern int nilfs_search_super_root(struct the_nilfs *, 242extern int nilfs_search_super_root(struct the_nilfs *,
244 struct nilfs_recovery_info *); 243 struct nilfs_recovery_info *);
245extern int nilfs_salvage_orphan_logs(struct the_nilfs *, 244int nilfs_salvage_orphan_logs(struct the_nilfs *nilfs, struct super_block *sb,
246 struct nilfs_sb_info *, 245 struct nilfs_recovery_info *ri);
247 struct nilfs_recovery_info *);
248extern void nilfs_dispose_segment_list(struct list_head *); 246extern void nilfs_dispose_segment_list(struct list_head *);
249 247
250#endif /* _NILFS_SEGMENT_H */ 248#endif /* _NILFS_SEGMENT_H */
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 1368c4293c7f..a8cbd695441e 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -71,23 +71,23 @@ struct kmem_cache *nilfs_transaction_cachep;
71struct kmem_cache *nilfs_segbuf_cachep; 71struct kmem_cache *nilfs_segbuf_cachep;
72struct kmem_cache *nilfs_btree_path_cache; 72struct kmem_cache *nilfs_btree_path_cache;
73 73
74static int nilfs_setup_super(struct nilfs_sb_info *sbi, int is_mount); 74static int nilfs_setup_super(struct super_block *sb, int is_mount);
75static int nilfs_remount(struct super_block *sb, int *flags, char *data); 75static int nilfs_remount(struct super_block *sb, int *flags, char *data);
76 76
77static void nilfs_set_error(struct nilfs_sb_info *sbi) 77static void nilfs_set_error(struct super_block *sb)
78{ 78{
79 struct the_nilfs *nilfs = sbi->s_nilfs; 79 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
80 struct nilfs_super_block **sbp; 80 struct nilfs_super_block **sbp;
81 81
82 down_write(&nilfs->ns_sem); 82 down_write(&nilfs->ns_sem);
83 if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) { 83 if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) {
84 nilfs->ns_mount_state |= NILFS_ERROR_FS; 84 nilfs->ns_mount_state |= NILFS_ERROR_FS;
85 sbp = nilfs_prepare_super(sbi, 0); 85 sbp = nilfs_prepare_super(sb, 0);
86 if (likely(sbp)) { 86 if (likely(sbp)) {
87 sbp[0]->s_state |= cpu_to_le16(NILFS_ERROR_FS); 87 sbp[0]->s_state |= cpu_to_le16(NILFS_ERROR_FS);
88 if (sbp[1]) 88 if (sbp[1])
89 sbp[1]->s_state |= cpu_to_le16(NILFS_ERROR_FS); 89 sbp[1]->s_state |= cpu_to_le16(NILFS_ERROR_FS);
90 nilfs_commit_super(sbi, NILFS_SB_COMMIT_ALL); 90 nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL);
91 } 91 }
92 } 92 }
93 up_write(&nilfs->ns_sem); 93 up_write(&nilfs->ns_sem);
@@ -108,7 +108,7 @@ static void nilfs_set_error(struct nilfs_sb_info *sbi)
108void nilfs_error(struct super_block *sb, const char *function, 108void nilfs_error(struct super_block *sb, const char *function,
109 const char *fmt, ...) 109 const char *fmt, ...)
110{ 110{
111 struct the_nilfs *nilfs = sbi->s_nilfs; 111 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
112 struct va_format vaf; 112 struct va_format vaf;
113 va_list args; 113 va_list args;
114 114
@@ -123,7 +123,7 @@ void nilfs_error(struct super_block *sb, const char *function,
123 va_end(args); 123 va_end(args);
124 124
125 if (!(sb->s_flags & MS_RDONLY)) { 125 if (!(sb->s_flags & MS_RDONLY)) {
126 nilfs_set_error(sbi); 126 nilfs_set_error(sb);
127 127
128 if (nilfs_test_opt(nilfs, ERRORS_RO)) { 128 if (nilfs_test_opt(nilfs, ERRORS_RO)) {
129 printk(KERN_CRIT "Remounting filesystem read-only\n"); 129 printk(KERN_CRIT "Remounting filesystem read-only\n");
@@ -188,9 +188,9 @@ void nilfs_destroy_inode(struct inode *inode)
188 call_rcu(&inode->i_rcu, nilfs_i_callback); 188 call_rcu(&inode->i_rcu, nilfs_i_callback);
189} 189}
190 190
191static int nilfs_sync_super(struct nilfs_sb_info *sbi, int flag) 191static int nilfs_sync_super(struct super_block *sb, int flag)
192{ 192{
193 struct the_nilfs *nilfs = sbi->s_nilfs; 193 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
194 int err; 194 int err;
195 195
196 retry: 196 retry:
@@ -262,10 +262,10 @@ void nilfs_set_log_cursor(struct nilfs_super_block *sbp,
262 spin_unlock(&nilfs->ns_last_segment_lock); 262 spin_unlock(&nilfs->ns_last_segment_lock);
263} 263}
264 264
265struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi, 265struct nilfs_super_block **nilfs_prepare_super(struct super_block *sb,
266 int flip) 266 int flip)
267{ 267{
268 struct the_nilfs *nilfs = sbi->s_nilfs; 268 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
269 struct nilfs_super_block **sbp = nilfs->ns_sbp; 269 struct nilfs_super_block **sbp = nilfs->ns_sbp;
270 270
271 /* nilfs->ns_sem must be locked by the caller. */ 271 /* nilfs->ns_sem must be locked by the caller. */
@@ -275,7 +275,7 @@ struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi,
275 memcpy(sbp[0], sbp[1], nilfs->ns_sbsize); 275 memcpy(sbp[0], sbp[1], nilfs->ns_sbsize);
276 } else { 276 } else {
277 printk(KERN_CRIT "NILFS: superblock broke on dev %s\n", 277 printk(KERN_CRIT "NILFS: superblock broke on dev %s\n",
278 sbi->s_super->s_id); 278 sb->s_id);
279 return NULL; 279 return NULL;
280 } 280 }
281 } else if (sbp[1] && 281 } else if (sbp[1] &&
@@ -289,9 +289,9 @@ struct nilfs_super_block **nilfs_prepare_super(struct nilfs_sb_info *sbi,
289 return sbp; 289 return sbp;
290} 290}
291 291
292int nilfs_commit_super(struct nilfs_sb_info *sbi, int flag) 292int nilfs_commit_super(struct super_block *sb, int flag)
293{ 293{
294 struct the_nilfs *nilfs = sbi->s_nilfs; 294 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
295 struct nilfs_super_block **sbp = nilfs->ns_sbp; 295 struct nilfs_super_block **sbp = nilfs->ns_sbp;
296 time_t t; 296 time_t t;
297 297
@@ -311,27 +311,28 @@ int nilfs_commit_super(struct nilfs_sb_info *sbi, int flag)
311 nilfs->ns_sbsize)); 311 nilfs->ns_sbsize));
312 } 312 }
313 clear_nilfs_sb_dirty(nilfs); 313 clear_nilfs_sb_dirty(nilfs);
314 return nilfs_sync_super(sbi, flag); 314 return nilfs_sync_super(sb, flag);
315} 315}
316 316
317/** 317/**
318 * nilfs_cleanup_super() - write filesystem state for cleanup 318 * nilfs_cleanup_super() - write filesystem state for cleanup
319 * @sbi: nilfs_sb_info to be unmounted or degraded to read-only 319 * @sb: super block instance to be unmounted or degraded to read-only
320 * 320 *
321 * This function restores state flags in the on-disk super block. 321 * This function restores state flags in the on-disk super block.
322 * This will set "clean" flag (i.e. NILFS_VALID_FS) unless the 322 * This will set "clean" flag (i.e. NILFS_VALID_FS) unless the
323 * filesystem was not clean previously. 323 * filesystem was not clean previously.
324 */ 324 */
325int nilfs_cleanup_super(struct nilfs_sb_info *sbi) 325int nilfs_cleanup_super(struct super_block *sb)
326{ 326{
327 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
327 struct nilfs_super_block **sbp; 328 struct nilfs_super_block **sbp;
328 int flag = NILFS_SB_COMMIT; 329 int flag = NILFS_SB_COMMIT;
329 int ret = -EIO; 330 int ret = -EIO;
330 331
331 sbp = nilfs_prepare_super(sbi, 0); 332 sbp = nilfs_prepare_super(sb, 0);
332 if (sbp) { 333 if (sbp) {
333 sbp[0]->s_state = cpu_to_le16(sbi->s_nilfs->ns_mount_state); 334 sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state);
334 nilfs_set_log_cursor(sbp[0], sbi->s_nilfs); 335 nilfs_set_log_cursor(sbp[0], nilfs);
335 if (sbp[1] && sbp[0]->s_last_cno == sbp[1]->s_last_cno) { 336 if (sbp[1] && sbp[0]->s_last_cno == sbp[1]->s_last_cno) {
336 /* 337 /*
337 * make the "clean" flag also to the opposite 338 * make the "clean" flag also to the opposite
@@ -341,7 +342,7 @@ int nilfs_cleanup_super(struct nilfs_sb_info *sbi)
341 sbp[1]->s_state = sbp[0]->s_state; 342 sbp[1]->s_state = sbp[0]->s_state;
342 flag = NILFS_SB_COMMIT_ALL; 343 flag = NILFS_SB_COMMIT_ALL;
343 } 344 }
344 ret = nilfs_commit_super(sbi, flag); 345 ret = nilfs_commit_super(sb, flag);
345 } 346 }
346 return ret; 347 return ret;
347} 348}
@@ -351,11 +352,11 @@ static void nilfs_put_super(struct super_block *sb)
351 struct nilfs_sb_info *sbi = NILFS_SB(sb); 352 struct nilfs_sb_info *sbi = NILFS_SB(sb);
352 struct the_nilfs *nilfs = sbi->s_nilfs; 353 struct the_nilfs *nilfs = sbi->s_nilfs;
353 354
354 nilfs_detach_segment_constructor(sbi); 355 nilfs_detach_log_writer(sb);
355 356
356 if (!(sb->s_flags & MS_RDONLY)) { 357 if (!(sb->s_flags & MS_RDONLY)) {
357 down_write(&nilfs->ns_sem); 358 down_write(&nilfs->ns_sem);
358 nilfs_cleanup_super(sbi); 359 nilfs_cleanup_super(sb);
359 up_write(&nilfs->ns_sem); 360 up_write(&nilfs->ns_sem);
360 } 361 }
361 362
@@ -371,8 +372,7 @@ static void nilfs_put_super(struct super_block *sb)
371 372
372static int nilfs_sync_fs(struct super_block *sb, int wait) 373static int nilfs_sync_fs(struct super_block *sb, int wait)
373{ 374{
374 struct nilfs_sb_info *sbi = NILFS_SB(sb); 375 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
375 struct the_nilfs *nilfs = sbi->s_nilfs;
376 struct nilfs_super_block **sbp; 376 struct nilfs_super_block **sbp;
377 int err = 0; 377 int err = 0;
378 378
@@ -382,10 +382,10 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
382 382
383 down_write(&nilfs->ns_sem); 383 down_write(&nilfs->ns_sem);
384 if (nilfs_sb_dirty(nilfs)) { 384 if (nilfs_sb_dirty(nilfs)) {
385 sbp = nilfs_prepare_super(sbi, nilfs_sb_will_flip(nilfs)); 385 sbp = nilfs_prepare_super(sb, nilfs_sb_will_flip(nilfs));
386 if (likely(sbp)) { 386 if (likely(sbp)) {
387 nilfs_set_log_cursor(sbp[0], nilfs); 387 nilfs_set_log_cursor(sbp[0], nilfs);
388 nilfs_commit_super(sbi, NILFS_SB_COMMIT); 388 nilfs_commit_super(sb, NILFS_SB_COMMIT);
389 } 389 }
390 } 390 }
391 up_write(&nilfs->ns_sem); 391 up_write(&nilfs->ns_sem);
@@ -393,10 +393,10 @@ static int nilfs_sync_fs(struct super_block *sb, int wait)
393 return err; 393 return err;
394} 394}
395 395
396int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt, 396int nilfs_attach_checkpoint(struct super_block *sb, __u64 cno, int curr_mnt,
397 struct nilfs_root **rootp) 397 struct nilfs_root **rootp)
398{ 398{
399 struct the_nilfs *nilfs = sbi->s_nilfs; 399 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
400 struct nilfs_root *root; 400 struct nilfs_root *root;
401 struct nilfs_checkpoint *raw_cp; 401 struct nilfs_checkpoint *raw_cp;
402 struct buffer_head *bh_cp; 402 struct buffer_head *bh_cp;
@@ -425,7 +425,7 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt,
425 goto failed; 425 goto failed;
426 } 426 }
427 427
428 err = nilfs_ifile_read(sbi->s_super, root, nilfs->ns_inode_size, 428 err = nilfs_ifile_read(sb, root, nilfs->ns_inode_size,
429 &raw_cp->cp_ifile_inode, &root->ifile); 429 &raw_cp->cp_ifile_inode, &root->ifile);
430 if (err) 430 if (err)
431 goto failed_bh; 431 goto failed_bh;
@@ -449,8 +449,7 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno, int curr_mnt,
449 449
450static int nilfs_freeze(struct super_block *sb) 450static int nilfs_freeze(struct super_block *sb)
451{ 451{
452 struct nilfs_sb_info *sbi = NILFS_SB(sb); 452 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
453 struct the_nilfs *nilfs = sbi->s_nilfs;
454 int err; 453 int err;
455 454
456 if (sb->s_flags & MS_RDONLY) 455 if (sb->s_flags & MS_RDONLY)
@@ -458,21 +457,20 @@ static int nilfs_freeze(struct super_block *sb)
458 457
459 /* Mark super block clean */ 458 /* Mark super block clean */
460 down_write(&nilfs->ns_sem); 459 down_write(&nilfs->ns_sem);
461 err = nilfs_cleanup_super(sbi); 460 err = nilfs_cleanup_super(sb);
462 up_write(&nilfs->ns_sem); 461 up_write(&nilfs->ns_sem);
463 return err; 462 return err;
464} 463}
465 464
466static int nilfs_unfreeze(struct super_block *sb) 465static int nilfs_unfreeze(struct super_block *sb)
467{ 466{
468 struct nilfs_sb_info *sbi = NILFS_SB(sb); 467 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
469 struct the_nilfs *nilfs = sbi->s_nilfs;
470 468
471 if (sb->s_flags & MS_RDONLY) 469 if (sb->s_flags & MS_RDONLY)
472 return 0; 470 return 0;
473 471
474 down_write(&nilfs->ns_sem); 472 down_write(&nilfs->ns_sem);
475 nilfs_setup_super(sbi, false); 473 nilfs_setup_super(sb, false);
476 up_write(&nilfs->ns_sem); 474 up_write(&nilfs->ns_sem);
477 return 0; 475 return 0;
478} 476}
@@ -668,15 +666,15 @@ nilfs_set_default_options(struct super_block *sb,
668 NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER; 666 NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER;
669} 667}
670 668
671static int nilfs_setup_super(struct nilfs_sb_info *sbi, int is_mount) 669static int nilfs_setup_super(struct super_block *sb, int is_mount)
672{ 670{
673 struct the_nilfs *nilfs = sbi->s_nilfs; 671 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
674 struct nilfs_super_block **sbp; 672 struct nilfs_super_block **sbp;
675 int max_mnt_count; 673 int max_mnt_count;
676 int mnt_count; 674 int mnt_count;
677 675
678 /* nilfs->ns_sem must be locked by the caller. */ 676 /* nilfs->ns_sem must be locked by the caller. */
679 sbp = nilfs_prepare_super(sbi, 0); 677 sbp = nilfs_prepare_super(sb, 0);
680 if (!sbp) 678 if (!sbp)
681 return -EIO; 679 return -EIO;
682 680
@@ -707,7 +705,7 @@ skip_mount_setup:
707 /* synchronize sbp[1] with sbp[0] */ 705 /* synchronize sbp[1] with sbp[0] */
708 if (sbp[1]) 706 if (sbp[1])
709 memcpy(sbp[1], sbp[0], nilfs->ns_sbsize); 707 memcpy(sbp[1], sbp[0], nilfs->ns_sbsize);
710 return nilfs_commit_super(sbi, NILFS_SB_COMMIT_ALL); 708 return nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL);
711} 709}
712 710
713struct nilfs_super_block *nilfs_read_super_block(struct super_block *sb, 711struct nilfs_super_block *nilfs_read_super_block(struct super_block *sb,
@@ -841,7 +839,7 @@ static int nilfs_attach_snapshot(struct super_block *s, __u64 cno,
841 goto out; 839 goto out;
842 } 840 }
843 841
844 ret = nilfs_attach_checkpoint(NILFS_SB(s), cno, false, &root); 842 ret = nilfs_attach_checkpoint(s, cno, false, &root);
845 if (ret) { 843 if (ret) {
846 printk(KERN_ERR "NILFS: error loading snapshot " 844 printk(KERN_ERR "NILFS: error loading snapshot "
847 "(checkpoint number=%llu).\n", 845 "(checkpoint number=%llu).\n",
@@ -938,7 +936,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
938 } 936 }
939 sbi->s_nilfs = nilfs; 937 sbi->s_nilfs = nilfs;
940 938
941 err = init_nilfs(nilfs, sbi, (char *)data); 939 err = init_nilfs(nilfs, sb, (char *)data);
942 if (err) 940 if (err)
943 goto failed_nilfs; 941 goto failed_nilfs;
944 942
@@ -950,12 +948,12 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
950 bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info; 948 bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
951 sb->s_bdi = bdi ? : &default_backing_dev_info; 949 sb->s_bdi = bdi ? : &default_backing_dev_info;
952 950
953 err = load_nilfs(nilfs, sbi); 951 err = load_nilfs(nilfs, sb);
954 if (err) 952 if (err)
955 goto failed_nilfs; 953 goto failed_nilfs;
956 954
957 cno = nilfs_last_cno(nilfs); 955 cno = nilfs_last_cno(nilfs);
958 err = nilfs_attach_checkpoint(sbi, cno, true, &fsroot); 956 err = nilfs_attach_checkpoint(sb, cno, true, &fsroot);
959 if (err) { 957 if (err) {
960 printk(KERN_ERR "NILFS: error loading last checkpoint " 958 printk(KERN_ERR "NILFS: error loading last checkpoint "
961 "(checkpoint number=%llu).\n", (unsigned long long)cno); 959 "(checkpoint number=%llu).\n", (unsigned long long)cno);
@@ -963,7 +961,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
963 } 961 }
964 962
965 if (!(sb->s_flags & MS_RDONLY)) { 963 if (!(sb->s_flags & MS_RDONLY)) {
966 err = nilfs_attach_segment_constructor(sbi, fsroot); 964 err = nilfs_attach_log_writer(sb, fsroot);
967 if (err) 965 if (err)
968 goto failed_checkpoint; 966 goto failed_checkpoint;
969 } 967 }
@@ -976,14 +974,14 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
976 974
977 if (!(sb->s_flags & MS_RDONLY)) { 975 if (!(sb->s_flags & MS_RDONLY)) {
978 down_write(&nilfs->ns_sem); 976 down_write(&nilfs->ns_sem);
979 nilfs_setup_super(sbi, true); 977 nilfs_setup_super(sb, true);
980 up_write(&nilfs->ns_sem); 978 up_write(&nilfs->ns_sem);
981 } 979 }
982 980
983 return 0; 981 return 0;
984 982
985 failed_segctor: 983 failed_segctor:
986 nilfs_detach_segment_constructor(sbi); 984 nilfs_detach_log_writer(sb);
987 985
988 failed_checkpoint: 986 failed_checkpoint:
989 nilfs_put_root(fsroot); 987 nilfs_put_root(fsroot);
@@ -1004,8 +1002,7 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)
1004 1002
1005static int nilfs_remount(struct super_block *sb, int *flags, char *data) 1003static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1006{ 1004{
1007 struct nilfs_sb_info *sbi = NILFS_SB(sb); 1005 struct the_nilfs *nilfs = NILFS_SB(sb)->s_nilfs;
1008 struct the_nilfs *nilfs = sbi->s_nilfs;
1009 unsigned long old_sb_flags; 1006 unsigned long old_sb_flags;
1010 unsigned long old_mount_opt; 1007 unsigned long old_mount_opt;
1011 int err; 1008 int err;
@@ -1031,8 +1028,8 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1031 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) 1028 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1032 goto out; 1029 goto out;
1033 if (*flags & MS_RDONLY) { 1030 if (*flags & MS_RDONLY) {
1034 /* Shutting down the segment constructor */ 1031 /* Shutting down log writer */
1035 nilfs_detach_segment_constructor(sbi); 1032 nilfs_detach_log_writer(sb);
1036 sb->s_flags |= MS_RDONLY; 1033 sb->s_flags |= MS_RDONLY;
1037 1034
1038 /* 1035 /*
@@ -1040,7 +1037,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1040 * the RDONLY flag and then mark the partition as valid again. 1037 * the RDONLY flag and then mark the partition as valid again.
1041 */ 1038 */
1042 down_write(&nilfs->ns_sem); 1039 down_write(&nilfs->ns_sem);
1043 nilfs_cleanup_super(sbi); 1040 nilfs_cleanup_super(sb);
1044 up_write(&nilfs->ns_sem); 1041 up_write(&nilfs->ns_sem);
1045 } else { 1042 } else {
1046 __u64 features; 1043 __u64 features;
@@ -1067,12 +1064,12 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
1067 sb->s_flags &= ~MS_RDONLY; 1064 sb->s_flags &= ~MS_RDONLY;
1068 1065
1069 root = NILFS_I(sb->s_root->d_inode)->i_root; 1066 root = NILFS_I(sb->s_root->d_inode)->i_root;
1070 err = nilfs_attach_segment_constructor(sbi, root); 1067 err = nilfs_attach_log_writer(sb, root);
1071 if (err) 1068 if (err)
1072 goto restore_opts; 1069 goto restore_opts;
1073 1070
1074 down_write(&nilfs->ns_sem); 1071 down_write(&nilfs->ns_sem);
1075 nilfs_setup_super(sbi, true); 1072 nilfs_setup_super(sb, true);
1076 up_write(&nilfs->ns_sem); 1073 up_write(&nilfs->ns_sem);
1077 } 1074 }
1078 out: 1075 out:
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index 1bf695e887a7..d2acd1a651f3 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -201,16 +201,16 @@ static int nilfs_store_log_cursor(struct the_nilfs *nilfs,
201/** 201/**
202 * load_nilfs - load and recover the nilfs 202 * load_nilfs - load and recover the nilfs
203 * @nilfs: the_nilfs structure to be released 203 * @nilfs: the_nilfs structure to be released
204 * @sbi: nilfs_sb_info used to recover past segment 204 * @sb: super block isntance used to recover past segment
205 * 205 *
206 * load_nilfs() searches and load the latest super root, 206 * load_nilfs() searches and load the latest super root,
207 * attaches the last segment, and does recovery if needed. 207 * attaches the last segment, and does recovery if needed.
208 * The caller must call this exclusively for simultaneous mounts. 208 * The caller must call this exclusively for simultaneous mounts.
209 */ 209 */
210int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) 210int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb)
211{ 211{
212 struct nilfs_recovery_info ri; 212 struct nilfs_recovery_info ri;
213 unsigned int s_flags = sbi->s_super->s_flags; 213 unsigned int s_flags = sb->s_flags;
214 int really_read_only = bdev_read_only(nilfs->ns_bdev); 214 int really_read_only = bdev_read_only(nilfs->ns_bdev);
215 int valid_fs = nilfs_valid_fs(nilfs); 215 int valid_fs = nilfs_valid_fs(nilfs);
216 int err; 216 int err;
@@ -275,7 +275,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
275 goto scan_error; 275 goto scan_error;
276 } 276 }
277 277
278 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);
279 if (unlikely(err)) { 279 if (unlikely(err)) {
280 printk(KERN_ERR "NILFS: error loading super root.\n"); 280 printk(KERN_ERR "NILFS: error loading super root.\n");
281 goto failed; 281 goto failed;
@@ -308,7 +308,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
308 err = -EROFS; 308 err = -EROFS;
309 goto failed_unload; 309 goto failed_unload;
310 } 310 }
311 sbi->s_super->s_flags &= ~MS_RDONLY; 311 sb->s_flags &= ~MS_RDONLY;
312 } else if (nilfs_test_opt(nilfs, NORECOVERY)) { 312 } else if (nilfs_test_opt(nilfs, NORECOVERY)) {
313 printk(KERN_ERR "NILFS: recovery cancelled because norecovery " 313 printk(KERN_ERR "NILFS: recovery cancelled because norecovery "
314 "option was specified for a read/write mount\n"); 314 "option was specified for a read/write mount\n");
@@ -316,13 +316,13 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
316 goto failed_unload; 316 goto failed_unload;
317 } 317 }
318 318
319 err = nilfs_salvage_orphan_logs(nilfs, sbi, &ri); 319 err = nilfs_salvage_orphan_logs(nilfs, sb, &ri);
320 if (err) 320 if (err)
321 goto failed_unload; 321 goto failed_unload;
322 322
323 down_write(&nilfs->ns_sem); 323 down_write(&nilfs->ns_sem);
324 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */ 324 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */
325 err = nilfs_cleanup_super(sbi); 325 err = nilfs_cleanup_super(sb);
326 up_write(&nilfs->ns_sem); 326 up_write(&nilfs->ns_sem);
327 327
328 if (err) { 328 if (err) {
@@ -334,7 +334,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
334 334
335 skip_recovery: 335 skip_recovery:
336 nilfs_clear_recovery_info(&ri); 336 nilfs_clear_recovery_info(&ri);
337 sbi->s_super->s_flags = s_flags; 337 sb->s_flags = s_flags;
338 return 0; 338 return 0;
339 339
340 scan_error: 340 scan_error:
@@ -348,7 +348,7 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
348 348
349 failed: 349 failed:
350 nilfs_clear_recovery_info(&ri); 350 nilfs_clear_recovery_info(&ri);
351 sbi->s_super->s_flags = s_flags; 351 sb->s_flags = s_flags;
352 return err; 352 return err;
353} 353}
354 354
@@ -526,7 +526,6 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
526/** 526/**
527 * init_nilfs - initialize a NILFS instance. 527 * init_nilfs - initialize a NILFS instance.
528 * @nilfs: the_nilfs structure 528 * @nilfs: the_nilfs structure
529 * @sbi: nilfs_sb_info
530 * @sb: super block 529 * @sb: super block
531 * @data: mount options 530 * @data: mount options
532 * 531 *
@@ -537,9 +536,8 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
537 * 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
538 * code is returned. 537 * code is returned.
539 */ 538 */
540int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data) 539int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data)
541{ 540{
542 struct super_block *sb = sbi->s_super;
543 struct nilfs_super_block *sbp; 541 struct nilfs_super_block *sbp;
544 int blocksize; 542 int blocksize;
545 int err; 543 int err;
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h
index 10521b97ded6..793bd272f9e0 100644
--- a/fs/nilfs2/the_nilfs.h
+++ b/fs/nilfs2/the_nilfs.h
@@ -267,15 +267,14 @@ static inline int nilfs_sb_will_flip(struct the_nilfs *nilfs)
267void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64); 267void nilfs_set_last_segment(struct the_nilfs *, sector_t, u64, __u64);
268struct the_nilfs *alloc_nilfs(struct block_device *bdev); 268struct the_nilfs *alloc_nilfs(struct block_device *bdev);
269void destroy_nilfs(struct the_nilfs *nilfs); 269void destroy_nilfs(struct the_nilfs *nilfs);
270int init_nilfs(struct the_nilfs *, struct nilfs_sb_info *, char *); 270int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data);
271int load_nilfs(struct the_nilfs *, struct nilfs_sb_info *); 271int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb);
272int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t); 272int nilfs_discard_segments(struct the_nilfs *, __u64 *, size_t);
273int nilfs_count_free_blocks(struct the_nilfs *, sector_t *); 273int nilfs_count_free_blocks(struct the_nilfs *, sector_t *);
274struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno); 274struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno);
275struct nilfs_root *nilfs_find_or_create_root(struct the_nilfs *nilfs, 275struct nilfs_root *nilfs_find_or_create_root(struct the_nilfs *nilfs,
276 __u64 cno); 276 __u64 cno);
277void nilfs_put_root(struct nilfs_root *root); 277void nilfs_put_root(struct nilfs_root *root);
278struct nilfs_sb_info *nilfs_find_sbinfo(struct the_nilfs *, int, __u64);
279int nilfs_near_disk_full(struct the_nilfs *); 278int nilfs_near_disk_full(struct the_nilfs *);
280void nilfs_fall_back_super_block(struct the_nilfs *); 279void nilfs_fall_back_super_block(struct the_nilfs *);
281void nilfs_swap_super_block(struct the_nilfs *); 280void nilfs_swap_super_block(struct the_nilfs *);