public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Takashi Sato <t-sato@yk.jp.nec.com>
Subject: [PATCH V3] Allow SysRq emergency thaw to thaw frozen filesystems
Date: Fri, 16 Jan 2009 13:50:19 -0600	[thread overview]
Message-ID: <4970E4FB.7040407@redhat.com> (raw)
In-Reply-To: <4970E087.8020308@redhat.com>

Now that the filesystem freeze operation has been elevated
to the VFS, and is just an ioctl away, some sort of safety net
for unintentionally frozen root filesystems may be in order.

The timeout thaw originally proposed did not get merged, but
perhaps something like this would be useful in emergencies.

For example, freeze /path/to/mountpoint may freeze your
root filesystem if you forgot that you had that unmounted.

I chose 'j' as the last remaining character other than 'h'
which is sort of reserved for help (because help is generated
on any unknown character).

I've tested this on a non-root fs with multiple (nested) freezers,
as well as on a system rendered unresponsive due to a frozen
root fs.

(this version fixes a couple small issues raised by Randy Dunlap)

Thanks,
-Eric

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

Index: linux-2.6/drivers/char/sysrq.c
===================================================================
--- linux-2.6.orig/drivers/char/sysrq.c	2009-01-16 13:24:14.688575212 -0600
+++ linux-2.6/drivers/char/sysrq.c	2009-01-16 13:47:46.169575069 -0600
@@ -346,6 +346,17 @@ static struct sysrq_key_op sysrq_moom_op
 	.enable_mask	= SYSRQ_ENABLE_SIGNAL,
 };
 
+static void sysrq_handle_thaw(int key, struct tty_struct *tty)
+{
+	emergency_thaw_all();
+}
+static struct sysrq_key_op sysrq_thaw_op = {
+	.handler	= sysrq_handle_thaw,
+	.help_msg	= "thaw-filesystems(J)",
+	.action_msg	= "Emergency Thaw of all frozen filesystems",
+	.enable_mask	= SYSRQ_ENABLE_SIGNAL,
+};
+
 static void sysrq_handle_kill(int key, struct tty_struct *tty)
 {
 	send_sig_all(SIGKILL);
@@ -396,9 +407,9 @@ static struct sysrq_key_op *sysrq_key_ta
 	&sysrq_moom_op,			/* f */
 	/* g: May be registered by ppc for kgdb */
 	NULL,				/* g */
-	NULL,				/* h */
+	NULL,				/* h - reserved for help */
 	&sysrq_kill_op,			/* i */
-	NULL,				/* j */
+	&sysrq_thaw_op,			/* j */
 	&sysrq_SAK_op,			/* k */
 #ifdef CONFIG_SMP
 	&sysrq_showallcpus_op,		/* l */
Index: linux-2.6/fs/buffer.c
===================================================================
--- linux-2.6.orig/fs/buffer.c	2009-01-16 13:24:15.564575078 -0600
+++ linux-2.6/fs/buffer.c	2009-01-16 13:47:58.518575938 -0600
@@ -258,6 +258,29 @@ struct super_block *freeze_bdev(struct b
 }
 EXPORT_SYMBOL(freeze_bdev);
 
+void do_thaw_all(unsigned long unused)
+{
+	struct super_block *sb;
+	char b[BDEVNAME_SIZE];
+
+	list_for_each_entry(sb, &super_blocks, s_list) {
+		while (sb->s_bdev && !thaw_bdev(sb->s_bdev, sb))
+			printk(KERN_WARNING "Emergency Thaw on %s\n",
+			       bdevname(sb->s_bdev, b));
+	}
+	printk(KERN_WARNING "Emergency Thaw complete\n");
+}
+
+/**
+ * emergency_thaw_all -- forcibly thaw every frozen filesystem
+ *
+ * Used for emergency unfreeze of all filesystems via SysRq
+ */
+void emergency_thaw_all(void)
+{
+	pdflush_operation(do_thaw_all, 0);
+}
+
 /**
  * thaw_bdev  -- unlock filesystem
  * @bdev:	blockdevice to unlock
Index: linux-2.6/include/linux/buffer_head.h
===================================================================
--- linux-2.6.orig/include/linux/buffer_head.h	2009-01-14 15:15:53.320575384 -0600
+++ linux-2.6/include/linux/buffer_head.h	2009-01-16 13:26:35.394575234 -0600
@@ -171,6 +171,7 @@ void __wait_on_buffer(struct buffer_head
 wait_queue_head_t *bh_waitq_head(struct buffer_head *bh);
 int fsync_bdev(struct block_device *);
 struct super_block *freeze_bdev(struct block_device *);
+void emergency_thaw_all(void);
 int thaw_bdev(struct block_device *, struct super_block *);
 int fsync_super(struct super_block *);
 int fsync_no_super(struct block_device *);
Index: linux-2.6/Documentation/sysrq.txt
===================================================================
--- linux-2.6.orig/Documentation/sysrq.txt	2009-01-16 13:24:12.943637511 -0600
+++ linux-2.6/Documentation/sysrq.txt	2009-01-16 13:26:35.436575321 -0600
@@ -81,6 +81,8 @@ On all -  write a character to /proc/sys
 
 'i'     - Send a SIGKILL to all processes, except for init.
 
+'j'	- Forcibly "Just thaw it" - filesystems frozen by the FIFREEZE ioctl.
+
 'k'     - Secure Access Key (SAK) Kills all programs on the current virtual
           console. NOTE: See important comments below in SAK section.
 
@@ -160,6 +162,9 @@ t'E'rm and k'I'll are useful if you have
 are unable to kill any other way, especially if it's spawning other
 processes.
 
+"'J'ust thaw it" is useful if your system becomes unresponsive due to a frozen
+(probably root) filesystem via the FIFREEZE ioctl.
+
 *  Sometimes SysRq seems to get 'stuck' after using it, what can I do?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 That happens to me, also. I've found that tapping shift, alt, and control


  parent reply	other threads:[~2009-01-16 19:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-15  4:06 [PATCH] Allow SysRq emergency sync to thaw frozen filesystems Eric Sandeen
2009-01-16  0:20 ` Andrew Morton
2009-01-16  3:49   ` Eric Sandeen
2009-01-16  3:59     ` Eric Sandeen
2009-01-16 15:33       ` Valdis.Kletnieks
2009-01-16 15:40         ` Eric Sandeen
2009-01-16 16:21     ` Dave Kleikamp
2009-01-16 16:42       ` Dave Kleikamp
2009-01-16  8:48 ` Pavel Machek
2009-01-16 15:17   ` Valdis.Kletnieks
2009-01-16 15:28     ` Eric Sandeen
2009-01-16 15:33     ` Pavel Machek
2009-01-16 15:40     ` Theodore Tso
2009-01-16 15:52       ` Valdis.Kletnieks
2009-01-16 16:08       ` Eric Sandeen
2009-01-16 19:31 ` [PATCH V2] Allow SysRq emergency thaw " Eric Sandeen
2009-01-16 19:38   ` Randy Dunlap
2009-01-16 19:46     ` Eric Sandeen
2009-01-16 19:50   ` Eric Sandeen [this message]
2009-01-30 21:40     ` [PATCH V3] " Andrew Morton
2009-02-02 22:55       ` [PATCH V4] " Eric Sandeen
2009-02-03 11:48         ` Jamie Lokier
2009-02-03 13:31           ` Dave Kleikamp
2009-02-03 21:21           ` Dave Chinner
2009-02-03 22:01         ` Andrew Morton
2009-02-03 22:07           ` Eric Sandeen
2009-02-03 22:21             ` Andrew Morton
2009-02-16 22:01           ` [PATCH V5] " Eric Sandeen

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=4970E4FB.7040407@redhat.com \
    --to=sandeen@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=t-sato@yk.jp.nec.com \
    /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