Linux NILFS development
 help / color / mirror / Atom feed
From: Ryusuke Konishi <ryusuke-sG5X7nlA6pw@public.gmane.org>
To: jan.de.kruyf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: crash
Date: Thu, 11 Feb 2010 14:30:01 +0900 (JST)	[thread overview]
Message-ID: <20100211.143001.184824921.ryusuke@osrg.net> (raw)
In-Reply-To: <ee5afd761002092326k3bb3a74fq7145cdb9925d88d5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Hi,
On Wed, 10 Feb 2010 09:26:46 +0200, Jan de Kruyf wrote:
> Hallo,
> This patch never made it to the module tree:
> 
> from    Ryusuke Konishi <ryusuke-sG5X7nlA6pw@public.gmane.org>
> to    users-JrjvKiOkagjYtjvyW6yDsg@public.gmane.org,
> sandeen-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
> cc    jan.de.kruyf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
> konishi.ryusuke-Zyj7fXuS5i5L9jVzuh4AOg@public.gmane.org
> date    Thu, Nov 19, 2009 at 9:10 PM
> subject    Re: [NILFS users] [PATCH 4/4] nilfs2: add norepair mount option
> 
> 
> Could I apply the original patch without a problem to the latest module tree?
> 
> from    Ryusuke Konishi <ryusuke-sG5X7nlA6pw@public.gmane.org>
> to    users-JrjvKiOkagjYtjvyW6yDsg@public.gmane.org,
> jan.de.kruyf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> date    Sat, Nov 7, 2009 at 9:28 PM
> subject    Re: [NILFS users] [SPAM] Re: [SPAM] Re: urgent help need!
> disk partition info lost
> 
> Regards,
> 
> Jan de Kruyf.

The patch looks a bit old.

I attached the latest patch against 2.0.18.

Maybe both are safe, but this new one would be better.

Regards,
Ryusuke Konishi

--
diff --git a/fs/nilfs2_fs.h b/fs/nilfs2_fs.h
index ce52040..2e4cbd1 100644
--- a/fs/nilfs2_fs.h
+++ b/fs/nilfs2_fs.h
@@ -151,6 +151,8 @@ struct nilfs_super_root {
 #define NILFS_MOUNT_BARRIER		0x1000  /* Use block barriers */
 #define NILFS_MOUNT_STRICT_ORDER	0x2000  /* Apply strict in-order
 						   semantics also for data */
+#define NILFS_MOUNT_NORECOVERY		0x4000  /* Disable write access during
+						   mount-time recovery */
 
 
 /**
diff --git a/fs/super.c b/fs/super.c
index c9acc9a..d15ede2 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -505,22 +505,6 @@ void nilfs_detach_checkpoint(struct nilfs_sb_info *sbi)
 	nilfs_debug(2, "detached ifile\n");
 }
 
-static int nilfs_mark_recovery_complete(struct nilfs_sb_info *sbi)
-{
-	struct the_nilfs *nilfs = sbi->s_nilfs;
-	int err = 0;
-
-	down_write(&nilfs->ns_sem);
-	if (!(nilfs->ns_mount_state & NILFS_VALID_FS)) {
-		nilfs->ns_mount_state |= NILFS_VALID_FS;
-		err = nilfs_commit_super(sbi, 1);
-		if (likely(!err))
-			printk(KERN_INFO "NILFS: recovery complete.\n");
-	}
-	up_write(&nilfs->ns_sem);
-	return err;
-}
-
 static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
 	struct super_block *sb = dentry->d_sb;
@@ -649,7 +633,7 @@ static struct export_operations nilfs_export_ops = {
 
 enum {
 	Opt_err_cont, Opt_err_panic, Opt_err_ro,
-	Opt_barrier, Opt_snapshot, Opt_order,
+	Opt_barrier, Opt_snapshot, Opt_order, Opt_norecovery,
 	Opt_err,
 };
 
@@ -660,6 +644,7 @@ static match_table_t tokens = {
 	{Opt_barrier, "barrier=%s"},
 	{Opt_snapshot, "cp=%u"},
 	{Opt_order, "order=%s"},
+	{Opt_norecovery, "norecovery"},
 	{Opt_err, NULL}
 };
 
@@ -728,6 +713,9 @@ static int parse_options(char *options, struct super_block *sb)
 			sbi->s_snapshot_cno = option;
 			nilfs_set_opt(sbi, SNAPSHOT);
 			break;
+		case Opt_norecovery:
+			nilfs_set_opt(sbi, NORECOVERY);
+			break;
 		default:
 			printk(KERN_ERR
 			       "NILFS: Unrecognized mount option \"%s\"\n", p);
@@ -753,9 +741,7 @@ static int nilfs_setup_super(struct nilfs_sb_info *sbi)
 	int mnt_count = le16_to_cpu(sbp->s_mnt_count);
 
 	/* nilfs->sem must be locked by the caller. */
-	if (!(nilfs->ns_mount_state & NILFS_VALID_FS)) {
-		printk(KERN_WARNING "NILFS warning: mounting unchecked fs\n");
-	} else if (nilfs->ns_mount_state & NILFS_ERROR_FS) {
+	if (nilfs->ns_mount_state & NILFS_ERROR_FS) {
 		printk(KERN_WARNING
 		       "NILFS warning: mounting fs with errors\n");
 #if 0
@@ -865,11 +851,10 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
 	sb->s_root = NULL;
 	sb->s_time_gran = 1;
 
-	if (!nilfs_loaded(nilfs)) {
-		err = load_nilfs(nilfs, sbi);
-		if (err)
-			goto failed_sbi;
-	}
+	err = load_nilfs(nilfs, sbi);
+	if (err)
+		goto failed_sbi;
+
 	cno = nilfs_last_cno(nilfs);
 
 	if (sb->s_flags & MS_RDONLY) {
@@ -946,12 +931,6 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
 		up_write(&nilfs->ns_sem);
 	}
 
-	err = nilfs_mark_recovery_complete(sbi);
-	if (unlikely(err)) {
-		printk(KERN_ERR "NILFS: recovery failed.\n");
-		goto failed_root;
-	}
-
 	down_write(&nilfs->ns_super_sem);
 	if (!nilfs_test_opt(sbi, SNAPSHOT))
 		nilfs->ns_current = sbi;
@@ -960,10 +939,6 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
 	nilfs_debug(1, "mounted filesystem\n");
 	return 0;
 
- failed_root:
-	dput(sb->s_root);
-	sb->s_root = NULL;
-
  failed_segctor:
 	nilfs_detach_segment_constructor(sbi);
 
@@ -1008,6 +983,14 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
 		goto restore_opts;
 	}
 
+	if (!nilfs_valid_fs(nilfs)) {
+		printk(KERN_WARNING "NILFS (device %s): couldn't "
+		       "remount because the filesystem is in an "
+		       "incomplete recovery state.\n", sb->s_id);
+		err = -EINVAL;
+		goto restore_opts;
+	}
+
 	if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
 		goto out;
 	if (*flags & MS_RDONLY) {
diff --git a/fs/the_nilfs.c b/fs/the_nilfs.c
index 365971b..028f378 100644
--- a/fs/the_nilfs.c
+++ b/fs/the_nilfs.c
@@ -294,29 +294,30 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
 	struct nilfs_recovery_info ri;
 	unsigned int s_flags = sbi->s_super->s_flags;
 	int really_read_only = bdev_read_only(nilfs->ns_bdev);
-	unsigned valid_fs;
-	int err = 0;
-
-	nilfs_init_recovery_info(&ri);
+	int valid_fs = nilfs_valid_fs(nilfs);
+	int err;
 
-	down_write(&nilfs->ns_sem);
-	valid_fs = (nilfs->ns_mount_state & NILFS_VALID_FS);
-	up_write(&nilfs->ns_sem);
+	if (nilfs_loaded(nilfs)) {
+		if (valid_fs ||
+		    ((s_flags & MS_RDONLY) && nilfs_test_opt(sbi, NORECOVERY)))
+			return 0;
+		printk(KERN_ERR "NILFS: the filesystem is in an incomplete "
+		       "recovery state.\n");
+		return -EINVAL;
+	}
 
-	if (!valid_fs && (s_flags & MS_RDONLY)) {
-		printk(KERN_INFO "NILFS: INFO: recovery "
-		       "required for readonly filesystem.\n");
-		if (really_read_only) {
-			printk(KERN_ERR "NILFS: write access "
-			       "unavailable, cannot proceed.\n");
-			err = -EROFS;
-			goto failed;
+	if (!valid_fs) {
+		printk(KERN_WARNING "NILFS warning: mounting unchecked fs\n");
+		if (s_flags & MS_RDONLY) {
+			printk(KERN_INFO "NILFS: INFO: recovery "
+			       "required for readonly filesystem.\n");
+			printk(KERN_INFO "NILFS: write access will "
+			       "be enabled during recovery.\n");
 		}
-		printk(KERN_INFO "NILFS: write access will "
-		       "be enabled during recovery.\n");
-		sbi->s_super->s_flags &= ~MS_RDONLY;
 	}
 
+	nilfs_init_recovery_info(&ri);
+
 	err = nilfs_search_super_root(nilfs, sbi, &ri);
 	if (unlikely(err)) {
 		printk(KERN_ERR "NILFS: error searching super root.\n");
@@ -329,19 +330,56 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
 		goto failed;
 	}
 
-	if (!valid_fs) {
-		err = nilfs_recover_logical_segments(nilfs, sbi, &ri);
-		if (unlikely(err)) {
-			nilfs_mdt_destroy(nilfs->ns_cpfile);
-			nilfs_mdt_destroy(nilfs->ns_sufile);
-			nilfs_mdt_destroy(nilfs->ns_dat);
-			goto failed;
+	if (valid_fs)
+		goto skip_recovery;
+
+	if (s_flags & MS_RDONLY) {
+		if (nilfs_test_opt(sbi, NORECOVERY)) {
+			printk(KERN_INFO "NILFS: norecovery option specified. "
+			       "skipping roll-forward recovery\n");
+			goto skip_recovery;
 		}
-		if (ri.ri_need_recovery == NILFS_RECOVERY_SR_UPDATED)
-			sbi->s_super->s_dirt = 1;
+		if (really_read_only) {
+			printk(KERN_ERR "NILFS: write access "
+			       "unavailable, cannot proceed.\n");
+			err = -EROFS;
+			goto failed_unload;
+		}
+		sbi->s_super->s_flags &= ~MS_RDONLY;
+	} else if (nilfs_test_opt(sbi, NORECOVERY)) {
+		printk(KERN_ERR "NILFS: recovery cancelled because norecovery "
+		       "option was specified for a read/write mount\n");
+		err = -EINVAL;
+		goto failed_unload;
 	}
 
+	err = nilfs_recover_logical_segments(nilfs, sbi, &ri);
+	if (err)
+		goto failed_unload;
+
+	down_write(&nilfs->ns_sem);
+	nilfs->ns_mount_state |= NILFS_VALID_FS;
+	nilfs->ns_sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state);
+	err = nilfs_commit_super(sbi, 1);
+	up_write(&nilfs->ns_sem);
+
+	if (err) {
+		printk(KERN_ERR "NILFS: failed to update super block. "
+		       "recovery unfinished.\n");
+		goto failed_unload;
+	}
+	printk(KERN_INFO "NILFS: recovery complete.\n");
+
+ skip_recovery:
 	set_nilfs_loaded(nilfs);
+	nilfs_clear_recovery_info(&ri);
+	sbi->s_super->s_flags = s_flags;
+	return 0;
+
+ failed_unload:
+	nilfs_mdt_destroy(nilfs->ns_cpfile);
+	nilfs_mdt_destroy(nilfs->ns_sufile);
+	nilfs_mdt_destroy(nilfs->ns_dat);
 
  failed:
 	nilfs_clear_recovery_info(&ri);
diff --git a/fs/the_nilfs.h b/fs/the_nilfs.h
index fa3a1df..25c24a0 100644
--- a/fs/the_nilfs.h
+++ b/fs/the_nilfs.h
@@ -242,6 +242,16 @@ static inline void nilfs_put_sbinfo(struct nilfs_sb_info *sbi)
 		kfree(sbi);
 }
 
+static inline int nilfs_valid_fs(struct the_nilfs *nilfs)
+{
+	unsigned valid_fs;
+
+	down_read(&nilfs->ns_sem);
+	valid_fs = (nilfs->ns_mount_state & NILFS_VALID_FS);
+	up_read(&nilfs->ns_sem);
+	return valid_fs;
+}
+
 static inline void
 nilfs_get_segment_range(struct the_nilfs *nilfs, __u64 segnum,
 			sector_t *seg_start, sector_t *seg_end)
diff --git a/nilfs2.txt b/nilfs2.txt
index dbbda00..906b505 100644
--- a/nilfs2.txt
+++ b/nilfs2.txt
@@ -71,6 +71,10 @@ order=strict		Apply strict in-order semantics that preserves sequence
 			blocks.  That means, it is guaranteed that no
 			overtaking of events occurs in the recovered file
 			system after a crash.
+norecovery		Disable recovery of the filesystem on mount.
+			This disables every write access on the device for
+			read-only mounts or snapshots.  This option will fail
+			for r/w mounts on an unclean volume.
 
 NILFS2 usage
 ============
--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2010-02-11  5:30 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-10  0:59 crash Ryusuke Konishi
     [not found] ` <201002100059.AA01340-ZdTO5nnmHvkOizVVqyxoihMFgDP4sedm@public.gmane.org>
2010-02-10  4:07   ` crash Ryusuke Konishi
     [not found]     ` <ee5afd761002092314i1ba1ec66ie6fe7d0f22d6927e@mail.gmail.com>
     [not found]       ` <ee5afd761002092314i1ba1ec66ie6fe7d0f22d6927e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-10  7:26         ` crash Jan de Kruyf
     [not found]           ` <ee5afd761002092326k3bb3a74fq7145cdb9925d88d5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-11  5:30             ` Ryusuke Konishi [this message]
     [not found]               ` <20100211.143001.184824921.ryusuke-sG5X7nlA6pw@public.gmane.org>
2010-02-11 17:43                 ` crash Jan de Kruyf
     [not found]                   ` <ee5afd761002110943y1ca061bdi610de2f1a5df3c32-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-14  7:34                     ` crash Ryusuke Konishi
     [not found] <ee5afd761002182235r1fe20b0kc7ef7082a5a907e3@mail.gmail.com>
     [not found] ` <ee5afd761002182235r1fe20b0kc7ef7082a5a907e3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-02-20 13:38   ` crash Ryusuke Konishi
  -- strict thread matches above, loose matches on Subject: below --
2009-07-23 12:55 Crash Andrea Gelmini
     [not found] ` <9cdbb57f0907230555k768383c2ld1690d31cc6fff83-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-23 16:12   ` Crash Ryusuke Konishi
     [not found]     ` <20090724.011249.110726474.ryusuke-sG5X7nlA6pw@public.gmane.org>
2009-07-23 21:02       ` Crash Andrea Gelmini
     [not found]         ` <9cdbb57f0907231402i1a92cb4qfe5a9d81346a4665-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-23 21:20           ` Crash Andrea Gelmini
     [not found]             ` <9cdbb57f0907231420y4122d649y69fee2273a05b4cc-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-27  0:40               ` Crash Jiro SEKIBA
     [not found]                 ` <873a8jhsbd.wl%jir-27yqGEOhnJbQT0dZR+AlfA@public.gmane.org>
2009-07-27  7:58                   ` Crash Andrea Gelmini
2009-07-29  2:49                   ` Crash Jiro SEKIBA
     [not found]                     ` <87eis0mcev.wl%jir-27yqGEOhnJbQT0dZR+AlfA@public.gmane.org>
2009-07-29  3:46                       ` Crash Ryusuke Konishi
     [not found]                         ` <20090729.124638.38314632.ryusuke-sG5X7nlA6pw@public.gmane.org>
2009-07-29  4:40                           ` Crash Jiro SEKIBA
     [not found]                             ` <874osw14pz.wl%jir-27yqGEOhnJbQT0dZR+AlfA@public.gmane.org>
2009-07-29  5:08                               ` Crash Ryusuke Konishi
2009-08-01 13:39                   ` Crash Andrea Gelmini
     [not found]                     ` <9cdbb57f0908010639l26c26182ma121b0d7672003e0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-08-02  7:58                       ` Crash Jiro SEKIBA
2009-07-24  8:58           ` Crash Reinoud Zandijk
     [not found]             ` <20090724085803.GA23256-5cYspOl2ggRz6xQTk39kMVfVdRo2wo/d@public.gmane.org>
2009-07-24  9:47               ` Crash Andrea Gelmini
     [not found]                 ` <9cdbb57f0907240247n5ffd6f81yaee39eb386516c25-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-07-24 10:02                   ` Crash Reinoud Zandijk
2009-07-24 10:47                   ` Crash Ryusuke Konishi
2009-07-24 10:46               ` Crash Ryusuke Konishi
     [not found]                 ` <20090724.194617.88653682.ryusuke-sG5X7nlA6pw@public.gmane.org>
2009-07-24 11:13                   ` Crash Reinoud Zandijk
     [not found]                     ` <20090724111333.GE23256-5cYspOl2ggRz6xQTk39kMVfVdRo2wo/d@public.gmane.org>
2009-07-27  7:45                       ` Crash Ryusuke Konishi
2009-07-29  2:46           ` Crash Ryusuke Konishi
     [not found]             ` <20090729.114604.56042421.ryusuke-sG5X7nlA6pw@public.gmane.org>
2009-08-01 13:36               ` Crash Andrea Gelmini
     [not found]                 ` <9cdbb57f0908010636u7296da29p61df192dc35d0d12-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-08-01 13:56                   ` Crash Ryusuke Konishi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100211.143001.184824921.ryusuke@osrg.net \
    --to=ryusuke-sg5x7nla6pw@public.gmane.org \
    --cc=jan.de.kruyf-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-nilfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox