git: dfe83ae4da34 - stable/14 - sysctl vm.vm_objects: report cdev name for device-backed objects

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 15:05:42 UTC
The branch stable/14 has been updated by kib:

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

commit dfe83ae4da34798a7bd0e6c7607b548ead4a1869
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-10-10 09:37:19 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-10-15 15:03:59 +0000

    sysctl vm.vm_objects: report cdev name for device-backed objects
    
    (cherry picked from commit d9daa28c364d0b1189ab616d8d697b4c9f748038)
---
 sys/vm/vm_object.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index d0f367815469..d2ac8f696634 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -68,6 +68,7 @@
 
 #include <sys/systm.h>
 #include <sys/blockcount.h>
+#include <sys/conf.h>
 #include <sys/cpuset.h>
 #include <sys/ipc.h>
 #include <sys/jail.h>
@@ -2517,8 +2518,10 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
 	struct vattr va;
 	vm_object_t obj;
 	vm_page_t m;
+	struct cdev *cdev;
+	struct cdevsw *csw;
 	u_long sp;
-	int count, error;
+	int count, error, ref;
 	key_t key;
 	unsigned short seq;
 	bool want_path;
@@ -2605,6 +2608,17 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
 			sp = swap_pager_swapped_pages(obj);
 			kvo->kvo_swapped = sp > UINT32_MAX ? UINT32_MAX : sp;
 		}
+		if (obj->type == OBJT_DEVICE || obj->type == OBJT_MGTDEVICE) {
+			cdev = obj->un_pager.devp.dev;
+			if (cdev != NULL) {
+				csw = dev_refthread(cdev, &ref);
+				if (csw != NULL) {
+					strlcpy(kvo->kvo_path, cdev->si_name,
+					    sizeof(kvo->kvo_path));
+					dev_relthread(cdev, ref);
+				}
+			}
+		}
 		VM_OBJECT_RUNLOCK(obj);
 		if ((obj->flags & OBJ_SYSVSHM) != 0) {
 			kvo->kvo_flags |= KVMO_FLAG_SYSVSHM;