1 /* 2 * Copyright (c) 2020 iXsystems, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28 #include <sys/cdefs.h> 29 __FBSDID("$FreeBSD$"); 30 31 #include <sys/list.h> 32 #include <sys/mutex.h> 33 #include <sys/procfs_list.h> 34 35 void 36 seq_printf(struct seq_file *m, const char *fmt, ...) 37 {} 38 39 void 40 procfs_list_install(const char *module, 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 mutex_init(&procfs_list->pl_lock, NULL, MUTEX_DEFAULT, NULL); 50 list_create(&procfs_list->pl_list, 51 procfs_list_node_off + sizeof (procfs_list_node_t), 52 procfs_list_node_off + offsetof(procfs_list_node_t, pln_link)); 53 procfs_list->pl_next_id = 1; 54 procfs_list->pl_node_offset = procfs_list_node_off; 55 } 56 57 void 58 procfs_list_uninstall(procfs_list_t *procfs_list) 59 {} 60 61 void 62 procfs_list_destroy(procfs_list_t *procfs_list) 63 { 64 ASSERT(list_is_empty(&procfs_list->pl_list)); 65 list_destroy(&procfs_list->pl_list); 66 mutex_destroy(&procfs_list->pl_lock); 67 } 68 69 #define NODE_ID(procfs_list, obj) \ 70 (((procfs_list_node_t *)(((char *)obj) + \ 71 (procfs_list)->pl_node_offset))->pln_id) 72 73 void 74 procfs_list_add(procfs_list_t *procfs_list, void *p) 75 { 76 ASSERT(MUTEX_HELD(&procfs_list->pl_lock)); 77 NODE_ID(procfs_list, p) = procfs_list->pl_next_id++; 78 list_insert_tail(&procfs_list->pl_list, p); 79 } 80