Path: blob/main/sys/contrib/openzfs/lib/libspl/procfs_list.c
96339 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License (the "License").6* You may not use this file except in compliance with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/21/*22* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.23* Copyright (c) 2012, 2018 by Delphix. All rights reserved.24* Copyright (c) 2016 Actifio, Inc. All rights reserved.25* Copyright (c) 2025, Klara, Inc.26*/2728#include <assert.h>29#include <pthread.h>30#include <stddef.h>31#include <sys/procfs_list.h>32#include <sys/mutex.h>33#include <sys/list.h>3435/*36* =========================================================================37* procfs list38* =========================================================================39*/4041void42seq_printf(struct seq_file *m, const char *fmt, ...)43{44(void) m, (void) fmt;45}4647void48procfs_list_install(const char *module,49const char *submodule,50const char *name,51mode_t mode,52procfs_list_t *procfs_list,53int (*show)(struct seq_file *f, void *p),54int (*show_header)(struct seq_file *f),55int (*clear)(procfs_list_t *procfs_list),56size_t procfs_list_node_off)57{58(void) module, (void) submodule, (void) name, (void) mode, (void) show,59(void) show_header, (void) clear;60mutex_init(&procfs_list->pl_lock, NULL, MUTEX_DEFAULT, NULL);61list_create(&procfs_list->pl_list,62procfs_list_node_off + sizeof (procfs_list_node_t),63procfs_list_node_off + offsetof(procfs_list_node_t, pln_link));64procfs_list->pl_next_id = 1;65procfs_list->pl_node_offset = procfs_list_node_off;66}6768void69procfs_list_uninstall(procfs_list_t *procfs_list)70{71(void) procfs_list;72}7374void75procfs_list_destroy(procfs_list_t *procfs_list)76{77ASSERT(list_is_empty(&procfs_list->pl_list));78list_destroy(&procfs_list->pl_list);79mutex_destroy(&procfs_list->pl_lock);80}8182#define NODE_ID(procfs_list, obj) \83(((procfs_list_node_t *)(((char *)obj) + \84(procfs_list)->pl_node_offset))->pln_id)8586void87procfs_list_add(procfs_list_t *procfs_list, void *p)88{89ASSERT(MUTEX_HELD(&procfs_list->pl_lock));90NODE_ID(procfs_list, p) = procfs_list->pl_next_id++;91list_insert_tail(&procfs_list->pl_list, p);92}939495