From 871fa61d262f807446cd5c687edc77d6ddb84932 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Thu, 13 Nov 2025 21:16:38 +1100 Subject: [PATCH] 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 Signed-off-by: Rob Norris Closes #17934 --- cmd/zed/agents/zfs_diagnosis.c | 77 ++++++++++++---------------------- cmd/zfs/zfs_main.c | 62 +++++++++------------------ 2 files changed, 47 insertions(+), 92 deletions(-) diff --git a/cmd/zed/agents/zfs_diagnosis.c b/cmd/zed/agents/zfs_diagnosis.c index 453243b2f..206caa16b 100644 --- a/cmd/zed/agents/zfs_diagnosis.c +++ b/cmd/zed/agents/zfs_diagnosis.c @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -96,7 +95,7 @@ typedef struct zfs_case { uint32_t zc_version; zfs_case_data_t zc_data; fmd_case_t *zc_case; - uu_list_node_t zc_node; + list_node_t zc_node; id_t zc_remove_timer; char *zc_fru; er_timeval_t zc_when; @@ -126,8 +125,7 @@ zfs_de_stats_t zfs_stats = { /* wait 15 seconds after a removal */ static hrtime_t zfs_remove_timeout = SEC2NSEC(15); -uu_list_pool_t *zfs_case_pool; -uu_list_t *zfs_cases; +static list_t zfs_cases; #define ZFS_MAKE_RSRC(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, NULL, zfs_remove_timeout); - uu_list_node_init(zcp, &zcp->zc_node, zfs_case_pool); - (void) uu_list_insert_before(zfs_cases, NULL, zcp); + list_link_init(&zcp->zc_node); + list_insert_head(&zfs_cases, 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; } - for (zcp = uu_list_first(zfs_cases); zcp != NULL; - zcp = uu_list_next(zfs_cases, zcp)) { + for (zcp = list_head(&zfs_cases); zcp != NULL; + zcp = list_next(&zfs_cases, zcp)) { 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. */ - for (zcp = uu_list_first(zfs_cases); zcp != NULL; - zcp = uu_list_next(zfs_cases, zcp)) { + for (zcp = list_head(&zfs_cases); zcp != NULL; + zcp = list_next(&zfs_cases, zcp)) { if (zcp->zc_data.zc_pool_guid == pool_guid && zcp->zc_data.zc_vdev_guid == vdev_guid) { 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. */ - for (zcp = uu_list_first(zfs_cases); zcp != NULL; - zcp = uu_list_next(zfs_cases, zcp)) { + for (zcp = list_head(&zfs_cases); zcp != NULL; + zcp = list_next(&zfs_cases, zcp)) { if (zcp->zc_data.zc_pool_guid == pool_guid && zcp->zc_data.zc_vdev_guid == 0) zcp->zc_present = B_TRUE; @@ -321,8 +319,8 @@ zfs_mark_pool(zpool_handle_t *zhp, void *unused) if (nelem == 2) { loaded.ertv_sec = tod[0]; loaded.ertv_nsec = tod[1]; - for (zcp = uu_list_first(zfs_cases); zcp != NULL; - zcp = uu_list_next(zfs_cases, zcp)) { + for (zcp = list_head(&zfs_cases); zcp != NULL; + zcp = list_next(&zfs_cases, zcp)) { if (zcp->zc_data.zc_pool_guid == pool_guid && zcp->zc_data.zc_vdev_guid == 0) { zcp->zc_when = loaded; @@ -389,8 +387,7 @@ zpool_find_load_time(zpool_handle_t *zhp, void *arg) static void zfs_purge_cases(fmd_hdl_t *hdl) { - zfs_case_t *zcp; - uu_list_walk_t *walk; + zfs_case_t *zcp, *next; 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. */ - for (zcp = uu_list_first(zfs_cases); zcp != NULL; - zcp = uu_list_next(zfs_cases, zcp)) + for (zcp = list_head(&zfs_cases); zcp != NULL; + zcp = list_next(&zfs_cases, zcp)) zcp->zc_present = B_FALSE; /* @@ -425,12 +422,11 @@ zfs_purge_cases(fmd_hdl_t *hdl) /* * Remove those cases which were not found. */ - walk = uu_list_walk_start(zfs_cases, UU_WALK_ROBUST); - while ((zcp = uu_list_walk_next(walk)) != NULL) { + for (zcp = list_head(&zfs_cases); zcp != NULL; zcp = next) { + next = list_next(&zfs_cases, zcp); if (!zcp->zc_present) 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); - for (zcp = uu_list_first(zfs_cases); zcp != NULL; - zcp = uu_list_next(zfs_cases, zcp)) { + for (zcp = list_head(&zfs_cases); zcp != NULL; + zcp = list_next(&zfs_cases, zcp)) { if (zcp->zc_data.zc_pool_guid == pool_guid) { pool_found = B_TRUE; 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 * close any open device cases that may be pending. */ - for (dcp = uu_list_first(zfs_cases); dcp != NULL; - dcp = uu_list_next(zfs_cases, dcp)) { + for (dcp = list_head(&zfs_cases); dcp != NULL; + dcp = list_next(&zfs_cases, dcp)) { if (dcp->zc_data.zc_pool_guid == zcp->zc_data.zc_pool_guid && 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) fmd_timer_remove(hdl, zcp->zc_remove_timer); - uu_list_remove(zfs_cases, zcp); - uu_list_node_fini(zcp, &zcp->zc_node, zfs_case_pool); + list_remove(&zfs_cases, zcp); 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) return; - if ((zfs_case_pool = uu_list_pool_create("zfs_case_pool", - 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; - } + list_create(&zfs_cases, + sizeof (zfs_case_t), offsetof(zfs_case_t, zc_node)); if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0) { - uu_list_destroy(zfs_cases); - uu_list_pool_destroy(zfs_case_pool); + list_destroy(&zfs_cases); libzfs_fini(zhdl); return; } @@ -1148,24 +1131,18 @@ void _zfs_diagnosis_fini(fmd_hdl_t *hdl) { zfs_case_t *zcp; - uu_list_walk_t *walk; libzfs_handle_t *zhdl; /* * Remove all active cases. */ - walk = uu_list_walk_start(zfs_cases, UU_WALK_ROBUST); - while ((zcp = uu_list_walk_next(walk)) != NULL) { + while ((zcp = list_remove_head(&zfs_cases)) != NULL) { fmd_hdl_debug(hdl, "removing case ena %llu", (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)); } - uu_list_walk_end(walk); - uu_list_destroy(zfs_cases); - uu_list_pool_destroy(zfs_case_pool); + list_destroy(&zfs_cases); zhdl = fmd_hdl_getspecific(hdl); libzfs_fini(zhdl); diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 3648f58c6..01d93ed92 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -2851,7 +2850,7 @@ typedef struct us_node { nvlist_t *usn_nvl; us_cbdata_t *usn_cbdata; avl_node_t usn_avlnode; - uu_list_node_t usn_listnode; + list_node_t usn_listnode; } us_node_t; struct us_cbdata { @@ -3365,10 +3364,8 @@ zfs_do_userspace(int argc, char **argv) us_cbdata_t cb; us_node_t *node; us_node_t *rmnode; - uu_list_pool_t *listpool; - uu_list_t *list; + list_t list; avl_index_t idx = 0; - uu_list_index_t idx2 = 0; if (argc < 2) usage(B_FALSE); @@ -3543,28 +3540,25 @@ zfs_do_userspace(int argc, char **argv) us_populated = B_TRUE; - listpool = uu_list_pool_create("tmplist", sizeof (us_node_t), - offsetof(us_node_t, usn_listnode), NULL, UU_DEFAULT); - list = uu_list_create(listpool, NULL, UU_DEFAULT); - uu_list_node_init(node, &node->usn_listnode, listpool); + list_create(&list, sizeof (us_node_t), + offsetof(us_node_t, usn_listnode)); + list_link_init(&node->usn_listnode); while (node != NULL) { rmnode = node; node = AVL_NEXT(&cb.cb_avl, node); avl_remove(&cb.cb_avl, rmnode); - if (uu_list_find(list, rmnode, NULL, &idx2) == NULL) - uu_list_insert(list, rmnode, idx2); + list_insert_head(&list, rmnode); } - for (node = uu_list_first(list); node != NULL; - node = uu_list_next(list, node)) { - + for (node = list_head(&list); node != NULL; + node = list_next(&list, node)) { if (avl_find(&cb.cb_avl, node, &idx) == NULL) avl_insert(&cb.cb_avl, node, idx); } - uu_list_destroy(list); - uu_list_pool_destroy(listpool); + while ((node = list_remove_head(&list)) != NULL) { } + list_destroy(&list); /* Print and free node nvlist memory */ 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; avl_tree_t fspn_avl; - uu_list_node_t fspn_list_node; + list_node_t fspn_list_node; } fs_perm_node_t; /* top level structure */ struct fs_perm_set { - uu_list_pool_t *fsps_list_pool; - uu_list_t *fsps_list; /* list of fs_perms */ + list_t fsps_list; /* list of fs_perms */ }; static inline const char * @@ -5516,14 +5509,8 @@ static inline void fs_perm_set_init(fs_perm_set_t *fspset) { memset(fspset, 0, sizeof (fs_perm_set_t)); - - if ((fspset->fsps_list_pool = uu_list_pool_create("fsps_list_pool", - 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(); + list_create(&fspset->fsps_list, sizeof (fs_perm_node_t), + offsetof(fs_perm_node_t, fspn_list_node)); } 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 fs_perm_set_fini(fs_perm_set_t *fspset) { - fs_perm_node_t *node = uu_list_first(fspset->fsps_list); - - while (node != NULL) { - fs_perm_node_t *next_node = - uu_list_next(fspset->fsps_list, node); + fs_perm_node_t *node; + while ((node = list_remove_head(&fspset->fsps_list)) != NULL) { fs_perm_t *fsperm = &node->fspn_fsperm; fs_perm_fini(fsperm); - uu_list_remove(fspset->fsps_list, node); free(node); - node = next_node; } + list_destroy(&fspset->fsps_list); } static inline void @@ -5779,7 +5762,6 @@ static inline int parse_fs_perm_set(fs_perm_set_t *fspset, nvlist_t *nvl) { nvpair_t *nvp = NULL; - avl_index_t idx = 0; while ((nvp = nvlist_next_nvpair(nvl, nvp)) != 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); - 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); 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); - uu_list_insert(fspset->fsps_list, node, idx); + list_insert_tail(&fspset->fsps_list, node); } return (0); @@ -6476,8 +6454,8 @@ print_fs_perms(fs_perm_set_t *fspset) char buf[MAXNAMELEN + 32]; const char *dsname = buf; - for (node = uu_list_first(fspset->fsps_list); node != NULL; - node = uu_list_next(fspset->fsps_list, node)) { + for (node = list_head(&fspset->fsps_list); node != NULL; + node = list_next(&fspset->fsps_list, node)) { avl_tree_t *sc_avl = &node->fspn_fsperm.fsp_sc_avl; avl_tree_t *uge_avl = &node->fspn_fsperm.fsp_uge_avl; int left = 0;