1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3 * This file and its contents are supplied under the terms of the
4 * Common Development and Distribution License ("CDDL"), version 1.0.
5 * You may only use this file in accordance with the terms of version
6 * 1.0 of the CDDL.
7 *
8 * A full copy of the text of the CDDL should have accompanied this
9 * source. A copy of the CDDL is also available via the Internet at
10 * https://opensource.org/license/CDDL-1.0.
11 */
12 /*
13 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
14 * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
15 * Copyright (c) 2016 Actifio, Inc. All rights reserved.
16 * Copyright (c) 2025, Klara, Inc.
17 */
18
19 #include <assert.h>
20 #include <pthread.h>
21 #include <stddef.h>
22 #include <sys/procfs_list.h>
23 #include <sys/mutex.h>
24 #include <sys/list.h>
25
26 /*
27 * =========================================================================
28 * procfs list
29 * =========================================================================
30 */
31
32 void
seq_printf(struct seq_file * m,const char * fmt,...)33 seq_printf(struct seq_file *m, const char *fmt, ...)
34 {
35 (void) m, (void) fmt;
36 }
37
38 void
procfs_list_install(const char * module,const char * submodule,const char * name,mode_t mode,procfs_list_t * procfs_list,int (* show)(struct seq_file * f,void * p),int (* show_header)(struct seq_file * f),int (* clear)(procfs_list_t * procfs_list),size_t procfs_list_node_off)39 procfs_list_install(const char *module,
40 const char *submodule,
41 const char *name,
42 mode_t mode,
43 procfs_list_t *procfs_list,
44 int (*show)(struct seq_file *f, void *p),
45 int (*show_header)(struct seq_file *f),
46 int (*clear)(procfs_list_t *procfs_list),
47 size_t procfs_list_node_off)
48 {
49 (void) module, (void) submodule, (void) name, (void) mode, (void) show,
50 (void) show_header, (void) clear;
51 mutex_init(&procfs_list->pl_lock, NULL, MUTEX_DEFAULT, NULL);
52 list_create(&procfs_list->pl_list,
53 procfs_list_node_off + sizeof (procfs_list_node_t),
54 procfs_list_node_off + offsetof(procfs_list_node_t, pln_link));
55 procfs_list->pl_next_id = 1;
56 procfs_list->pl_node_offset = procfs_list_node_off;
57 }
58
59 void
procfs_list_uninstall(procfs_list_t * procfs_list)60 procfs_list_uninstall(procfs_list_t *procfs_list)
61 {
62 (void) procfs_list;
63 }
64
65 void
procfs_list_destroy(procfs_list_t * procfs_list)66 procfs_list_destroy(procfs_list_t *procfs_list)
67 {
68 ASSERT(list_is_empty(&procfs_list->pl_list));
69 list_destroy(&procfs_list->pl_list);
70 mutex_destroy(&procfs_list->pl_lock);
71 }
72
73 #define NODE_ID(procfs_list, obj) \
74 (((procfs_list_node_t *)(((char *)obj) + \
75 (procfs_list)->pl_node_offset))->pln_id)
76
77 void
procfs_list_add(procfs_list_t * procfs_list,void * p)78 procfs_list_add(procfs_list_t *procfs_list, void *p)
79 {
80 ASSERT(MUTEX_HELD(&procfs_list->pl_lock));
81 NODE_ID(procfs_list, p) = procfs_list->pl_next_id++;
82 list_insert_tail(&procfs_list->pl_list, p);
83 }
84