panic/reboot changes (RFC)

Josh Huber (huber@mclx.com)
Tue, 8 Aug 2000 17:22:38 -0400


--wTWi5aaYRw9ix9vO
Content-Type: multipart/mixed; boundary="hoZxPH4CaxYzWscb"
Content-Disposition: inline

--hoZxPH4CaxYzWscb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Attached is a patch to 2.4.0-test6-pre8 that does the following:

* Adds two functions similar to (un)register_panic_notifier() for
changing the contents of the panic_notifier_list.
* Adds (un)register_panic_notifier() functions to ksyms.c ones so
modules can use them. (should these be added to panic.c?) In 2.2.16
the reboot notifiers are listed in ksyms.c, and not sys.c as they
are in 2.4-test kernels.
* Moves the call to notifier_call_chain up in panic() so it's the
first action to be taken.

The reason I believe the notifier_call_chain call should be moved is
that it's important (at least, for debugging systems) to be able to
call a function before buffers are synched to disk, and
smp_send_stop() is called. I also moved unblank_console() to up above
the notifier_call_chain.

For example, in a crash dump system, you want whatever routine is
saving a crash dump to be called prior to sys_sync.

Is this move going to break the three other places it's used?:
indy_reboot_setup, arch/mips/sgi/kernel/reset.c
setup_arch, arch/alpha/kernel/setup.c
ip22_reboot_setup, arch/mips64/sgi-ip22/ip22-reset.c

at first glance, it doesn't look like it.

* added a flag 'panic_on_oops' which will cause a panic instead of an
oops -- default to 0, but modifiable from /proc/sys. Right now I
just added a check to the i386 traps.c file, but you get the idea.
* added a panicing flag inside panic() to prevent recursive endless
calls to panic.

Files touched:
kernel/panic.c
arch/i386/kernel/traps.c
kernel/sysctl.c
include/linux/sysctl.h
include/linux/kernel.h

At this point, I'm just looking for comments, suggestions, etc.

Thanks,
--=20
Josh
6B21489A | GnuPG ID/Fingerprint | huber@mclx.com |
61F0 6138 BE7B FEBF A223 E9D1 BFE1 2065 6B21 489A

--hoZxPH4CaxYzWscb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="panic_changes.diff"
Content-Transfer-Encoding: quoted-printable

diff -urN linux-2.4.0-test6-pre8/include/linux/kernel.h linux-2.4.0-test6-p=
re8-patched/include/linux/kernel.h
--- linux-2.4.0-test6-pre8/include/linux/kernel.h Tue Jun 20 10:52:36 2000
+++ linux-2.4.0-test6-pre8-patched/include/linux/kernel.h Tue Aug 8 16:46:=
07 2000
@@ -44,7 +44,10 @@
#define FASTCALL(x) x
#endif
=20
+extern int panic_on_oops;
extern struct notifier_block *panic_notifier_list;
+extern int register_panic_notifier(struct notifier_block * nb);
+extern int unregister_panic_notifier(struct notifier_block * nb);
NORET_TYPE void panic(const char * fmt, ...)
__attribute__ ((NORET_AND format (printf, 1, 2)));
NORET_TYPE void do_exit(long error_code)
diff -urN linux-2.4.0-test6-pre8/include/linux/sysctl.h linux-2.4.0-test6-p=
re8-patched/include/linux/sysctl.h
--- linux-2.4.0-test6-pre8/include/linux/sysctl.h Fri Jul 21 17:13:33 2000
+++ linux-2.4.0-test6-pre8-patched/include/linux/sysctl.h Tue Aug 8 16:31:=
44 2000
@@ -113,6 +113,7 @@
KERN_OVERFLOWGID=3D47, /* int: overflow GID */
KERN_SHMPATH=3D48, /* string: path to shm fs */
KERN_HOTPLUG=3D49, /* string: path to hotplug policy agent */
+ KERN_PANIC_ON_OOPS=3D50, /* int: should we panic on an oops? */
};
=20
=20
diff -urN linux-2.4.0-test6-pre8/kernel/exit.c linux-2.4.0-test6-pre8-patch=
ed/kernel/exit.c
--- linux-2.4.0-test6-pre8/kernel/exit.c Tue Aug 8 15:21:05 2000
+++ linux-2.4.0-test6-pre8-patched/kernel/exit.c Tue Aug 8 16:10:19 2000
@@ -437,6 +437,10 @@
panic("Attempted to kill the idle task!");
if (tsk->pid =3D=3D 1)
panic("Attempted to kill init!");
+
+ if(panic_on_oops)
+ panic("oops, forcing panic");
+
tsk->flags |=3D PF_EXITING;
del_timer_sync(&tsk->real_timer);
=20
diff -urN linux-2.4.0-test6-pre8/kernel/panic.c linux-2.4.0-test6-pre8-patc=
hed/kernel/panic.c
--- linux-2.4.0-test6-pre8/kernel/panic.c Tue Jun 20 17:32:27 2000
+++ linux-2.4.0-test6-pre8-patched/kernel/panic.c Tue Aug 8 17:05:26 2000
@@ -21,9 +21,41 @@
extern void unblank_console(void);
=20
int panic_timeout;
+int panic_on_oops =3D 0;
=20
struct notifier_block *panic_notifier_list =3D NULL;
=20
+/**
+ * register_panic_notifier - Register function to be called at panic =
time
+ * @nb: Info about notifier function to be called
+ *
+ * Registers a function with the list of functions
+ * to be called at panic time.
+ *
+ * Currently always returns zero, as notifier_chain_register
+ * always returns zero.
+ */
+
+int register_panic_notifier(struct notifier_block * nb)
+{
+ return notifier_chain_register(&panic_notifier_list, nb);
+}
+
+/**
+ * unregister_panic_notifier - Unregister previously registered panic noti=
fier
+ * @nb: Hook to be unregistered
+ *
+ * Unregisters a previously registered panic
+ * notifier function.
+ *
+ * Returns zero on success, or %-ENOENT on failure.
+ */
+
+int unregister_panic_notifier(struct notifier_block * nb)
+{
+ return notifier_chain_unregister(&panic_notifier_list, nb);
+}
+
static int __init panic_setup(char *str)
{
panic_timeout =3D simple_strtoul(str, NULL, 0);
@@ -46,11 +78,19 @@
NORET_TYPE void panic(const char * fmt, ...)
{
static char buf[1024];
+ static int panicing =3D 0;
va_list args;
#if defined(CONFIG_ARCH_S390)
unsigned long caller =3D (unsigned long) __builtin_return_address(=
0);
#endif
=20
+ if (panicing)
+ goto out;
+
+ panicing =3D 1;
+ unblank_console();
+ notifier_call_chain(&panic_notifier_list, 0, NULL);
+
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
@@ -62,14 +102,11 @@
else
sys_sync();
=20
- unblank_console();
-
#ifdef CONFIG_SMP
smp_send_stop();
#endif
-
- notifier_call_chain(&panic_notifier_list, 0, NULL);
-
+=09
+ out:
if (panic_timeout > 0)
{
/*
@@ -101,3 +138,6 @@
CHECK_EMERGENCY_SYNC
}
}
+
+EXPORT_SYMBOL(register_panic_notifier);
+EXPORT_SYMBOL(unregister_panic_notifier);
diff -urN linux-2.4.0-test6-pre8/kernel/sysctl.c linux-2.4.0-test6-pre8-pat=
ched/kernel/sysctl.c
--- linux-2.4.0-test6-pre8/kernel/sysctl.c Tue Aug 8 15:21:05 2000
+++ linux-2.4.0-test6-pre8-patched/kernel/sysctl.c Tue Aug 8 16:30:20 2000
@@ -230,6 +230,8 @@
{KERN_OVERFLOWGID, "overflowgid", &overflowgid, sizeof(int), 0644, NULL,
&proc_dointvec_minmax, &sysctl_intvec, NULL,
&minolduid, &maxolduid},
+ {KERN_PANIC_ON_OOPS, "panic_on_oops", &panic_on_oops, sizeof(int),
+ 0644, NULL, &proc_dointvec},
{0}
};
=20

--hoZxPH4CaxYzWscb--

--wTWi5aaYRw9ix9vO
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjmQeh4ACgkQv+EgZWshSJoFLgCfWdSbm5jK6CNUblFpO2DpZB3o
HvQAoKqN5m6kJEpFe/UL7yES9UMt8hrR
=qfel
-----END PGP SIGNATURE-----

--wTWi5aaYRw9ix9vO--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/