git: 9b2f554dca7d - stable/13 - Add 'show tmpfs' ddb command

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Fri, 20 Jan 2023 03:23:24 UTC
The branch stable/13 has been updated by kib:

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

commit 9b2f554dca7d3a8104a760df69e011acec592df9
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-10-20 14:30:00 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-01-20 03:19:01 +0000

    Add 'show tmpfs' ddb command
    
    Tested by:      pho
    
    (cherry picked from commit 83aff0f08c525ea3c394f3dd6598665cd369d53c)
---
 sys/fs/tmpfs/tmpfs_vfsops.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/sys/fs/tmpfs/tmpfs_vfsops.c b/sys/fs/tmpfs/tmpfs_vfsops.c
index b8ecedbb0348..c80042286948 100644
--- a/sys/fs/tmpfs/tmpfs_vfsops.c
+++ b/sys/fs/tmpfs/tmpfs_vfsops.c
@@ -43,6 +43,7 @@
  * allocate and release resources.
  */
 
+#include "opt_ddb.h"
 #include "opt_tmpfs.h"
 
 #include <sys/cdefs.h>
@@ -696,3 +697,44 @@ struct vfsops tmpfs_vfsops = {
 	.vfs_uninit =			tmpfs_uninit,
 };
 VFS_SET(tmpfs_vfsops, tmpfs, VFCF_JAIL);
+
+#ifdef DDB
+#include <ddb/ddb.h>
+
+static void
+db_print_tmpfs(struct mount *mp, struct tmpfs_mount *tmp)
+{
+	db_printf("mp %p (%s) tmp %p\n", mp,
+	    mp->mnt_stat.f_mntonname, tmp);
+	db_printf(
+	    "\tsize max %ju pages max %lu pages used %lu\n"
+	    "\tinodes max %ju inodes inuse %ju refcount %ju\n"
+	    "\tmaxfilesize %ju r%c %snamecache %smtime\n",
+	    (uintmax_t)tmp->tm_size_max, tmp->tm_pages_max, tmp->tm_pages_used,
+	    (uintmax_t)tmp->tm_nodes_max, (uintmax_t)tmp->tm_nodes_inuse,
+	    (uintmax_t)tmp->tm_refcount, (uintmax_t)tmp->tm_maxfilesize,
+	    tmp->tm_ronly ? 'o' : 'w', tmp->tm_nonc ? "no" : "",
+	    tmp->tm_nomtime ? "no" : "");
+}
+
+DB_SHOW_COMMAND(tmpfs, db_show_tmpfs)
+{
+	struct mount *mp;
+	struct tmpfs_mount *tmp;
+
+	if (have_addr) {
+		mp = (struct mount *)addr;
+		tmp = VFS_TO_TMPFS(mp);
+		db_print_tmpfs(mp, tmp);
+		return;
+	}
+
+	TAILQ_FOREACH(mp, &mountlist, mnt_list) {
+		if (strcmp(mp->mnt_stat.f_fstypename, tmpfs_vfsconf.vfc_name) ==
+		    0) {
+			tmp = VFS_TO_TMPFS(mp);
+			db_print_tmpfs(mp, tmp);
+		}
+	}
+}
+#endif	/* DDB */