Commit 0234576d041b9b2cc7043691ea61d2c2ca597aaa

Authored by Ryusuke Konishi
1 parent a057d2c011

nilfs2: add norecovery mount option

This adds "norecovery" mount option which disables temporal write
access to read-only mounts or snapshots during mount/recovery.
Without this option, write access will be even performed for those
types of mounts; the temporal write access is needed to mount root
file system read-only after an unclean shutdown.

This option will be helpful when user wants to prevent any write
access to the device.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Cc: Eric Sandeen <sandeen@redhat.com>

Showing 4 changed files with 39 additions and 3 deletions Side-by-side Diff

Documentation/filesystems/nilfs2.txt
... ... @@ -70,6 +70,10 @@
70 70 blocks. That means, it is guaranteed that no
71 71 overtaking of events occurs in the recovered file
72 72 system after a crash.
  73 +norecovery Disable recovery of the filesystem on mount.
  74 + This disables every write access on the device for
  75 + read-only mounts or snapshots. This option will fail
  76 + for r/w mounts on an unclean volume.
73 77  
74 78 NILFS2 usage
75 79 ============
... ... @@ -479,6 +479,8 @@
479 479 seq_printf(seq, ",errors=panic");
480 480 if (nilfs_test_opt(sbi, STRICT_ORDER))
481 481 seq_printf(seq, ",order=strict");
  482 + if (nilfs_test_opt(sbi, NORECOVERY))
  483 + seq_printf(seq, ",norecovery");
482 484  
483 485 return 0;
484 486 }
... ... @@ -547,7 +549,7 @@
547 549  
548 550 enum {
549 551 Opt_err_cont, Opt_err_panic, Opt_err_ro,
550   - Opt_nobarrier, Opt_snapshot, Opt_order,
  552 + Opt_nobarrier, Opt_snapshot, Opt_order, Opt_norecovery,
551 553 Opt_err,
552 554 };
553 555  
... ... @@ -558,6 +560,7 @@
558 560 {Opt_nobarrier, "nobarrier"},
559 561 {Opt_snapshot, "cp=%u"},
560 562 {Opt_order, "order=%s"},
  563 + {Opt_norecovery, "norecovery"},
561 564 {Opt_err, NULL}
562 565 };
563 566  
... ... @@ -608,6 +611,9 @@
608 611 sbi->s_snapshot_cno = option;
609 612 nilfs_set_opt(sbi, SNAPSHOT);
610 613 break;
  614 + case Opt_norecovery:
  615 + nilfs_set_opt(sbi, NORECOVERY);
  616 + break;
611 617 default:
612 618 printk(KERN_ERR
613 619 "NILFS: Unrecognized mount option \"%s\"\n", p);
... ... @@ -859,6 +865,14 @@
859 865 printk(KERN_WARNING "NILFS (device %s): couldn't "
860 866 "remount to a different snapshot. \n",
861 867 sb->s_id);
  868 + err = -EINVAL;
  869 + goto restore_opts;
  870 + }
  871 +
  872 + if (!nilfs_valid_fs(nilfs)) {
  873 + printk(KERN_WARNING "NILFS (device %s): couldn't "
  874 + "remount because the filesystem is in an "
  875 + "incomplete recovery state.\n", sb->s_id);
862 876 err = -EINVAL;
863 877 goto restore_opts;
864 878 }
fs/nilfs2/the_nilfs.c
... ... @@ -264,8 +264,14 @@
264 264 int valid_fs = nilfs_valid_fs(nilfs);
265 265 int err;
266 266  
267   - if (nilfs_loaded(nilfs))
268   - return 0;
  267 + if (nilfs_loaded(nilfs)) {
  268 + if (valid_fs ||
  269 + ((s_flags & MS_RDONLY) && nilfs_test_opt(sbi, NORECOVERY)))
  270 + return 0;
  271 + printk(KERN_ERR "NILFS: the filesystem is in an incomplete "
  272 + "recovery state.\n");
  273 + return -EINVAL;
  274 + }
269 275  
270 276 if (!valid_fs) {
271 277 printk(KERN_WARNING "NILFS warning: mounting unchecked fs\n");
... ... @@ -295,6 +301,11 @@
295 301 goto skip_recovery;
296 302  
297 303 if (s_flags & MS_RDONLY) {
  304 + if (nilfs_test_opt(sbi, NORECOVERY)) {
  305 + printk(KERN_INFO "NILFS: norecovery option specified. "
  306 + "skipping roll-forward recovery\n");
  307 + goto skip_recovery;
  308 + }
298 309 if (really_read_only) {
299 310 printk(KERN_ERR "NILFS: write access "
300 311 "unavailable, cannot proceed.\n");
... ... @@ -302,6 +313,11 @@
302 313 goto failed_unload;
303 314 }
304 315 sbi->s_super->s_flags &= ~MS_RDONLY;
  316 + } else if (nilfs_test_opt(sbi, NORECOVERY)) {
  317 + printk(KERN_ERR "NILFS: recovery cancelled because norecovery "
  318 + "option was specified for a read/write mount\n");
  319 + err = -EINVAL;
  320 + goto failed_unload;
305 321 }
306 322  
307 323 err = nilfs_recover_logical_segments(nilfs, sbi, &ri);
include/linux/nilfs2_fs.h
... ... @@ -151,6 +151,8 @@
151 151 #define NILFS_MOUNT_BARRIER 0x1000 /* Use block barriers */
152 152 #define NILFS_MOUNT_STRICT_ORDER 0x2000 /* Apply strict in-order
153 153 semantics also for data */
  154 +#define NILFS_MOUNT_NORECOVERY 0x4000 /* Disable write access during
  155 + mount-time recovery */
154 156  
155 157  
156 158 /**