super.c (6dd4740662405a68bb229ac2b9e0aeaaf2188bf2) super.c (e59399d0102c1813cec48db5cebe1750313f88a0)
1/*
2 * super.c - NILFS module and super block management.
3 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 313 unchanged lines hidden (view full) ---

322 nilfs_detach_segment_constructor(sbi);
323
324 if (!(sb->s_flags & MS_RDONLY)) {
325 down_write(&nilfs->ns_sem);
326 nilfs->ns_sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state);
327 nilfs_commit_super(sbi, 1);
328 up_write(&nilfs->ns_sem);
329 }
1/*
2 * super.c - NILFS module and super block management.
3 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or

--- 313 unchanged lines hidden (view full) ---

322 nilfs_detach_segment_constructor(sbi);
323
324 if (!(sb->s_flags & MS_RDONLY)) {
325 down_write(&nilfs->ns_sem);
326 nilfs->ns_sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state);
327 nilfs_commit_super(sbi, 1);
328 up_write(&nilfs->ns_sem);
329 }
330 down_write(&nilfs->ns_sem);
330 down_write(&nilfs->ns_super_sem);
331 if (nilfs->ns_current == sbi)
332 nilfs->ns_current = NULL;
331 if (nilfs->ns_current == sbi)
332 nilfs->ns_current = NULL;
333 up_write(&nilfs->ns_sem);
333 up_write(&nilfs->ns_super_sem);
334
335 nilfs_detach_checkpoint(sbi);
336 put_nilfs(sbi->s_nilfs);
337 sbi->s_super = NULL;
338 sb->s_fs_info = NULL;
339 nilfs_put_sbinfo(sbi);
340
341 unlock_kernel();

--- 61 unchanged lines hidden (view full) ---

403
404int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno)
405{
406 struct the_nilfs *nilfs = sbi->s_nilfs;
407 struct nilfs_checkpoint *raw_cp;
408 struct buffer_head *bh_cp;
409 int err;
410
334
335 nilfs_detach_checkpoint(sbi);
336 put_nilfs(sbi->s_nilfs);
337 sbi->s_super = NULL;
338 sb->s_fs_info = NULL;
339 nilfs_put_sbinfo(sbi);
340
341 unlock_kernel();

--- 61 unchanged lines hidden (view full) ---

403
404int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno)
405{
406 struct the_nilfs *nilfs = sbi->s_nilfs;
407 struct nilfs_checkpoint *raw_cp;
408 struct buffer_head *bh_cp;
409 int err;
410
411 down_write(&nilfs->ns_sem);
411 down_write(&nilfs->ns_super_sem);
412 list_add(&sbi->s_list, &nilfs->ns_supers);
412 list_add(&sbi->s_list, &nilfs->ns_supers);
413 up_write(&nilfs->ns_sem);
413 up_write(&nilfs->ns_super_sem);
414
415 sbi->s_ifile = nilfs_mdt_new(
416 nilfs, sbi->s_super, NILFS_IFILE_INO, NILFS_IFILE_GFP);
417 if (!sbi->s_ifile)
418 return -ENOMEM;
419
420 err = nilfs_palloc_init_blockgroup(sbi->s_ifile, nilfs->ns_inode_size);
421 if (unlikely(err))

--- 21 unchanged lines hidden (view full) ---

443 return 0;
444
445 failed_bh:
446 nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, cno, bh_cp);
447 failed:
448 nilfs_mdt_destroy(sbi->s_ifile);
449 sbi->s_ifile = NULL;
450
414
415 sbi->s_ifile = nilfs_mdt_new(
416 nilfs, sbi->s_super, NILFS_IFILE_INO, NILFS_IFILE_GFP);
417 if (!sbi->s_ifile)
418 return -ENOMEM;
419
420 err = nilfs_palloc_init_blockgroup(sbi->s_ifile, nilfs->ns_inode_size);
421 if (unlikely(err))

--- 21 unchanged lines hidden (view full) ---

443 return 0;
444
445 failed_bh:
446 nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, cno, bh_cp);
447 failed:
448 nilfs_mdt_destroy(sbi->s_ifile);
449 sbi->s_ifile = NULL;
450
451 down_write(&nilfs->ns_sem);
451 down_write(&nilfs->ns_super_sem);
452 list_del_init(&sbi->s_list);
452 list_del_init(&sbi->s_list);
453 up_write(&nilfs->ns_sem);
453 up_write(&nilfs->ns_super_sem);
454
455 return err;
456}
457
458void nilfs_detach_checkpoint(struct nilfs_sb_info *sbi)
459{
460 struct the_nilfs *nilfs = sbi->s_nilfs;
461
462 nilfs_mdt_clear(sbi->s_ifile);
463 nilfs_mdt_destroy(sbi->s_ifile);
464 sbi->s_ifile = NULL;
454
455 return err;
456}
457
458void nilfs_detach_checkpoint(struct nilfs_sb_info *sbi)
459{
460 struct the_nilfs *nilfs = sbi->s_nilfs;
461
462 nilfs_mdt_clear(sbi->s_ifile);
463 nilfs_mdt_destroy(sbi->s_ifile);
464 sbi->s_ifile = NULL;
465 down_write(&nilfs->ns_sem);
465 down_write(&nilfs->ns_super_sem);
466 list_del_init(&sbi->s_list);
466 list_del_init(&sbi->s_list);
467 up_write(&nilfs->ns_sem);
467 up_write(&nilfs->ns_super_sem);
468}
469
470static int nilfs_mark_recovery_complete(struct nilfs_sb_info *sbi)
471{
472 struct the_nilfs *nilfs = sbi->s_nilfs;
473 int err = 0;
474
475 down_write(&nilfs->ns_sem);

--- 402 unchanged lines hidden (view full) ---

878 }
879
880 err = nilfs_mark_recovery_complete(sbi);
881 if (unlikely(err)) {
882 printk(KERN_ERR "NILFS: recovery failed.\n");
883 goto failed_root;
884 }
885
468}
469
470static int nilfs_mark_recovery_complete(struct nilfs_sb_info *sbi)
471{
472 struct the_nilfs *nilfs = sbi->s_nilfs;
473 int err = 0;
474
475 down_write(&nilfs->ns_sem);

--- 402 unchanged lines hidden (view full) ---

878 }
879
880 err = nilfs_mark_recovery_complete(sbi);
881 if (unlikely(err)) {
882 printk(KERN_ERR "NILFS: recovery failed.\n");
883 goto failed_root;
884 }
885
886 down_write(&nilfs->ns_sem);
886 down_write(&nilfs->ns_super_sem);
887 if (!nilfs_test_opt(sbi, SNAPSHOT))
888 nilfs->ns_current = sbi;
887 if (!nilfs_test_opt(sbi, SNAPSHOT))
888 nilfs->ns_current = sbi;
889 up_write(&nilfs->ns_sem);
889 up_write(&nilfs->ns_super_sem);
890
891 return 0;
892
893 failed_root:
894 dput(sb->s_root);
895 sb->s_root = NULL;
896
897 failed_segctor:

--- 15 unchanged lines hidden (view full) ---

913 struct nilfs_super_block *sbp;
914 struct the_nilfs *nilfs = sbi->s_nilfs;
915 unsigned long old_sb_flags;
916 struct nilfs_mount_options old_opts;
917 int err;
918
919 lock_kernel();
920
890
891 return 0;
892
893 failed_root:
894 dput(sb->s_root);
895 sb->s_root = NULL;
896
897 failed_segctor:

--- 15 unchanged lines hidden (view full) ---

913 struct nilfs_super_block *sbp;
914 struct the_nilfs *nilfs = sbi->s_nilfs;
915 unsigned long old_sb_flags;
916 struct nilfs_mount_options old_opts;
917 int err;
918
919 lock_kernel();
920
921 down_write(&nilfs->ns_super_sem);
921 old_sb_flags = sb->s_flags;
922 old_opts.mount_opt = sbi->s_mount_opt;
923 old_opts.snapshot_cno = sbi->s_snapshot_cno;
924
925 if (!parse_options(data, sb)) {
926 err = -EINVAL;
927 goto restore_opts;
928 }

--- 31 unchanged lines hidden (view full) ---

960 nilfs_commit_super(sbi, 1);
961 up_write(&nilfs->ns_sem);
962 } else {
963 /*
964 * Mounting a RDONLY partition read-write, so reread and
965 * store the current valid flag. (It may have been changed
966 * by fsck since we originally mounted the partition.)
967 */
922 old_sb_flags = sb->s_flags;
923 old_opts.mount_opt = sbi->s_mount_opt;
924 old_opts.snapshot_cno = sbi->s_snapshot_cno;
925
926 if (!parse_options(data, sb)) {
927 err = -EINVAL;
928 goto restore_opts;
929 }

--- 31 unchanged lines hidden (view full) ---

961 nilfs_commit_super(sbi, 1);
962 up_write(&nilfs->ns_sem);
963 } else {
964 /*
965 * Mounting a RDONLY partition read-write, so reread and
966 * store the current valid flag. (It may have been changed
967 * by fsck since we originally mounted the partition.)
968 */
968 down(&sb->s_bdev->bd_mount_sem);
969 down_read(&nilfs->ns_sem);
970 if (nilfs->ns_current && nilfs->ns_current != sbi) {
971 printk(KERN_WARNING "NILFS (device %s): couldn't "
972 "remount because an RW-mount exists.\n",
973 sb->s_id);
969 if (nilfs->ns_current && nilfs->ns_current != sbi) {
970 printk(KERN_WARNING "NILFS (device %s): couldn't "
971 "remount because an RW-mount exists.\n",
972 sb->s_id);
974 up_read(&nilfs->ns_sem);
975 err = -EBUSY;
973 err = -EBUSY;
976 goto rw_remount_failed;
974 goto restore_opts;
977 }
975 }
978 up_read(&nilfs->ns_sem);
979 if (sbi->s_snapshot_cno != nilfs_last_cno(nilfs)) {
980 printk(KERN_WARNING "NILFS (device %s): couldn't "
981 "remount because the current RO-mount is not "
982 "the latest one.\n",
983 sb->s_id);
984 err = -EINVAL;
976 if (sbi->s_snapshot_cno != nilfs_last_cno(nilfs)) {
977 printk(KERN_WARNING "NILFS (device %s): couldn't "
978 "remount because the current RO-mount is not "
979 "the latest one.\n",
980 sb->s_id);
981 err = -EINVAL;
985 goto rw_remount_failed;
982 goto restore_opts;
986 }
987 sb->s_flags &= ~MS_RDONLY;
988 nilfs_clear_opt(sbi, SNAPSHOT);
989 sbi->s_snapshot_cno = 0;
990
991 err = nilfs_attach_segment_constructor(sbi);
992 if (err)
983 }
984 sb->s_flags &= ~MS_RDONLY;
985 nilfs_clear_opt(sbi, SNAPSHOT);
986 sbi->s_snapshot_cno = 0;
987
988 err = nilfs_attach_segment_constructor(sbi);
989 if (err)
993 goto rw_remount_failed;
990 goto restore_opts;
994
995 down_write(&nilfs->ns_sem);
996 nilfs_setup_super(sbi);
991
992 down_write(&nilfs->ns_sem);
993 nilfs_setup_super(sbi);
997 nilfs->ns_current = sbi;
998 up_write(&nilfs->ns_sem);
999
994 up_write(&nilfs->ns_sem);
995
1000 up(&sb->s_bdev->bd_mount_sem);
996 nilfs->ns_current = sbi;
1001 }
1002 out:
997 }
998 out:
999 up_write(&nilfs->ns_super_sem);
1003 unlock_kernel();
1004 return 0;
1005
1000 unlock_kernel();
1001 return 0;
1002
1006 rw_remount_failed:
1007 up(&sb->s_bdev->bd_mount_sem);
1008 restore_opts:
1009 sb->s_flags = old_sb_flags;
1010 sbi->s_mount_opt = old_opts.mount_opt;
1011 sbi->s_snapshot_cno = old_opts.snapshot_cno;
1003 restore_opts:
1004 sb->s_flags = old_sb_flags;
1005 sbi->s_mount_opt = old_opts.mount_opt;
1006 sbi->s_snapshot_cno = old_opts.snapshot_cno;
1007 up_write(&nilfs->ns_super_sem);
1012 unlock_kernel();
1013 return err;
1014}
1015
1016struct nilfs_super_data {
1017 struct block_device *bdev;
1018 struct nilfs_sb_info *sbi;
1019 __u64 cno;

--- 93 unchanged lines hidden (view full) ---

1113
1114 if (!sd.cno) {
1115 /*
1116 * Check if an exclusive mount exists or not.
1117 * Snapshot mounts coexist with a current mount
1118 * (i.e. rw-mount or ro-mount), whereas rw-mount and
1119 * ro-mount are mutually exclusive.
1120 */
1008 unlock_kernel();
1009 return err;
1010}
1011
1012struct nilfs_super_data {
1013 struct block_device *bdev;
1014 struct nilfs_sb_info *sbi;
1015 __u64 cno;

--- 93 unchanged lines hidden (view full) ---

1109
1110 if (!sd.cno) {
1111 /*
1112 * Check if an exclusive mount exists or not.
1113 * Snapshot mounts coexist with a current mount
1114 * (i.e. rw-mount or ro-mount), whereas rw-mount and
1115 * ro-mount are mutually exclusive.
1116 */
1121 down_read(&nilfs->ns_sem);
1117 down_read(&nilfs->ns_super_sem);
1122 if (nilfs->ns_current &&
1123 ((nilfs->ns_current->s_super->s_flags ^ flags)
1124 & MS_RDONLY)) {
1118 if (nilfs->ns_current &&
1119 ((nilfs->ns_current->s_super->s_flags ^ flags)
1120 & MS_RDONLY)) {
1125 up_read(&nilfs->ns_sem);
1121 up_read(&nilfs->ns_super_sem);
1126 err = -EBUSY;
1127 goto failed_unlock;
1128 }
1122 err = -EBUSY;
1123 goto failed_unlock;
1124 }
1129 up_read(&nilfs->ns_sem);
1125 up_read(&nilfs->ns_super_sem);
1130 }
1131
1132 /*
1133 * Find existing nilfs_sb_info struct
1134 */
1135 sd.sbi = nilfs_find_sbinfo(nilfs, !(flags & MS_RDONLY), sd.cno);
1136
1137 if (!sd.cno)

--- 123 unchanged lines hidden ---
1126 }
1127
1128 /*
1129 * Find existing nilfs_sb_info struct
1130 */
1131 sd.sbi = nilfs_find_sbinfo(nilfs, !(flags & MS_RDONLY), sd.cno);
1132
1133 if (!sd.cno)

--- 123 unchanged lines hidden ---