summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Morton <akpm@digeo.com>2003-05-07 08:15:36 -0700
committerLinus Torvalds <torvalds@home.transmeta.com>2003-05-07 08:15:36 -0700
commitb7bd1dee9cecddb692740a236f14d6769172acbf (patch)
tree10b33d375642914c3a5ece4ef30cbba468fd5db9
parent862fb2829261c21f53e9bcd843c801d4781512a8 (diff)
[PATCH] sysrq-S, sysrq-U cleanups
From: Christoph Hellwig <hch@lst.de> Change sysrq sync/remount from a magic bdflush hook to proper pdflush operations. The sync operation reuses most of the regular sys_sync path now instead of implementing it's own superblock walking and (broken) local disk detection, the remount implementation has been moved to super.c, cleaned up and updated for the last two years locking changes. It also shares some code with the regular remount path now.
-rw-r--r--drivers/char/sysrq.c122
-rw-r--r--fs/buffer.c16
-rw-r--r--fs/namespace.c5
-rw-r--r--fs/super.c49
-rw-r--r--include/linux/fs.h4
-rw-r--r--include/linux/sysrq.h18
-rw-r--r--kernel/panic.c5
-rw-r--r--mm/page-writeback.c2
8 files changed, 70 insertions, 151 deletions
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index afd8b71f8c87..ea238b20a194 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -101,131 +101,19 @@ static void sysrq_handle_reboot(int key, struct pt_regs *pt_regs,
{
machine_restart(NULL);
}
+
static struct sysrq_key_op sysrq_reboot_op = {
.handler = sysrq_handle_reboot,
.help_msg = "reBoot",
.action_msg = "Resetting",
};
-
-
-/* SYNC SYSRQ HANDLERS BLOCK */
-
-/* do_emergency_sync helper function */
-/* Guesses if the device is a local hard drive */
-static int is_local_disk(struct block_device *bdev)
-{
- switch (MAJOR(bdev->bd_dev)) {
- case IDE0_MAJOR:
- case IDE1_MAJOR:
- case IDE2_MAJOR:
- case IDE3_MAJOR:
- case IDE4_MAJOR:
- case IDE5_MAJOR:
- case IDE6_MAJOR:
- case IDE7_MAJOR:
- case IDE8_MAJOR:
- case IDE9_MAJOR:
- case SCSI_DISK0_MAJOR:
- case SCSI_DISK1_MAJOR:
- case SCSI_DISK2_MAJOR:
- case SCSI_DISK3_MAJOR:
- case SCSI_DISK4_MAJOR:
- case SCSI_DISK5_MAJOR:
- case SCSI_DISK6_MAJOR:
- case SCSI_DISK7_MAJOR:
- case XT_DISK_MAJOR:
- return 1;
- default:
- return 0;
- }
-}
-
-/* do_emergency_sync helper function */
-static void go_sync(struct super_block *sb, int remount_flag)
-{
- int orig_loglevel;
- orig_loglevel = console_loglevel;
- console_loglevel = 7;
- printk(KERN_INFO "%sing device %s ... ",
- remount_flag ? "Remount" : "Sync",
- sb->s_id);
-
- if (remount_flag) { /* Remount R/O */
- int ret, flags;
- struct file *file;
-
- if (sb->s_flags & MS_RDONLY) {
- printk("R/O\n");
- return;
- }
-
- file_list_lock();
- list_for_each_entry(file, &sb->s_files, f_list) {
- if (file->f_dentry && file_count(file)
- && S_ISREG(file->f_dentry->d_inode->i_mode))
- file->f_mode &= ~2;
- }
- file_list_unlock();
- DQUOT_OFF(sb);
- fsync_bdev(sb->s_bdev);
- flags = MS_RDONLY;
- if (sb->s_op && sb->s_op->remount_fs) {
- ret = sb->s_op->remount_fs(sb, &flags, NULL);
- if (ret)
- printk("error %d\n", ret);
- else {
- sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK);
- printk("OK\n");
- }
- } else
- printk("nothing to do\n");
- } else { /* Sync only */
- fsync_bdev(sb->s_bdev);
- printk("OK\n");
- }
- console_loglevel = orig_loglevel;
-}
-/*
- * Emergency Sync or Unmount. We cannot do it directly, so we set a special
- * flag and wake up the bdflush kernel thread which immediately calls this function.
- * We process all mounted hard drives first to recover from crashed experimental
- * block devices and malfunctional network filesystems.
- */
-
-int emergency_sync_scheduled;
-
-void do_emergency_sync(void) {
- struct super_block *sb;
- int remount_flag;
- int orig_loglevel;
-
- lock_kernel();
- remount_flag = (emergency_sync_scheduled == EMERG_REMOUNT);
- emergency_sync_scheduled = 0;
-
- list_for_each_entry(sb, &super_blocks, s_list)
- if (sb->s_bdev && is_local_disk(sb->s_bdev))
- go_sync(sb, remount_flag);
-
- list_for_each_entry(sb, &super_blocks, s_list)
- if (sb->s_bdev && !is_local_disk(sb->s_bdev))
- go_sync(sb, remount_flag);
-
- unlock_kernel();
-
- orig_loglevel = console_loglevel;
- console_loglevel = 7;
- printk(KERN_INFO "Done.\n");
- console_loglevel = orig_loglevel;
-}
-
static void sysrq_handle_sync(int key, struct pt_regs *pt_regs,
struct tty_struct *tty)
{
- emergency_sync_scheduled = EMERG_SYNC;
- wakeup_bdflush(0);
+ emergency_sync();
}
+
static struct sysrq_key_op sysrq_sync_op = {
.handler = sysrq_handle_sync,
.help_msg = "Sync",
@@ -235,9 +123,9 @@ static struct sysrq_key_op sysrq_sync_op = {
static void sysrq_handle_mountro(int key, struct pt_regs *pt_regs,
struct tty_struct *tty)
{
- emergency_sync_scheduled = EMERG_REMOUNT;
- wakeup_bdflush(0);
+ emergency_remount();
}
+
static struct sysrq_key_op sysrq_mountro_op = {
.handler = sysrq_handle_mountro,
.help_msg = "Unmount",
diff --git a/fs/buffer.c b/fs/buffer.c
index 5ed6a8e2918f..f380aa531352 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -244,18 +244,28 @@ int fsync_bdev(struct block_device *bdev)
* sync everything. Start out by waking pdflush, because that writes back
* all queues in parallel.
*/
-asmlinkage long sys_sync(void)
+static void do_sync(unsigned long wait)
{
wakeup_bdflush(0);
sync_inodes(0); /* All mappings, inodes and their blockdevs */
DQUOT_SYNC(NULL);
sync_supers(); /* Write the superblocks */
sync_filesystems(0); /* Start syncing the filesystems */
- sync_filesystems(1); /* Waitingly sync the filesystems */
- sync_inodes(1); /* Mappings, inodes and blockdevs, again. */
+ sync_filesystems(wait); /* Waitingly sync the filesystems */
+ sync_inodes(wait); /* Mappings, inodes and blockdevs, again. */
+}
+
+asmlinkage long sys_sync(void)
+{
+ do_sync(1);
return 0;
}
+void emergency_sync(void)
+{
+ pdflush_operation(do_sync, 0);
+}
+
/*
* Generic function to fsync a file.
*
diff --git a/fs/namespace.c b/fs/namespace.c
index 2dc2a5f73976..91cfd2ce3825 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -24,7 +24,6 @@
#include <asm/uaccess.h>
extern struct vfsmount *do_kern_mount(const char *type, int flags, char *name, void *data);
-extern int do_remount_sb(struct super_block *sb, int flags, void * data);
extern int __init init_rootfs(void);
extern int __init fs_subsys_init(void);
@@ -326,7 +325,7 @@ static int do_umount(struct vfsmount *mnt, int flags)
down_write(&sb->s_umount);
if (!(sb->s_flags & MS_RDONLY)) {
lock_kernel();
- retval = do_remount_sb(sb, MS_RDONLY, 0);
+ retval = do_remount_sb(sb, MS_RDONLY, 0, 0);
unlock_kernel();
}
up_write(&sb->s_umount);
@@ -555,7 +554,7 @@ static int do_remount(struct nameidata *nd,int flags,int mnt_flags,void *data)
return -EINVAL;
down_write(&sb->s_umount);
- err = do_remount_sb(sb, flags, data);
+ err = do_remount_sb(sb, flags, data, 0);
if (!err)
nd->mnt->mnt_flags=mnt_flags;
up_write(&sb->s_umount);
diff --git a/fs/super.c b/fs/super.c
index b2a02451eda5..58f90ef3a2b9 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -31,6 +31,7 @@
#include <linux/mount.h>
#include <linux/security.h>
#include <linux/vfs.h>
+#include <linux/writeback.h> /* for the emergency remount stuff */
#include <asm/uaccess.h>
@@ -431,6 +432,18 @@ out:
return err;
}
+static void mark_files_ro(struct super_block *sb)
+{
+ struct file *f;
+
+ file_list_lock();
+ list_for_each_entry(f, &sb->s_files, f_list) {
+ if (S_ISREG(f->f_dentry->d_inode->i_mode) && file_count(f))
+ f->f_mode &= ~FMODE_WRITE;
+ }
+ file_list_unlock();
+}
+
/**
* do_remount_sb - asks filesystem to change mount options.
* @sb: superblock in question
@@ -439,21 +452,25 @@ out:
*
* Alters the mount options of a mounted file system.
*/
-int do_remount_sb(struct super_block *sb, int flags, void *data)
+int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
{
int retval;
if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev))
return -EACCES;
- /*flags |= MS_RDONLY;*/
if (flags & MS_RDONLY)
acct_auto_close(sb);
shrink_dcache_sb(sb);
fsync_super(sb);
+
/* If we are remounting RDONLY, make sure there are no rw files open */
- if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY))
- if (!fs_may_remount_ro(sb))
+ if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) {
+ if (force)
+ mark_files_ro(sb);
+ else if (!fs_may_remount_ro(sb))
return -EBUSY;
+ }
+
if (sb->s_op->remount_fs) {
lock_super(sb);
retval = sb->s_op->remount_fs(sb, &flags, data);
@@ -465,6 +482,28 @@ int do_remount_sb(struct super_block *sb, int flags, void *data)
return 0;
}
+static void do_emergency_remount(unsigned long foo)
+{
+ struct super_block *sb;
+
+ spin_lock(&sb_lock);
+ list_for_each_entry(sb, &super_blocks, s_list) {
+ sb->s_count++;
+ spin_unlock(&sb_lock);
+ down_read(&sb->s_umount);
+ if (sb->s_root && sb->s_bdev && !(sb->s_flags & MS_RDONLY))
+ do_remount_sb(sb, MS_RDONLY, NULL, 1);
+ drop_super(sb);
+ spin_lock(&sb_lock);
+ }
+ spin_unlock(&sb_lock);
+}
+
+void emergency_remount(void)
+{
+ pdflush_operation(do_emergency_remount, 0);
+}
+
/*
* Unnamed block devices are dummy devices used by virtual
* filesystems which don't use real block-devices. -- jrs
@@ -618,7 +657,7 @@ struct super_block *get_sb_single(struct file_system_type *fs_type,
}
s->s_flags |= MS_ACTIVE;
}
- do_remount_sb(s, flags, data);
+ do_remount_sb(s, flags, data, 0);
return s;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b9b2cf5b69e8..370c6f0b4fe3 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1113,6 +1113,10 @@ extern int filemap_flush(struct address_space *);
extern int filemap_fdatawait(struct address_space *);
extern void sync_supers(void);
extern void sync_filesystems(int wait);
+extern void emergency_sync(void);
+extern void emergency_remount(void);
+extern int do_remount_sb(struct super_block *sb, int flags,
+ void *data, int force);
extern sector_t bmap(struct inode *, sector_t);
extern int setattr_mask(unsigned int);
extern int notify_change(struct dentry *, struct iattr *);
diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
index ee340cd26eaf..1acdb0bd4689 100644
--- a/include/linux/sysrq.h
+++ b/include/linux/sysrq.h
@@ -92,21 +92,3 @@ static inline int __reterr(void)
#define unregister_sysrq_key(ig,nore) __reterr()
#endif
-
-
-/* Deferred actions */
-
-extern int emergency_sync_scheduled;
-
-#define EMERG_SYNC 1
-#define EMERG_REMOUNT 2
-
-void do_emergency_sync(void);
-
-#ifdef CONFIG_MAGIC_SYSRQ
-#define CHECK_EMERGENCY_SYNC \
- if (emergency_sync_scheduled) \
- do_emergency_sync();
-#else
-#define CHECK_EMERGENCY_SYNC
-#endif
diff --git a/kernel/panic.c b/kernel/panic.c
index 66a22b5d9c77..80c582d13d4f 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -96,9 +96,8 @@ NORET_TYPE void panic(const char * fmt, ...)
disabled_wait(caller);
#endif
local_irq_enable();
- for(;;) {
- CHECK_EMERGENCY_SYNC
- }
+ for (;;)
+ ;
}
/**
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index c33c6a207426..589c8be70ff1 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -20,7 +20,6 @@
#include <linux/pagemap.h>
#include <linux/writeback.h>
#include <linux/init.h>
-#include <linux/sysrq.h>
#include <linux/backing-dev.h>
#include <linux/blkdev.h>
#include <linux/mpage.h>
@@ -237,7 +236,6 @@ static void background_writeout(unsigned long _min_pages)
.nonblocking = 1,
};
- CHECK_EMERGENCY_SYNC
for ( ; ; ) {
struct page_state ps;
long background_thresh;