zfs: replace uu_list with sys/list

Lets just use the list implementation we use everywhere else.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes #17934
This commit is contained in:
Rob Norris 2025-11-13 21:16:38 +11:00 committed by Brian Behlendorf
parent b593748287
commit 871fa61d26
2 changed files with 47 additions and 92 deletions

View File

@ -29,7 +29,6 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <libuutil.h>
#include <libzfs.h> #include <libzfs.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
@ -96,7 +95,7 @@ typedef struct zfs_case {
uint32_t zc_version; uint32_t zc_version;
zfs_case_data_t zc_data; zfs_case_data_t zc_data;
fmd_case_t *zc_case; fmd_case_t *zc_case;
uu_list_node_t zc_node; list_node_t zc_node;
id_t zc_remove_timer; id_t zc_remove_timer;
char *zc_fru; char *zc_fru;
er_timeval_t zc_when; er_timeval_t zc_when;
@ -126,8 +125,7 @@ zfs_de_stats_t zfs_stats = {
/* wait 15 seconds after a removal */ /* wait 15 seconds after a removal */
static hrtime_t zfs_remove_timeout = SEC2NSEC(15); static hrtime_t zfs_remove_timeout = SEC2NSEC(15);
uu_list_pool_t *zfs_case_pool; static list_t zfs_cases;
uu_list_t *zfs_cases;
#define ZFS_MAKE_RSRC(type) \ #define ZFS_MAKE_RSRC(type) \
FM_RSRC_CLASS "." ZFS_ERROR_CLASS "." type FM_RSRC_CLASS "." ZFS_ERROR_CLASS "." type
@ -174,8 +172,8 @@ zfs_case_unserialize(fmd_hdl_t *hdl, fmd_case_t *cp)
zcp->zc_remove_timer = fmd_timer_install(hdl, zcp, zcp->zc_remove_timer = fmd_timer_install(hdl, zcp,
NULL, zfs_remove_timeout); NULL, zfs_remove_timeout);
uu_list_node_init(zcp, &zcp->zc_node, zfs_case_pool); list_link_init(&zcp->zc_node);
(void) uu_list_insert_before(zfs_cases, NULL, zcp); list_insert_head(&zfs_cases, zcp);
fmd_case_setspecific(hdl, cp, zcp); fmd_case_setspecific(hdl, cp, zcp);
@ -206,8 +204,8 @@ zfs_other_serd_cases(fmd_hdl_t *hdl, const zfs_case_data_t *zfs_case)
next_check = gethrestime_sec() + CASE_GC_TIMEOUT_SECS; next_check = gethrestime_sec() + CASE_GC_TIMEOUT_SECS;
} }
for (zcp = uu_list_first(zfs_cases); zcp != NULL; for (zcp = list_head(&zfs_cases); zcp != NULL;
zcp = uu_list_next(zfs_cases, zcp)) { zcp = list_next(&zfs_cases, zcp)) {
zfs_case_data_t *zcd = &zcp->zc_data; zfs_case_data_t *zcd = &zcp->zc_data;
/* /*
@ -257,8 +255,8 @@ zfs_mark_vdev(uint64_t pool_guid, nvlist_t *vd, er_timeval_t *loaded)
/* /*
* Mark any cases associated with this (pool, vdev) pair. * Mark any cases associated with this (pool, vdev) pair.
*/ */
for (zcp = uu_list_first(zfs_cases); zcp != NULL; for (zcp = list_head(&zfs_cases); zcp != NULL;
zcp = uu_list_next(zfs_cases, zcp)) { zcp = list_next(&zfs_cases, zcp)) {
if (zcp->zc_data.zc_pool_guid == pool_guid && if (zcp->zc_data.zc_pool_guid == pool_guid &&
zcp->zc_data.zc_vdev_guid == vdev_guid) { zcp->zc_data.zc_vdev_guid == vdev_guid) {
zcp->zc_present = B_TRUE; zcp->zc_present = B_TRUE;
@ -304,8 +302,8 @@ zfs_mark_pool(zpool_handle_t *zhp, void *unused)
/* /*
* Mark any cases associated with just this pool. * Mark any cases associated with just this pool.
*/ */
for (zcp = uu_list_first(zfs_cases); zcp != NULL; for (zcp = list_head(&zfs_cases); zcp != NULL;
zcp = uu_list_next(zfs_cases, zcp)) { zcp = list_next(&zfs_cases, zcp)) {
if (zcp->zc_data.zc_pool_guid == pool_guid && if (zcp->zc_data.zc_pool_guid == pool_guid &&
zcp->zc_data.zc_vdev_guid == 0) zcp->zc_data.zc_vdev_guid == 0)
zcp->zc_present = B_TRUE; zcp->zc_present = B_TRUE;
@ -321,8 +319,8 @@ zfs_mark_pool(zpool_handle_t *zhp, void *unused)
if (nelem == 2) { if (nelem == 2) {
loaded.ertv_sec = tod[0]; loaded.ertv_sec = tod[0];
loaded.ertv_nsec = tod[1]; loaded.ertv_nsec = tod[1];
for (zcp = uu_list_first(zfs_cases); zcp != NULL; for (zcp = list_head(&zfs_cases); zcp != NULL;
zcp = uu_list_next(zfs_cases, zcp)) { zcp = list_next(&zfs_cases, zcp)) {
if (zcp->zc_data.zc_pool_guid == pool_guid && if (zcp->zc_data.zc_pool_guid == pool_guid &&
zcp->zc_data.zc_vdev_guid == 0) { zcp->zc_data.zc_vdev_guid == 0) {
zcp->zc_when = loaded; zcp->zc_when = loaded;
@ -389,8 +387,7 @@ zpool_find_load_time(zpool_handle_t *zhp, void *arg)
static void static void
zfs_purge_cases(fmd_hdl_t *hdl) zfs_purge_cases(fmd_hdl_t *hdl)
{ {
zfs_case_t *zcp; zfs_case_t *zcp, *next;
uu_list_walk_t *walk;
libzfs_handle_t *zhdl = fmd_hdl_getspecific(hdl); libzfs_handle_t *zhdl = fmd_hdl_getspecific(hdl);
/* /*
@ -410,8 +407,8 @@ zfs_purge_cases(fmd_hdl_t *hdl)
/* /*
* Mark the cases as not present. * Mark the cases as not present.
*/ */
for (zcp = uu_list_first(zfs_cases); zcp != NULL; for (zcp = list_head(&zfs_cases); zcp != NULL;
zcp = uu_list_next(zfs_cases, zcp)) zcp = list_next(&zfs_cases, zcp))
zcp->zc_present = B_FALSE; zcp->zc_present = B_FALSE;
/* /*
@ -425,12 +422,11 @@ zfs_purge_cases(fmd_hdl_t *hdl)
/* /*
* Remove those cases which were not found. * Remove those cases which were not found.
*/ */
walk = uu_list_walk_start(zfs_cases, UU_WALK_ROBUST); for (zcp = list_head(&zfs_cases); zcp != NULL; zcp = next) {
while ((zcp = uu_list_walk_next(walk)) != NULL) { next = list_next(&zfs_cases, zcp);
if (!zcp->zc_present) if (!zcp->zc_present)
fmd_case_close(hdl, zcp->zc_case); fmd_case_close(hdl, zcp->zc_case);
} }
uu_list_walk_end(walk);
} }
/* /*
@ -660,8 +656,8 @@ zfs_fm_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class)
zfs_ereport_when(hdl, nvl, &er_when); zfs_ereport_when(hdl, nvl, &er_when);
for (zcp = uu_list_first(zfs_cases); zcp != NULL; for (zcp = list_head(&zfs_cases); zcp != NULL;
zcp = uu_list_next(zfs_cases, zcp)) { zcp = list_next(&zfs_cases, zcp)) {
if (zcp->zc_data.zc_pool_guid == pool_guid) { if (zcp->zc_data.zc_pool_guid == pool_guid) {
pool_found = B_TRUE; pool_found = B_TRUE;
pool_load = zcp->zc_when; pool_load = zcp->zc_when;
@ -867,8 +863,8 @@ zfs_fm_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class)
* Pool level fault. Before solving the case, go through and * Pool level fault. Before solving the case, go through and
* close any open device cases that may be pending. * close any open device cases that may be pending.
*/ */
for (dcp = uu_list_first(zfs_cases); dcp != NULL; for (dcp = list_head(&zfs_cases); dcp != NULL;
dcp = uu_list_next(zfs_cases, dcp)) { dcp = list_next(&zfs_cases, dcp)) {
if (dcp->zc_data.zc_pool_guid == if (dcp->zc_data.zc_pool_guid ==
zcp->zc_data.zc_pool_guid && zcp->zc_data.zc_pool_guid &&
dcp->zc_data.zc_vdev_guid != 0) dcp->zc_data.zc_vdev_guid != 0)
@ -1088,8 +1084,7 @@ zfs_fm_close(fmd_hdl_t *hdl, fmd_case_t *cs)
if (zcp->zc_data.zc_has_remove_timer) if (zcp->zc_data.zc_has_remove_timer)
fmd_timer_remove(hdl, zcp->zc_remove_timer); fmd_timer_remove(hdl, zcp->zc_remove_timer);
uu_list_remove(zfs_cases, zcp); list_remove(&zfs_cases, zcp);
uu_list_node_fini(zcp, &zcp->zc_node, zfs_case_pool);
fmd_hdl_free(hdl, zcp, sizeof (zfs_case_t)); fmd_hdl_free(hdl, zcp, sizeof (zfs_case_t));
} }
@ -1117,23 +1112,11 @@ _zfs_diagnosis_init(fmd_hdl_t *hdl)
if ((zhdl = libzfs_init()) == NULL) if ((zhdl = libzfs_init()) == NULL)
return; return;
if ((zfs_case_pool = uu_list_pool_create("zfs_case_pool", list_create(&zfs_cases,
sizeof (zfs_case_t), offsetof(zfs_case_t, zc_node), sizeof (zfs_case_t), offsetof(zfs_case_t, zc_node));
NULL, UU_LIST_POOL_DEBUG)) == NULL) {
libzfs_fini(zhdl);
return;
}
if ((zfs_cases = uu_list_create(zfs_case_pool, NULL,
UU_LIST_DEBUG)) == NULL) {
uu_list_pool_destroy(zfs_case_pool);
libzfs_fini(zhdl);
return;
}
if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0) { if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0) {
uu_list_destroy(zfs_cases); list_destroy(&zfs_cases);
uu_list_pool_destroy(zfs_case_pool);
libzfs_fini(zhdl); libzfs_fini(zhdl);
return; return;
} }
@ -1148,24 +1131,18 @@ void
_zfs_diagnosis_fini(fmd_hdl_t *hdl) _zfs_diagnosis_fini(fmd_hdl_t *hdl)
{ {
zfs_case_t *zcp; zfs_case_t *zcp;
uu_list_walk_t *walk;
libzfs_handle_t *zhdl; libzfs_handle_t *zhdl;
/* /*
* Remove all active cases. * Remove all active cases.
*/ */
walk = uu_list_walk_start(zfs_cases, UU_WALK_ROBUST); while ((zcp = list_remove_head(&zfs_cases)) != NULL) {
while ((zcp = uu_list_walk_next(walk)) != NULL) {
fmd_hdl_debug(hdl, "removing case ena %llu", fmd_hdl_debug(hdl, "removing case ena %llu",
(long long unsigned)zcp->zc_data.zc_ena); (long long unsigned)zcp->zc_data.zc_ena);
uu_list_remove(zfs_cases, zcp);
uu_list_node_fini(zcp, &zcp->zc_node, zfs_case_pool);
fmd_hdl_free(hdl, zcp, sizeof (zfs_case_t)); fmd_hdl_free(hdl, zcp, sizeof (zfs_case_t));
} }
uu_list_walk_end(walk);
uu_list_destroy(zfs_cases); list_destroy(&zfs_cases);
uu_list_pool_destroy(zfs_case_pool);
zhdl = fmd_hdl_getspecific(hdl); zhdl = fmd_hdl_getspecific(hdl);
libzfs_fini(zhdl); libzfs_fini(zhdl);

View File

@ -42,7 +42,6 @@
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include <libintl.h> #include <libintl.h>
#include <libuutil.h>
#include <libnvpair.h> #include <libnvpair.h>
#include <locale.h> #include <locale.h>
#include <stddef.h> #include <stddef.h>
@ -2851,7 +2850,7 @@ typedef struct us_node {
nvlist_t *usn_nvl; nvlist_t *usn_nvl;
us_cbdata_t *usn_cbdata; us_cbdata_t *usn_cbdata;
avl_node_t usn_avlnode; avl_node_t usn_avlnode;
uu_list_node_t usn_listnode; list_node_t usn_listnode;
} us_node_t; } us_node_t;
struct us_cbdata { struct us_cbdata {
@ -3365,10 +3364,8 @@ zfs_do_userspace(int argc, char **argv)
us_cbdata_t cb; us_cbdata_t cb;
us_node_t *node; us_node_t *node;
us_node_t *rmnode; us_node_t *rmnode;
uu_list_pool_t *listpool; list_t list;
uu_list_t *list;
avl_index_t idx = 0; avl_index_t idx = 0;
uu_list_index_t idx2 = 0;
if (argc < 2) if (argc < 2)
usage(B_FALSE); usage(B_FALSE);
@ -3543,28 +3540,25 @@ zfs_do_userspace(int argc, char **argv)
us_populated = B_TRUE; us_populated = B_TRUE;
listpool = uu_list_pool_create("tmplist", sizeof (us_node_t), list_create(&list, sizeof (us_node_t),
offsetof(us_node_t, usn_listnode), NULL, UU_DEFAULT); offsetof(us_node_t, usn_listnode));
list = uu_list_create(listpool, NULL, UU_DEFAULT); list_link_init(&node->usn_listnode);
uu_list_node_init(node, &node->usn_listnode, listpool);
while (node != NULL) { while (node != NULL) {
rmnode = node; rmnode = node;
node = AVL_NEXT(&cb.cb_avl, node); node = AVL_NEXT(&cb.cb_avl, node);
avl_remove(&cb.cb_avl, rmnode); avl_remove(&cb.cb_avl, rmnode);
if (uu_list_find(list, rmnode, NULL, &idx2) == NULL) list_insert_head(&list, rmnode);
uu_list_insert(list, rmnode, idx2);
} }
for (node = uu_list_first(list); node != NULL; for (node = list_head(&list); node != NULL;
node = uu_list_next(list, node)) { node = list_next(&list, node)) {
if (avl_find(&cb.cb_avl, node, &idx) == NULL) if (avl_find(&cb.cb_avl, node, &idx) == NULL)
avl_insert(&cb.cb_avl, node, idx); avl_insert(&cb.cb_avl, node, idx);
} }
uu_list_destroy(list); while ((node = list_remove_head(&list)) != NULL) { }
uu_list_pool_destroy(listpool); list_destroy(&list);
/* Print and free node nvlist memory */ /* Print and free node nvlist memory */
print_us(scripted, parsable, fields, types, cb.cb_width, B_TRUE, print_us(scripted, parsable, fields, types, cb.cb_width, B_TRUE,
@ -5419,13 +5413,12 @@ typedef struct fs_perm_node {
fs_perm_t fspn_fsperm; fs_perm_t fspn_fsperm;
avl_tree_t fspn_avl; avl_tree_t fspn_avl;
uu_list_node_t fspn_list_node; list_node_t fspn_list_node;
} fs_perm_node_t; } fs_perm_node_t;
/* top level structure */ /* top level structure */
struct fs_perm_set { struct fs_perm_set {
uu_list_pool_t *fsps_list_pool; list_t fsps_list; /* list of fs_perms */
uu_list_t *fsps_list; /* list of fs_perms */
}; };
static inline const char * static inline const char *
@ -5516,14 +5509,8 @@ static inline void
fs_perm_set_init(fs_perm_set_t *fspset) fs_perm_set_init(fs_perm_set_t *fspset)
{ {
memset(fspset, 0, sizeof (fs_perm_set_t)); memset(fspset, 0, sizeof (fs_perm_set_t));
list_create(&fspset->fsps_list, sizeof (fs_perm_node_t),
if ((fspset->fsps_list_pool = uu_list_pool_create("fsps_list_pool", offsetof(fs_perm_node_t, fspn_list_node));
sizeof (fs_perm_node_t), offsetof(fs_perm_node_t, fspn_list_node),
NULL, UU_DEFAULT)) == NULL)
nomem();
if ((fspset->fsps_list = uu_list_create(fspset->fsps_list_pool, NULL,
UU_DEFAULT)) == NULL)
nomem();
} }
static inline void fs_perm_fini(fs_perm_t *); static inline void fs_perm_fini(fs_perm_t *);
@ -5532,17 +5519,13 @@ static inline void who_perm_fini(who_perm_t *);
static inline void static inline void
fs_perm_set_fini(fs_perm_set_t *fspset) fs_perm_set_fini(fs_perm_set_t *fspset)
{ {
fs_perm_node_t *node = uu_list_first(fspset->fsps_list); fs_perm_node_t *node;
while ((node = list_remove_head(&fspset->fsps_list)) != NULL) {
while (node != NULL) {
fs_perm_node_t *next_node =
uu_list_next(fspset->fsps_list, node);
fs_perm_t *fsperm = &node->fspn_fsperm; fs_perm_t *fsperm = &node->fspn_fsperm;
fs_perm_fini(fsperm); fs_perm_fini(fsperm);
uu_list_remove(fspset->fsps_list, node);
free(node); free(node);
node = next_node;
} }
list_destroy(&fspset->fsps_list);
} }
static inline void static inline void
@ -5779,7 +5762,6 @@ static inline int
parse_fs_perm_set(fs_perm_set_t *fspset, nvlist_t *nvl) parse_fs_perm_set(fs_perm_set_t *fspset, nvlist_t *nvl)
{ {
nvpair_t *nvp = NULL; nvpair_t *nvp = NULL;
avl_index_t idx = 0;
while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) { while ((nvp = nvlist_next_nvpair(nvl, nvp)) != NULL) {
nvlist_t *nvl2 = NULL; nvlist_t *nvl2 = NULL;
@ -5792,10 +5774,6 @@ parse_fs_perm_set(fs_perm_set_t *fspset, nvlist_t *nvl)
VERIFY(DATA_TYPE_NVLIST == type); VERIFY(DATA_TYPE_NVLIST == type);
uu_list_node_init(node, &node->fspn_list_node,
fspset->fsps_list_pool);
idx = uu_list_numnodes(fspset->fsps_list);
fs_perm_init(fsperm, fspset, fsname); fs_perm_init(fsperm, fspset, fsname);
if (nvpair_value_nvlist(nvp, &nvl2) != 0) if (nvpair_value_nvlist(nvp, &nvl2) != 0)
@ -5803,7 +5781,7 @@ parse_fs_perm_set(fs_perm_set_t *fspset, nvlist_t *nvl)
(void) parse_fs_perm(fsperm, nvl2); (void) parse_fs_perm(fsperm, nvl2);
uu_list_insert(fspset->fsps_list, node, idx); list_insert_tail(&fspset->fsps_list, node);
} }
return (0); return (0);
@ -6476,8 +6454,8 @@ print_fs_perms(fs_perm_set_t *fspset)
char buf[MAXNAMELEN + 32]; char buf[MAXNAMELEN + 32];
const char *dsname = buf; const char *dsname = buf;
for (node = uu_list_first(fspset->fsps_list); node != NULL; for (node = list_head(&fspset->fsps_list); node != NULL;
node = uu_list_next(fspset->fsps_list, node)) { node = list_next(&fspset->fsps_list, node)) {
avl_tree_t *sc_avl = &node->fspn_fsperm.fsp_sc_avl; avl_tree_t *sc_avl = &node->fspn_fsperm.fsp_sc_avl;
avl_tree_t *uge_avl = &node->fspn_fsperm.fsp_uge_avl; avl_tree_t *uge_avl = &node->fspn_fsperm.fsp_uge_avl;
int left = 0; int left = 0;