git: 60bc9617e79e - main - kerneldump: add livedump_start_vnode(9)

From: Ka Ho Ng <khng_at_FreeBSD.org>
Date: Mon, 18 Mar 2024 21:13:54 UTC
The branch main has been updated by khng:

URL: https://cgit.FreeBSD.org/src/commit/?id=60bc9617e79e99bdf670304923f3baed4b749ad3

commit 60bc9617e79e99bdf670304923f3baed4b749ad3
Author:     Vijeyalakshumi Koteeswaran <kvinupriya@gmail.com>
AuthorDate: 2024-03-18 19:26:29 +0000
Commit:     Ka Ho Ng <khng@FreeBSD.org>
CommitDate: 2024-03-18 21:12:18 +0000

    kerneldump: add livedump_start_vnode(9)
    
    livedump_start_vnode(9) is introduced such that the live minidump on the
    system could take a vnode. This interface could be used to extend support
    for the existing framework in downstream.
    
    Bump __FreeBSD_version for introducing livedump_start_vnode(9).
    
    Sponsored by:   Juniper Networks, Inc.
    Reviewed by:    khng
    Differential Revision:  https://reviews.freebsd.org/D43471
---
 sys/kern/kern_vnodedumper.c | 32 +++++++++++++++++++++++---------
 sys/sys/kerneldump.h        |  1 +
 sys/sys/param.h             |  2 +-
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/sys/kern/kern_vnodedumper.c b/sys/kern/kern_vnodedumper.c
index 0104369b9d67..5a2c255390cc 100644
--- a/sys/kern/kern_vnodedumper.c
+++ b/sys/kern/kern_vnodedumper.c
@@ -61,11 +61,8 @@ int
 livedump_start(int fd, int flags, uint8_t compression)
 {
 #if MINIDUMP_PAGE_TRACKING == 1
-	struct dumperinfo di, *livedi;
-	struct diocskerneldump_arg kda;
-	struct vnode *vp;
 	struct file *fp;
-	void *rl_cookie;
+	struct vnode *vp;
 	int error;
 
 	error = priv_check(curthread, PRIV_KMEM_READ);
@@ -84,8 +81,27 @@ livedump_start(int fd, int flags, uint8_t compression)
 		error = EBADF;
 		goto drop;
 	}
+	error = livedump_start_vnode(vp, flags, compression);
+	if (error != 0)
+		goto drop;
+drop:
+	fdrop(fp, curthread);
+	return (error);
+#else
+	return (EOPNOTSUPP);
+#endif /* MINIDUMP_PAGE_TRACKING == 1 */
+}
 
-	/* Set up a new dumper. */
+int
+livedump_start_vnode(struct vnode *vp, int flags, uint8_t compression)
+{
+#if MINIDUMP_PAGE_TRACKING == 1
+	struct dumperinfo di, *livedi;
+	struct diocskerneldump_arg kda;
+	void *rl_cookie;
+	int error;
+
+        /* Set up a new dumper. */
 	bzero(&di, sizeof(di));
 	di.dumper_start = vnode_dumper_start;
 	di.dumper = vnode_dump;
@@ -97,13 +113,13 @@ livedump_start(int fd, int flags, uint8_t compression)
 	kda.kda_compression = compression;
 	error = dumper_create(&di, "livedump", &kda, &livedi);
 	if (error != 0)
-		goto drop;
+		return (error);
 
 	/* Only allow one livedump to proceed at a time. */
 	if (sx_try_xlock(&livedump_sx) == 0) {
 		dumper_destroy(livedi);
 		error = EBUSY;
-		goto drop;
+		return (error);
 	}
 
 	/* To be used by the callback functions. */
@@ -126,8 +142,6 @@ out:
 	vn_rangelock_unlock(vp, rl_cookie);
 	sx_xunlock(&livedump_sx);
 	dumper_destroy(livedi);
-drop:
-	fdrop(fp, curthread);
 	return (error);
 #else
 	return (EOPNOTSUPP);
diff --git a/sys/sys/kerneldump.h b/sys/sys/kerneldump.h
index 46f05b3c130d..1f03c4b9c2d5 100644
--- a/sys/sys/kerneldump.h
+++ b/sys/sys/kerneldump.h
@@ -161,6 +161,7 @@ void dumpsys_pb_progress(size_t);
 extern int do_minidump;
 
 int livedump_start(int, int, uint8_t);
+int livedump_start_vnode(struct vnode *, int, uint8_t);
 
 /* Live minidump events */
 typedef void (*livedump_start_fn)(void *arg, int *errorp);
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 4369aba9bb46..d56255431ba2 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -73,7 +73,7 @@
  * cannot include sys/param.h and should only be updated here.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1500015
+#define __FreeBSD_version 1500016
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,