mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-03-14 06:16:17 +03:00
libspl: move procfs_list implementation from libzpool
Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rob Norris <robn@despairlabs.com> Closes #17861
This commit is contained in:
parent
8700fc669b
commit
ee89fefe4d
@ -24,6 +24,7 @@ libspl_la_SOURCES = \
|
|||||||
%D%/mkdirp.c \
|
%D%/mkdirp.c \
|
||||||
%D%/mutex.c \
|
%D%/mutex.c \
|
||||||
%D%/page.c \
|
%D%/page.c \
|
||||||
|
%D%/procfs_list.c \
|
||||||
%D%/rwlock.c \
|
%D%/rwlock.c \
|
||||||
%D%/strlcat.c \
|
%D%/strlcat.c \
|
||||||
%D%/strlcpy.c \
|
%D%/strlcpy.c \
|
||||||
|
|||||||
93
lib/libspl/procfs_list.c
Normal file
93
lib/libspl/procfs_list.c
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
// SPDX-License-Identifier: CDDL-1.0
|
||||||
|
/*
|
||||||
|
* CDDL HEADER START
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the terms of the
|
||||||
|
* Common Development and Distribution License (the "License").
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
*
|
||||||
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||||
|
* or https://opensource.org/licenses/CDDL-1.0.
|
||||||
|
* See the License for the specific language governing permissions
|
||||||
|
* and limitations under the License.
|
||||||
|
*
|
||||||
|
* When distributing Covered Code, include this CDDL HEADER in each
|
||||||
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||||
|
* If applicable, add the following below this CDDL HEADER, with the
|
||||||
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
||||||
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
||||||
|
*
|
||||||
|
* CDDL HEADER END
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* Copyright (c) 2012, 2018 by Delphix. All rights reserved.
|
||||||
|
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
|
||||||
|
* Copyright (c) 2025, Klara, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <sys/procfs_list.h>
|
||||||
|
#include <sys/mutex.h>
|
||||||
|
#include <sys/list.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* =========================================================================
|
||||||
|
* procfs list
|
||||||
|
* =========================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
seq_printf(struct seq_file *m, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
(void) m, (void) fmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
(void) module, (void) submodule, (void) name, (void) mode, (void) show,
|
||||||
|
(void) show_header, (void) clear;
|
||||||
|
mutex_init(&procfs_list->pl_lock, NULL, MUTEX_DEFAULT, NULL);
|
||||||
|
list_create(&procfs_list->pl_list,
|
||||||
|
procfs_list_node_off + sizeof (procfs_list_node_t),
|
||||||
|
procfs_list_node_off + offsetof(procfs_list_node_t, pln_link));
|
||||||
|
procfs_list->pl_next_id = 1;
|
||||||
|
procfs_list->pl_node_offset = procfs_list_node_off;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
procfs_list_uninstall(procfs_list_t *procfs_list)
|
||||||
|
{
|
||||||
|
(void) procfs_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
procfs_list_destroy(procfs_list_t *procfs_list)
|
||||||
|
{
|
||||||
|
ASSERT(list_is_empty(&procfs_list->pl_list));
|
||||||
|
list_destroy(&procfs_list->pl_list);
|
||||||
|
mutex_destroy(&procfs_list->pl_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NODE_ID(procfs_list, obj) \
|
||||||
|
(((procfs_list_node_t *)(((char *)obj) + \
|
||||||
|
(procfs_list)->pl_node_offset))->pln_id)
|
||||||
|
|
||||||
|
void
|
||||||
|
procfs_list_add(procfs_list_t *procfs_list, void *p)
|
||||||
|
{
|
||||||
|
ASSERT(MUTEX_HELD(&procfs_list->pl_lock));
|
||||||
|
NODE_ID(procfs_list, p) = procfs_list->pl_next_id++;
|
||||||
|
list_insert_tail(&procfs_list->pl_list, p);
|
||||||
|
}
|
||||||
@ -74,65 +74,6 @@ zone_get_hostid(void *zonep)
|
|||||||
return (hostid);
|
return (hostid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* =========================================================================
|
|
||||||
* procfs list
|
|
||||||
* =========================================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
|
||||||
seq_printf(struct seq_file *m, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
(void) m, (void) fmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
(void) module, (void) submodule, (void) name, (void) mode, (void) show,
|
|
||||||
(void) show_header, (void) clear;
|
|
||||||
mutex_init(&procfs_list->pl_lock, NULL, MUTEX_DEFAULT, NULL);
|
|
||||||
list_create(&procfs_list->pl_list,
|
|
||||||
procfs_list_node_off + sizeof (procfs_list_node_t),
|
|
||||||
procfs_list_node_off + offsetof(procfs_list_node_t, pln_link));
|
|
||||||
procfs_list->pl_next_id = 1;
|
|
||||||
procfs_list->pl_node_offset = procfs_list_node_off;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
procfs_list_uninstall(procfs_list_t *procfs_list)
|
|
||||||
{
|
|
||||||
(void) procfs_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
procfs_list_destroy(procfs_list_t *procfs_list)
|
|
||||||
{
|
|
||||||
ASSERT(list_is_empty(&procfs_list->pl_list));
|
|
||||||
list_destroy(&procfs_list->pl_list);
|
|
||||||
mutex_destroy(&procfs_list->pl_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NODE_ID(procfs_list, obj) \
|
|
||||||
(((procfs_list_node_t *)(((char *)obj) + \
|
|
||||||
(procfs_list)->pl_node_offset))->pln_id)
|
|
||||||
|
|
||||||
void
|
|
||||||
procfs_list_add(procfs_list_t *procfs_list, void *p)
|
|
||||||
{
|
|
||||||
ASSERT(MUTEX_HELD(&procfs_list->pl_lock));
|
|
||||||
NODE_ID(procfs_list, p) = procfs_list->pl_next_id++;
|
|
||||||
list_insert_tail(&procfs_list->pl_list, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* =========================================================================
|
* =========================================================================
|
||||||
* vnode operations
|
* vnode operations
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user