git: eb9d205fa691 - main - livedump: add event handler hooks
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 05 Apr 2022 18:35:14 UTC
The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=eb9d205fa6918bad40bdbf66fe3d52931ae3d6ce commit eb9d205fa6918bad40bdbf66fe3d52931ae3d6ce Author: Mitchell Horne <mhorne@FreeBSD.org> AuthorDate: 2022-01-06 19:40:16 +0000 Commit: Mitchell Horne <mhorne@FreeBSD.org> CommitDate: 2022-04-05 18:35:05 +0000 livedump: add event handler hooks Add three hooks to the livedump process: before, after, and for each block of dumped data. This allows, for example, quiescing the system before the dump begins or protecting data of interest to ensure its consistency in the final output. Reviewed by: markj, kib (previous version) Reviewed by: debdrup (manpages) Reviewed by: Pau Amma <pauamma@gundo.com> (manpages) MFC after: 3 weeks Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D34067 --- share/man/man9/EVENTHANDLER.9 | 8 +++++++- sys/kern/kern_vnodedumper.c | 11 +++++++++++ sys/sys/kerneldump.h | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/share/man/man9/EVENTHANDLER.9 b/share/man/man9/EVENTHANDLER.9 index c38bb3d6c93a..b369e2f03258 100644 --- a/share/man/man9/EVENTHANDLER.9 +++ b/share/man/man9/EVENTHANDLER.9 @@ -318,8 +318,14 @@ Callbacks invoked after a linker file has been successfully unloaded. Callbacks invoked before a linker file is about to be unloaded. These callbacks may be used to return an error and prevent the unload from proceeding. +.It Vt livedumper_start +Callback invoked before beginning a kernel dump of the live system. +.It Vt livedumper_dump +Callback invoked for each dumped block of data during a live kernel dump. +.It Vt livedumper_finish +Callback invoked once a live kernel dump has completed. .It Vt lle_event -Callback invoked when an link layer event has happened. +Callback invoked when a link layer event has happened. .It Vt nmbclusters_change Callback invoked when the number of mbuf clusters has changed. .It Vt nmbufs_change diff --git a/sys/kern/kern_vnodedumper.c b/sys/kern/kern_vnodedumper.c index c8fdce5e550a..cd20f4f2fab4 100644 --- a/sys/kern/kern_vnodedumper.c +++ b/sys/kern/kern_vnodedumper.c @@ -31,6 +31,7 @@ #include <sys/conf.h> #include <sys/caprights.h> #include <sys/disk.h> +#include <sys/eventhandler.h> #include <sys/fcntl.h> #include <sys/file.h> #include <sys/kerneldump.h> @@ -111,9 +112,15 @@ livedump_start(int fd, int flags, uint8_t compression) rl_cookie = vn_rangelock_wlock(vp, 0, OFF_MAX); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + EVENTHANDLER_INVOKE(livedumper_start, &error); + if (error != 0) + goto out; + dump_savectx(); error = minidumpsys(livedi, true); + EVENTHANDLER_INVOKE(livedumper_finish); +out: VOP_UNLOCK(vp); vn_rangelock_unlock(vp, rl_cookie); sx_xunlock(&livedump_sx); @@ -162,6 +169,10 @@ vnode_dump(void *arg, void *virtual, vm_offset_t physical __unused, MPASS(vp != NULL); ASSERT_VOP_LOCKED(vp, __func__); + EVENTHANDLER_INVOKE(livedumper_dump, virtual, offset, length, &error); + if (error != 0) + return (error); + /* Done? */ if (virtual == NULL) return (0); diff --git a/sys/sys/kerneldump.h b/sys/sys/kerneldump.h index 2c73790bc81d..637eab5c39e5 100644 --- a/sys/sys/kerneldump.h +++ b/sys/sys/kerneldump.h @@ -164,6 +164,15 @@ extern int do_minidump; int livedump_start(int, int, uint8_t); +/* Live minidump events */ +typedef void (*livedump_start_fn)(void *arg, int *errorp); +typedef void (*livedump_dump_fn)(void *arg, void *virtual, off_t offset, + size_t len, int *errorp); +typedef void (*livedump_finish_fn)(void *arg); +EVENTHANDLER_DECLARE(livedumper_start, livedump_start_fn); +EVENTHANDLER_DECLARE(livedumper_dump, livedump_dump_fn); +EVENTHANDLER_DECLARE(livedumper_finish, livedump_finish_fn); + #endif #endif /* _SYS_KERNELDUMP_H */