FreeBSD/cddl/contrib/opensolaris/cmd/zpool/zpool_vdev.c
/*
 * Validate a whole disk.  Iterate over all slices on the disk and make sure
 * that none is in use by calling check_slice().
 */
Validate a whole disk.  Iterate over all slices on the disk and make sure
that none is in use by calling check_slice().
Validate a whole disk . Iterate over all slices on the disk and make sure that none is in use by calling check_slice () .
static int
check_disk(const char *name, dm_descriptor_t disk, int force, int isspare)
{
	dm_descriptor_t *drive, *media, *slice;
	int err = 0;
	int i;
	int ret;
	if ((drive = dm_get_associated_descriptors(disk, DM_DRIVE,
	    &err)) == NULL || *drive == NULL) {
		if (err)
			libdiskmgt_error(err);
		return (0);
	}
	if ((media = dm_get_associated_descriptors(*drive, DM_MEDIA,
	    &err)) == NULL) {
		dm_free_descriptors(drive);
		if (err)
			libdiskmgt_error(err);
		return (0);
	}
	dm_free_descriptors(drive);
	if (*media == NULL) {
		dm_free_descriptors(media);
		vdev_error(gettext("'%s' has no media in drive\n"), name);
		return (-1);
	}
	if ((slice = dm_get_associated_descriptors(*media, DM_SLICE,
	    &err)) == NULL) {
		dm_free_descriptors(media);
		if (err)
			libdiskmgt_error(err);
		return (0);
	}
	dm_free_descriptors(media);
	ret = 0;
	for (i = 0; slice[i] != NULL; i++) {
		char *name = dm_get_name(slice[i], &err);
		if (check_slice(name, force, B_TRUE, isspare) != 0)
			ret = -1;
		dm_free_name(name);
	}
	dm_free_descriptors(slice);
	return (ret);
}
static int check_disk ( const char * name , dm_descriptor_t disk , int force , int isspare ) { dm_descriptor_t * drive , * media , * slice ; int err = 0 ; int i ; int ret ; if ( ( drive = dm_get_associated_descriptors ( disk , DM_DRIVE , & err ) ) == NULL || * drive == NULL ) { if ( err ) libdiskmgt_error ( err ) ; return ( 0 ) ; } if ( ( media = dm_get_associated_descriptors ( * drive , DM_MEDIA , & err ) ) == NULL ) { dm_free_descriptors ( drive ) ; if ( err ) libdiskmgt_error ( err ) ; return ( 0 ) ; } dm_free_descriptors ( drive ) ; if ( * media == NULL ) { dm_free_descriptors ( media ) ; vdev_error ( gettext ( " \n " ) , name ) ; return ( -1 ) ; } if ( ( slice = dm_get_associated_descriptors ( * media , DM_SLICE , & err ) ) == NULL ) { dm_free_descriptors ( media ) ; if ( err ) libdiskmgt_error ( err ) ; return ( 0 ) ; } dm_free_descriptors ( media ) ; ret = 0 ; for ( i = 0 ; slice [ i ] != NULL ; i ++ ) { char * name = dm_get_name ( slice [ i ] , & err ) ; if ( check_slice ( name , force , B_TRUE , isspare ) != 0 ) ret = -1 ; dm_free_name ( name ) ; } dm_free_descriptors ( slice ) ; return ( ret ) ; }
Validate a whole disk.
Validate a whole disk .
/*
	 * Get the drive associated with this disk.  This should never fail,
	 * because we already have an alias handle open for the device.
	 */ /*
	 * It is possible that the user has specified a removable media drive,
	 * and the media is not present.
	 */ /*
	 * Iterate over all slices and report any errors.  We don't care about
	 * overlapping slices because we are using the whole disk.
	 */