@@ -2898,154 +2898,6 @@ zpool_find_vdev(zpool_handle_t *zhp, const char *path, boolean_t *avail_spare,
28982898 return (ret );
28992899}
29002900
2901- static int
2902- vdev_is_online (nvlist_t * nv )
2903- {
2904- uint64_t ival ;
2905-
2906- if (nvlist_lookup_uint64 (nv , ZPOOL_CONFIG_OFFLINE , & ival ) == 0 ||
2907- nvlist_lookup_uint64 (nv , ZPOOL_CONFIG_FAULTED , & ival ) == 0 ||
2908- nvlist_lookup_uint64 (nv , ZPOOL_CONFIG_REMOVED , & ival ) == 0 )
2909- return (0 );
2910-
2911- return (1 );
2912- }
2913-
2914- /*
2915- * Helper function for zpool_get_physpaths().
2916- */
2917- static int
2918- vdev_get_one_physpath (nvlist_t * config , char * physpath , size_t physpath_size ,
2919- size_t * bytes_written )
2920- {
2921- size_t bytes_left , pos , rsz ;
2922- char * tmppath ;
2923- const char * format ;
2924-
2925- if (nvlist_lookup_string (config , ZPOOL_CONFIG_PHYS_PATH ,
2926- & tmppath ) != 0 )
2927- return (EZFS_NODEVICE );
2928-
2929- pos = * bytes_written ;
2930- bytes_left = physpath_size - pos ;
2931- format = (pos == 0 ) ? "%s" : " %s" ;
2932-
2933- rsz = snprintf (physpath + pos , bytes_left , format , tmppath );
2934- * bytes_written += rsz ;
2935-
2936- if (rsz >= bytes_left ) {
2937- /* if physpath was not copied properly, clear it */
2938- if (bytes_left != 0 ) {
2939- physpath [pos ] = 0 ;
2940- }
2941- return (EZFS_NOSPC );
2942- }
2943- return (0 );
2944- }
2945-
2946- static int
2947- vdev_get_physpaths (nvlist_t * nv , char * physpath , size_t phypath_size ,
2948- size_t * rsz , boolean_t is_spare )
2949- {
2950- char * type ;
2951- int ret ;
2952-
2953- if (nvlist_lookup_string (nv , ZPOOL_CONFIG_TYPE , & type ) != 0 )
2954- return (EZFS_INVALCONFIG );
2955-
2956- if (strcmp (type , VDEV_TYPE_DISK ) == 0 ) {
2957- /*
2958- * An active spare device has ZPOOL_CONFIG_IS_SPARE set.
2959- * For a spare vdev, we only want to boot from the active
2960- * spare device.
2961- */
2962- if (is_spare ) {
2963- uint64_t spare = 0 ;
2964- (void ) nvlist_lookup_uint64 (nv , ZPOOL_CONFIG_IS_SPARE ,
2965- & spare );
2966- if (!spare )
2967- return (EZFS_INVALCONFIG );
2968- }
2969-
2970- if (vdev_is_online (nv )) {
2971- if ((ret = vdev_get_one_physpath (nv , physpath ,
2972- phypath_size , rsz )) != 0 )
2973- return (ret );
2974- }
2975- } else if (strcmp (type , VDEV_TYPE_MIRROR ) == 0 ||
2976- strcmp (type , VDEV_TYPE_RAIDZ ) == 0 ||
2977- strcmp (type , VDEV_TYPE_REPLACING ) == 0 ||
2978- (is_spare = (strcmp (type , VDEV_TYPE_SPARE ) == 0 ))) {
2979- nvlist_t * * child ;
2980- uint_t count ;
2981- int i , ret ;
2982-
2983- if (nvlist_lookup_nvlist_array (nv ,
2984- ZPOOL_CONFIG_CHILDREN , & child , & count ) != 0 )
2985- return (EZFS_INVALCONFIG );
2986-
2987- for (i = 0 ; i < count ; i ++ ) {
2988- ret = vdev_get_physpaths (child [i ], physpath ,
2989- phypath_size , rsz , is_spare );
2990- if (ret == EZFS_NOSPC )
2991- return (ret );
2992- }
2993- }
2994-
2995- return (EZFS_POOL_INVALARG );
2996- }
2997-
2998- /*
2999- * Get phys_path for a root pool config.
3000- * Return 0 on success; non-zero on failure.
3001- */
3002- static int
3003- zpool_get_config_physpath (nvlist_t * config , char * physpath , size_t phypath_size )
3004- {
3005- size_t rsz ;
3006- nvlist_t * vdev_root ;
3007- nvlist_t * * child ;
3008- uint_t count ;
3009- char * type ;
3010-
3011- rsz = 0 ;
3012-
3013- if (nvlist_lookup_nvlist (config , ZPOOL_CONFIG_VDEV_TREE ,
3014- & vdev_root ) != 0 )
3015- return (EZFS_INVALCONFIG );
3016-
3017- if (nvlist_lookup_string (vdev_root , ZPOOL_CONFIG_TYPE , & type ) != 0 ||
3018- nvlist_lookup_nvlist_array (vdev_root , ZPOOL_CONFIG_CHILDREN ,
3019- & child , & count ) != 0 )
3020- return (EZFS_INVALCONFIG );
3021-
3022- /*
3023- * root pool can only have a single top-level vdev.
3024- */
3025- if (strcmp (type , VDEV_TYPE_ROOT ) != 0 || count != 1 )
3026- return (EZFS_POOL_INVALARG );
3027-
3028- (void ) vdev_get_physpaths (child [0 ], physpath , phypath_size , & rsz ,
3029- B_FALSE );
3030-
3031- /* No online devices */
3032- if (rsz == 0 )
3033- return (EZFS_NODEVICE );
3034-
3035- return (0 );
3036- }
3037-
3038- /*
3039- * Get phys_path for a root pool
3040- * Return 0 on success; non-zero on failure.
3041- */
3042- int
3043- zpool_get_physpath (zpool_handle_t * zhp , char * physpath , size_t phypath_size )
3044- {
3045- return (zpool_get_config_physpath (zhp -> zpool_config , physpath ,
3046- phypath_size ));
3047- }
3048-
30492901/*
30502902 * Convert a vdev path to a GUID. Returns GUID or 0 on error.
30512903 *
0 commit comments